improve group norm cpu precision and performance #33176
Merged
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
问题:paddle.nn.GroupNorm 在float32下CPU计算结果和准确值的相对误差大于e-5
原因:原有计算方法在计算均值和方差时为逐个数相加,当计算数据个数较多 且 累加数比较大 且 单个元素较小 时就容易造成舍入误差 从而导致 最终结果的误差
方案:使用SIMD的思想进行分组累加,最后再归并加和以降低舍入误差,并调研其它框架中的类似算法,均使用此种思想来实现。同时有个附加好处是增加了计算并行性,提升性能
效果:paddle.nn.GroupNorm 在float32下CPU计算结果和准确值的相对误差已经小于e-6,且性能提升7%