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.125】【BUAA】Add BroadcastTensor, changed 3 files #67744

Closed
wants to merge 86 commits into from

Conversation

Whsjrczr
Copy link
Contributor

@Whsjrczr Whsjrczr commented Aug 27, 2024

PR Category

CINN

PR Types

Others

Description

加入broadcast_tensors:
paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/multiary_infer_sym.cc
paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/multiary_infer_sym.h
paddle/phi/ops/yaml/ops.yaml

Copy link

paddle-bot bot commented Aug 27, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Aug 27, 2024
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Aug 28, 2024
Comment on lines 666 to 679
std::vector<symbol::DimExpr> out_shape;
for (size_t i = 0; i < target_rank; i++) {
out_shape.push_back(symbol::DimExpr{1});
}

symbol::DimExprBuilder builder;
for (size_t i = 0; i < input_shape_or_data_list.size(); i++) {
size_t tmp_bound = input_shape_or_data_list[i].shape().size();
for (size_t j = 0; j < tmp_bound; j++) {
out_shape[target_rank - j - 1] = builder.Broadcast(
input_shape_or_data_list[i].shape()[tmp_bound - j - 1],
out_shape[target_rank - j - 1]);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.这里不需要初始化为1了
2.Broadcast可以嵌套,参考这个伪代码写吧
3e9d9d530da8e9436692a588437bf96c
3. 再内层for循环里做Broadcast操作时添加一个broadcast约束
AddBrpadCast(shape_or_data_list[i].shape()[0], shape_or_data_list[i].shape()[j])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要从最后一个维度往前做broadcast比对,每个tensor长度不一样,如果长度短,前面缺的用1补全,那么最内层for循环每次都需要判断shape_or_data_list[j]的长度,这样可以吗?

}

symbol::TensorListShapeOrDataDimExprs out_shapes;
for (size_t i = 0; i < target_rank; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i < input_shape_or_data_list.size()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants