Merged
Feat(MegaMoe): support swiglustep and swigluoai #9971
OblivionZHUAdd on Aug 12
Feat(MegaMoe): support swiglustep and swigluoai #9971
Merged
OblivionZHUAdd on Aug 12
Merged fromDeleted :masterintocann/ops-transformermaster
OblivionZHU
OblivionZHUCollaborators
Aug 12

描述

修改说明

本 PR 为 A5(arch35)MegaMoe 的激活与 MX 量化融合流程新增 swiglustep 和 swigluoai 支持,并对现有激活代码进行模块化重构。

主要修改

  • Host Tiling 新增 swiglustep、swigluoai 激活识别、参数校验、默认值设置和 TilingData 赋值。
  • 将激活参数校验从空指针检查函数中拆分,明确区分指针合法性校验和功能参数校验。
  • 新增 Host/Kernel 共用的 MegaMoeActMode、MegaMoeActSubMode 枚举,替代两侧分散维护的裸值 0/1/2/3。TilingData 仍使用 uint8_t,不改变现有布局。
  • 新增 gated_activation.h,集中实现 SwiGLU、SwiGLU-Step、SwiGLU-OAI 和 SiTU 激活流程。
  • SwiGLU 和 SwiGLU-Step 复用同一套模板实现,通过编译期参数区分裁剪位置。
  • 将激活上下文准备与分派封装到 VFDoActivation,使 VFDoActivationAndQuantForMX 仅负责组织激活和后续 MX 量化流程。
  • 保留非交织/交织输入布局、ping-pong UB 偏移、尾块补零和 TopK 权重预取支持。
  • 清理冗余常量、重复赋值及临时说明性注释。

激活参数约束

activation activationParams 默认值/约束
swiglu 空或 [clamp] clamp 默认取 float 最大值,要求非负且非 NaN
swiglustep 空或 [clamp] 与 swiglu 相同
swigluoai 空或 [clamp, alpha, beta] 默认 clamp=float max、alpha=1.702、beta=1.0;alpha/beta 要求为有限值
situglu [beta] 或 [beta, linear_beta] 参数要求为有限非零值

兼容性说明

  • 保留原有 swiglu 和 situglu 行为。
  • URMA 拓扑当前仅允许使用 swiglu,其他激活在 Tiling 阶段拦截,不修改 URMA Kernel。

关联的Issue

3980[Requirement|需求建议]: MegaMoe建议新增激活方式

测试

二级冒烟、算子泛化等。

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for OblivionZHU's contribution.)
OblivionZHUOblivionZHUCollaborators
Aug 12 Created pull request, commit b4bb406e
atomgit-bot
atomgit-bot
Aug 12 Comments:

变更摘要

该 PR 为 MegaMoe 算子新增了两种门控激活模式 swiglustep 和 swigluoai,并在 A5 (arch35) 平台上提供对应的 kernel 实现。同时,将原有的 ActivationFlowSwiGLU、ActivationFlowSiTU 及 COMPUTE_TANH_TWOPATH 宏从 block_epilogue_activation_mx_quant.h 重构提取到新文件 gated_activation.h 中,以改善代码组织。

主要改动

  • 新增 swiglustep 激活模式: 在 tiling 校验层(mega_moe_tiling.cpp)中增加对 "swiglustep" 字符串的识别,参数校验与 swiglu 一致(0 或 1 个 clamp 参数);tiling 数据中设定 actMode=2、actSubMode=0;kernel 实现公式为 min(SiLU(gate), clamp) × clip(up, ±clamp),与 SwiGLU 的区别在于 gate 不再做输入裁剪,而是对 SiLU 输出做上限裁剪。

  • 新增 swigluoai 激活模式: tiling 校验层要求 swigluoai 必须提供 3 个参数 [clamp, alpha, beta],并对各参数进行有效性校验(clamp ≥ 0、alpha/beta 有限);tiling 数据中设定 actMode=3,alpha/beta 从参数中取值;kernel 实现公式为 (up + beta) × min(gate, clamp) × sigmoid(alpha × min(gate, clamp)),与 SwiGLU 的区别在于 up 裁剪后加上 beta,且 sigmoid 计算使用 -alpha*gate 替代 -gate。

  • 新增 ActMode 枚举值: 在 block_epilogue_activation_mx_quant.h 的 ActMode 枚举中新增 SWIGLU_STEP = 2 和 SWIGLU_OAI = 3,并在激活分派器 VFDoActivationAndQuantForMX 和运行时路由逻辑中增加对应的分支调用。

  • 重构提取 gated_activation.h: 将 COMPUTE_TANH_TWOPATH 宏以及 ActivationFlowSwiGLU、ActivationFlowSiTU 的完整实现从 block_epilogue_activation_mx_quant.h 迁移至新文件 gated_activation.h,并在该文件中新增 ActivationFlowSwiGLUStep 和 ActivationFlowSwiGLUOai 两个 kernel 函数,通过 #include "gated_activation.h" 在原有位置引入。

  • URMA 拓扑限制: 在 tiling 校验层增加拓扑类型检查——当 topoType 为 TOPO_TYPE_URMA 时仅允许 swiglu 激活,禁止 swiglustep、swigluoai 等其他激活类型。

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Aug 12 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Aug 12 Comments:

CLA Signature Pass

OblivionZHU, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robot
CANN-robotCollaborators
Aug 12 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.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
mc2 ✅ yangzeheng, luobaiqing (2/2) ✅ yangzeheng (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

OblivionZHU, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
162 messages are collapsed here。 See more
luobq
luobqCollaborators
Aug 18 Comments:

/lgtm

likedislike
yangzeheng
yangzehengCollaborators
Aug 18 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Aug 18 Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
Aug 18 Merged pull request
OblivionZHUOblivionZHUCollaborators
Aug 18 Associated issue: [Requirement|需求建议]: MegaMoe建议新增激活方式