[Accuracy diff No.16] Fix accuracy diff for paddle.cumsum 、 paddle.logcumsumexp API#74081
Merged
lshpku merged 2 commits intoPaddlePaddle:developfrom Jul 17, 2025
Merged
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
wanghuancoder
approved these changes
Jul 17, 2025
Contributor
wanghuancoder
left a comment
There was a problem hiding this comment.
LGTM Kernel改动比较大,让书豪帮忙把把关
lshpku
reviewed
Jul 17, 2025
lshpku
reviewed
Jul 17, 2025
lshpku
approved these changes
Jul 17, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Operator Mechanism
PR Types
Bug fixes
Description
错误定位:
ThrustCumsumKernel自身的精度误差就极大解决方案:
ThrustCumsumKernel分支处理,进入后续 CUDAcub计算BlockPrefixCallbackOp采用 Kahan 算法,参考:https://en.wikipedia.org/wiki/Kahan_summation_algorithmBlockPrefixCallbackOp对于LogAddExp算子特例,采用 Kahan + Online Scale,使其数值更稳定其他修改:
np_logcumsumexp_grad,避免直接计算np.log(-dout)(dout > 0) 报错测试:
修复后,测试用例大致分为三类:
考虑到超大张量累积误差本身就更大,将 atol、rtol 改为 1 后基本通过测试:

将其添加至 torch_error_skip 跳过精度测试
将其添加至 torch_error_skip 跳过精度测试
补充测试:
张量通过


full填充为 0.01,则cumsum期望值约为42949672.97,logcumsumexp期望值约为22.1907发现
cumsum均与理论值有差异,但数值接近,用时相同;logcumsumexp的 torch 更接近理论值,paddle 仍有差异,且远远慢于 torch,等待算法进一步修复Pcard-85711