-
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
【Infer Symbolic Shape No.124】【BUAA】Add bmm, changed 3 files #67431
Changes from 1 commit
9efa4c0
321d80a
7f27b58
4812a76
99ef612
6f31ab0
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 |
---|---|---|
|
@@ -207,11 +207,63 @@ bool Binomial_OpInferSymbolicShape( | |
// return true; | ||
// } | ||
|
||
// bool BmmOpInferSymbolicShape(pir::Operation *op, | ||
// pir::InferSymbolicShapeContext *infer_context) { | ||
// // pass | ||
// return true; | ||
// } | ||
bool BmmOpInferSymbolicShape(pir::Operation *op, | ||
pir::InferSymbolicShapeContext *infer_context) { | ||
const auto &x_shape_or_data = | ||
infer_context->GetShapeOrDataForValue(op->operand_source(0)); | ||
const auto &y_shape_or_data = | ||
infer_context->GetShapeOrDataForValue(op->operand_source(1)); | ||
|
||
const std::vector<symbol::DimExpr> &x_dims = x_shape_or_data.shape(); | ||
const std::vector<symbol::DimExpr> &y_dims = y_shape_or_data.shape(); | ||
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. 同上 |
||
std::size_t x_ndims = x_dims.size(); | ||
std::size_t y_ndims = y_dims.size(); | ||
|
||
PADDLE_ENFORCE_EQ( | ||
x_ndims, | ||
3, | ||
common::errors::InvalidArgument("Input(X) of BmmOp must be 3-dimensional " | ||
"in BmmOp, but received X's shape: [%d].", | ||
x_ndims)); | ||
PADDLE_ENFORCE_EQ( | ||
y_ndims, | ||
3, | ||
common::errors::InvalidArgument("Input(Y) of BmmOp must be 3-dimensional " | ||
"in BmmOp, but received Y's shape: [%d].", | ||
y_ndims)); | ||
|
||
auto cal_shape_fn = [](const symbol::DimExpr &x, | ||
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. 删掉这个lambda表达式,调用cal_shape_fn的地方都使用 addequalcstr |
||
const symbol::DimExpr &y, | ||
const std::string &error_str) -> symbol::DimExpr { | ||
if (x == -1) { | ||
return y; | ||
} else if (y == -1) { | ||
return x; | ||
} | ||
PADDLE_ENFORCE_EQ(x, y, common::errors::InvalidArgument(error_str, x, y)); | ||
return x; | ||
}; | ||
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. DimExpr不可能为-1,这段逻辑是想给两个DimExpr加约束 |
||
|
||
cal_shape_fn(x_dims[2], | ||
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. 修改为 equal constrain |
||
y_dims[1], | ||
"Input(X)'s width must be equal with Input(Y)'s height in " | ||
"BmmOp, but receive X's width: [%d], Y's height: [%d]."); | ||
symbol::DimExpr batch_size = cal_shape_fn( | ||
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. 同上,batch_size 直接取其中一个Dim就行 |
||
x_dims[0], | ||
y_dims[0], | ||
"Input(X) and Input(Y) must have the same batch size in BmmOp, but " | ||
"received X's batch size: [%d], Y's batch size [%d]"); | ||
symbol::DimExpr out_height = x_dims[1]; | ||
symbol::DimExpr out_width = y_dims[2]; | ||
|
||
std::vector<symbol::DimExpr> out_dims = {batch_size, out_height, out_width}; | ||
|
||
infer_context->SetShapeOrDataForValue( | ||
op->result(0), | ||
symbol::ShapeOrDataDimExprs{symbol::TensorShapeOrDataDimExprs(out_dims)}); | ||
|
||
return true; | ||
} | ||
|
||
// bool CholeskySolveOpInferSymbolicShape(pir::Operation *op, | ||
// pir::InferSymbolicShapeContext | ||
|
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.
命名不规范,x_shape