-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[CINN] Add infer_symbol_shape for some ops #68166
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2046,6 +2046,45 @@ bool IndexPut_OpInferSymbolicShape( | |
return IndexPutOpInferSymbolicShape(op, infer_context); | ||
} | ||
|
||
bool LogLossOpInferSymbolicShape( | ||
pir::Operation *op, pir::InferSymbolicShapeContext *infer_context) { | ||
const symbol::ShapeOrDataDimExprs &input_shape_or_data = | ||
infer_context->GetShapeOrDataForValue( | ||
op->operand_source(0)), | ||
|
||
&label_shape_or_data = | ||
infer_context->GetShapeOrDataForValue( | ||
op->operand_source(1)); | ||
|
||
const auto &input_shape = input_shape_or_data.shape(); | ||
const auto &label_shape = label_shape_or_data.shape(); | ||
|
||
PADDLE_ENFORCE_EQ( | ||
input_shape.size() == 2 && label_shape.size() == 2, | ||
true, | ||
common::errors::InvalidArgument( | ||
"The rank of input and label should both be 2, but received: " | ||
"input: %d, label: %d\n", | ||
input_shape.size(), | ||
label_shape.size())); | ||
|
||
for (int i = 0; i < 2; i++) { | ||
infer_context->AddEqualCstr(input_shape[i], label_shape[i]); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 麻烦补充一个equalcstr(input_shape[1], dimexpr(1)); 的约束,对于动态维度,能添加约束信息就尽量添加 |
||
symbol::DimExpr one_dim = symbol::DimExpr{1}; | ||
|
||
infer_context->AddEqualCstr(input_shape[1], one_dim); | ||
infer_context->AddEqualCstr(label_shape[1], one_dim); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里其实添加一个就可以,上面已经添加了input_shape[1]和label_shape[1]的约束。可以放到下个pr修改 |
||
|
||
infer_context->SetShapeOrDataForValue( | ||
op->result(0), | ||
symbol::ShapeOrDataDimExprs{ | ||
symbol::TensorShapeOrDataDimExprs(input_shape)}); | ||
|
||
return true; | ||
} | ||
|
||
} // namespace paddle::dialect | ||
|
||
namespace cinn::dialect { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里可以直接写成
const auto &input_shape = infer_context->GetShapeOrDataForValue(op->operand_source(0)).shape();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GoldenStain 下一个PR改一下哈