Skip to content

Conversation

zty-king
Copy link
Contributor

PR Category

Operator Mechanism

PR Types

Bug fixes

Description

fused_rotary_position_embedding API在use_neox_rotary_style为False时,反向传播计算逻辑存在错误。

  • Paddle 目前kernel中的反向计算逻辑
    def paddle_backward_rotary_pos_emb(dL_dxprime, cos, sin):
    return dL_dxprime * cos - rotate_half(dL_dxprime) * sin

  • 正确的反向计算逻辑,可以和torch自动微分的结果对齐
    def correct_backward_rotary_pos_emb(dL_dxprime, cos, sin):
    return dL_dxprime * cos - rotate_half(dL_dxprime * sin)

Copy link

paddle-bot bot commented Aug 18, 2025

你的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.

@paddle-bot paddle-bot bot added the contributor External developers label Aug 18, 2025
@zty-king
Copy link
Contributor Author

  • 为什么之前单测能通过?
image image rotate_half为True时,正确的计算顺序如下: image 而实际计算顺序是: image 但是旧的单测,rotate_half为True时,前半部分的sin数据和后半部分的sin数据是一致的,此时s1和s0二者相等,所以跑出来的数据也相等了。
  • 因此将后半部分sin都乘以0.1,以作区别,并验证原逻辑,test无法通过,现逻辑可以通过

@zty-king
Copy link
Contributor Author

/re-run all-failed

Copy link
Contributor

@wanghuancoder wanghuancoder left a comment

Choose a reason for hiding this comment

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

LGTM

@wanghuancoder wanghuancoder merged commit 4c75158 into PaddlePaddle:develop Aug 22, 2025
88 of 94 checks passed
Luckycheng222 pushed a commit to Luckycheng222/Paddle that referenced this pull request Aug 25, 2025
* fix_fused_rotary_position_embedding

* fix the ci test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants