Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Infer Symbolic Shape No.15】Add LruOpInferSymbolicShape implementation #68096

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,38 @@ bool LogsumexpOpInferSymbolicShape(
return details::ReduceInferDim(op, infer_context, axis, keepdim, reduce_all);
}

bool LrnInferSymbolicShape(pir::Operation *op,
enkilee marked this conversation as resolved.
Show resolved Hide resolved
pir::InferSymbolicShapeContext *infer_context) {
const auto &x_shape_or_data =
infer_context->GetShapeOrDataForValue(op->operand_source(0));
const std::vector<symbol::DimExpr> &x_shape = x_shape_or_data.shape();
int x_size = x_shape.size();
PADDLE_ENFORCE_EQ(
x_size,
4,
common::errors::InvalidArgument("Input(input) rank should be 4, "
"but received input rank (%d) != 4",
x_size));
int n_value = op->attribute<pir::Int32Attribute>("n").data();
PADDLE_ENFORCE_GT(
n_value,
0UL,
common::errors::InvalidArgument("Argument(n) should be positive, "
"but received n(%d) not greater than 0",
n_value));
PADDLE_ENFORCE_EQ(
n_value % 2,
1UL,
common::errors::InvalidArgument("Argument(n) should be odd value, "
"but received n(%d) is not an odd value",
n_value));
infer_context->SetShapeOrDataForValue(
op->result(0), symbol::TensorShapeOrDataDimExprs(x_shape));
infer_context->SetShapeOrDataForValue(
op->result(1), symbol::TensorShapeOrDataDimExprs(x_shape));
return true;
}

bool LuOpInferSymbolicShape(pir::Operation *op,
pir::InferSymbolicShapeContext *infer_context) {
const auto &x_shape_or_data =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ OP_DECLARE_INFER_SYMBOLIC_SHAPE(L1Norm_)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(LpPool2d)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Logcumsumexp)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Logsumexp)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Lrn)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Lu)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Lu_)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Mode)
Expand Down
1 change: 1 addition & 0 deletions paddle/phi/ops/yaml/inconsistent/static_ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@
func: lrn
data_type: x
backward: lrn_grad
interfaces : paddle::dialect::InferSymbolicShapeInterface

- op : matmul
args : (Tensor x, Tensor y, bool transpose_x = false, bool transpose_y = false)
Expand Down
1 change: 1 addition & 0 deletions paddle/phi/ops/yaml/legacy/static_ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@
func: lrn
data_type: x
backward: lrn_grad
interfaces : paddle::dialect::InferSymbolicShapeInterface
enkilee marked this conversation as resolved.
Show resolved Hide resolved

- op : matmul
args : (Tensor x, Tensor y, bool transpose_x = false, bool transpose_y = false)
Expand Down