Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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 @@ -82,33 +82,22 @@ bool AddNOpInferSymbolicShape(pir::Operation *op,
"should be larger than 0. But received X's dimensions %d.",
inputs_shape.size()));
symbol::TensorShapeOrDataDimExprs candidate_shape = inputs_shape.front();
std::vector<symbol::DimExpr> candidate_shape_vec = candidate_shape.shape();
for (size_t i = 1; i < inputs_shape.size(); ++i) {
// 0D tensor
if (inputs_shape[i].shape().size() == 0) {
continue;
}
if (candidate_shape.shape().size() == 0) {
candidate_shape = inputs_shape[i];
candidate_shape_vec = candidate_shape.shape();
continue;
}
for (size_t j = 0; j < candidate_shape_vec.size(); ++j) {
if (candidate_shape_vec[j] != 0) {
if (inputs_shape[i].shape()[j] != 0) {
infer_context->AddEqualCstr(candidate_shape_vec[j],
inputs_shape[i].shape()[j]);
} else {
candidate_shape_vec[j] = symbol::DimExpr{0};
}
}
for (size_t j = 0; j < candidate_shape.shape().size(); ++j) {
infer_context->AddEqualCstr(candidate_shape.shape()[j],
inputs_shape[i].shape()[j]);
}
}
infer_context->SetShapeOrDataForValue(
op->result(0),
symbol::ShapeOrDataDimExprs{
symbol::TensorShapeOrDataDimExprs(candidate_shape_vec)});

op->result(0), symbol::ShapeOrDataDimExprs{candidate_shape});
return true;
}

Expand Down
30 changes: 10 additions & 20 deletions paddle/phi/infermeta/multiary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -416,29 +416,19 @@ void AddNInferMeta(const std::vector<const MetaTensor*>& x,
}
is_all_0d_tensor = false;
// use the first dimension
if (i == 0) {
if (common::product(in_dim) == 0) {
in_dim = x_dim;
} else {
if (config.is_runtime) {
for (int j = 0; j < x_dim.size(); ++j) {
if (in_dim[j] != 0) {
if (x_dim[j] == 0) {
// update the 0 dim
in_dim[j] = 0;
} else {
PADDLE_ENFORCE_EQ(
in_dim[j],
x_dim[j],
common::errors::InvalidArgument(
"The input tensor X of AddNOp must"
" have same shape. But received X[0]'s shape = "
"[%s], X[%d]'s shape = [%s].",
in_dim,
i,
x_dim));
}
}
}
PADDLE_ENFORCE_EQ(in_dim,
x_dim,
common::errors::InvalidArgument(
"The input tensor X of AddNOp must"
" have same shape. But received X[0]'s shape = "
"[%s], X[%d]'s shape = [%s].",
in_dim,
i,
x_dim));
} else {
PADDLE_ENFORCE_EQ(
in_dim.size(),
Expand Down
Loading