Merged
处理swiglu_group和swiglu_group_quant的自动反向未在dispatcher层注册的问题 #8389
liuhongpengAdd on Aug 7
处理swiglu_group和swiglu_group_quant的自动反向未在dispatcher层注册的问题 #8389
Merged
Merged fromliu_hp711/ops-nnsgqgintocann/ops-nnmaster
Pull Request has been successfully merged by CANN-robot.
(Thank you for liuhongpeng's contribution.)Aug 7 Created pull request, commit c62c2749
atomgit-bot
Aug 7 Comments:
Aug 7 Comments:
变更摘要
此 PR 主要解决 swiglu_group 算子的自动反向传播未在 dispatcher 层注册的问题,导致图模式(torch.compile)下部分场景的反向传播异常。核心改动是将反向传播逻辑从自定义的 torch.autograd.Function 子类 SwigluGroupFn 迁移至 torch.library.register_autograd 进行注册,使 autograd 在 dispatcher 层生效;同时调整了算子签名中参数的位置/关键字属性,将 weight 和 group_index 变为位置参数,clamp_limit 变为 keyword-only 参数。
主要改动
- 用
torch.library.register_autograd替换自定义SwigluGroupFn:移除原有的SwigluGroupFn(torch.autograd.Function)类,新增_swiglu_group_backward_autograd和_swiglu_group_setup_context函数,并通过torch.library.register_autograd("cann_ops_nn::swiglu_group", ...)在 dispatcher 层注册 autograd,使反向传播在图模式下正常工作。 - 调整算子签名中参数的关键字属性:将
swiglu_group的 schema 从(Tensor x, *, Tensor? weight, Tensor? group_index, float clamp_limit)改为(Tensor x, Tensor? weight, Tensor? group_index, *, float clamp_limit),即weight和group_index变为位置参数,clamp_limit变为 keyword-only 参数。 - 同步修改 meta 注册和实现函数的参数顺序:
swiglu_group_meta和swiglu_group实现的函数签名均从(x, *, weight, group_index, clamp_limit)调整为(x, weight, group_index, *, clamp_limit),与 schema 保持一致。 - 同步调整
graph_convert_swiglu_group.py中的 FX 转换器签名:将convert_swiglu_group函数的weight和group_index参数从*之后移至*之前,匹配算子签名变更。


Incorrect?
atomgit-bot
Aug 7 Comments:
Aug 7 Comments:
Aug 7 Added label: cann-cla/yes
CANN-robot
Aug 7 Comments:
Aug 7 Comments:
Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| activation | ✅ 黄迪, 唐玮玮 (2/2) | ✅ 黄迪 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
liu_hp711, thanks for your pull request. All authors of the commits have signed the CLA. 👍


65 messages are collapsed here。 See more
kevin_huang1234
Aug 12 Comments:
Aug 12 Comments:
/lgtm
/approve


Aug 12 Added label: lgtmapproved
Aug 12 Closed associated issue
Aug 12 Merged pull request
CANN-robot
Aug 12 Comments:
Aug 12 Comments:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
swiglu_group和swiglu_group_quant的自动反向未在dispatcher层,导致在跑图模式情况下自动反向部分场景出现问题。
关联的Issue
https://gitcode.com/cann/ops-nn/issues/4636
测试
自动反向功能的单算子和图模式验证OK,ST用例OK,冒烟OK。
文档更新
类型标签
AI/Agent生成声明