Skip to content

Conversation

@zhengshengning
Copy link
Contributor

@zhengshengning zhengshengning commented Sep 18, 2025

PR Category

Operator Mechanism

PR Types

Bug fixes

Description

简要改动总结

  1. sqrt 反向:由 one_half * dout / out 改为 dout / (two * out)。常量从 0.5 改为 2,等价重写但计算顺序不同,和 PyTorch 表达一致,可能带来更接近 PyTorch 的舍入结果(尤其在半精度/bfloat16)。

  2. rsqrt 反向:公式不变(-0.5 * dout * out^3),仅将连乘写成 (out * out * out) 的分组形式,逻辑与之前相同。

复测结果:
paddle.sqrt 对齐全部case(共460个)
paddle.rqrt 对齐全部case(共130个)

pcard-67164

Copy link
Contributor

@A-nnonymous A-nnonymous left a comment

Choose a reason for hiding this comment

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

LGTM

@zhengshengning zhengshengning merged commit f97f6c8 into PaddlePaddle:develop Sep 22, 2025
175 of 182 checks passed
XieYunshen pushed a commit to XieYunshen/Paddle that referenced this pull request Oct 14, 2025
paddle.sqrt and paddle.rsqrt accuracy and torch alignment
risemeup1 pushed a commit that referenced this pull request Oct 15, 2025
paddle.sqrt and paddle.rsqrt accuracy and torch alignment

Co-authored-by: zhengshengning <ningzhengsheng@baidu.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants