You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
你的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.
lshpku
changed the title
[CINN] Support pd_op.reduce_var with Welford algorithm in backend (demo)
[CINN] Backend supports the Welford variance algorithm
Feb 24, 2025
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 Category
CINN
PR Types
Improvements
Description
在CINN后端实现通过Welford算法计算方差,对应前端的
pd_op.variance
算子注:当前仅支持通过BatchNorm的组合算子调用variance算子,不支持前端用户直接调用
示例程序
生成的CUDA代码:
性能问题
Welford会造成一定的性能回退!
float32
,经测试任何shape下性能回退均小于0.5%,可以认为比较安全float16
,性能回退在1~3%之间,shape越小回退越明显,因为Welford的计算量较大,数据量小时无法覆盖计算延迟然而也不用过度担心,因为上述指的都是单就BatchNorm而言,但在模型里面BatchNorm用时占比一般不超过30%,哪怕是占比特别大的ResNet50,经测试也没有发现可见的ips回退,仅能通过nsys统计看出CINN的Kernel占比增加了1%
之后如果对性能有更高需求,可以再写一个pass,把variance和mean的计算合在一起,因为Welford其实同时算出了variance和mean,但当前mean是重复算的,合在一起可以省一个寄存器
Pcard-85711