Use BroadcastKernel and ReduceKernel to optimize expand and expand_grad. #49419
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Performance optimization
PR changes
OPs
Describe
使用
BroadcastKernel
和ReduceKernel
重写expand kernel,OP Benchmark CI中性能优化效果如下:其他情况说明:
ExpandKernel
中仍然加入了输出Shape的计算逻辑。实际上,InferShape的功能应该由ExpandInferMeta
函数完成,但静态图ExpandInferMeta
执行完后,输出Shape中仍然存在-1,个人认为这是ExpandInferMeta
的实现存在bug。考虑到目前尚不是完全确定静态图编译期InferShape的逻辑,故PR暂不修改这部分。ExpandAsKernel
可复用ExpandKernel
实现,后续再提PR修改。