Merged
megamoe support situ and swigluoai #8868
megamoe support situ and swigluoai #8868
Merged
ranczhwAdd on Jul 17
ranczhw
ranczhwCollaborators
Jul 17

描述

megamoe A2 A3 支持不同的激活类型,支持situ,swigluoai,swiglustep
放开了 intermediateHidden 最大值的限制
ep最大目前支持到了128

关联的Issue

测试

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for ranczhw's contribution.)
ranczhwranczhwCollaborators
Jul 17 Created pull request, commit 686b08ab
atomgit-bot
atomgit-bot
Jul 17 Comments:

变更摘要

该 PR 对 MegaMoe 的 SwiGLU epilogue 进行了 UB 分块(tiling)优化,核心思想是将原来一次性处理整行(N 维度)的方式改为按固定大小 TILE_LENGTH = 2048 的 tile 进行处理,使 UB 占用与中间隐藏层大小解耦。同时将 SwiGLU 激活计算抽取为独立的 SwigluActivation 结构体,移除了 MAX_INTERMEDIATE_HIDDEN 的上限约束,并增加了编译期 UB 容量校验。整体上使得算子能够支持更大规模的 intermediate_hidden(如 28672),而不受 UB 大小限制。

主要改动

  • 引入固定 Tile 分块机制替代整行处理:在 block_epilogue_pertoken_swiglu.hpp、block_epilogue_w4a8post_pertoken_swiglu.hpp 及两个 A2 变体文件中,将原来按 blockN 或 ChunkTileLen 一次性分配 UB 缓冲并处理的方式,全部改为按 TILE_LENGTH = 2048 进行循环分块处理,新增 ComputeTile、QuantizeAndCopyTile、AdvanceStage、TileLength、GetTaskRange 等辅助方法,buffer 分配也全部改用 TILE_LENGTH 定长。

  • 抽取 SwigluActivation 激活函数:新增 gated_activation.hpp 文件,定义 GATED_ACTIVATION_TILE_LENGTH = 2048 常量和 SwigluActivation 结构体,其 Compute 静态方法封装了 SiLU(gate)×up 的计算逻辑(含可选的 clamp),原先分散在各 epilogue 中的激活计算代码统一收敛到此接口。

  • 移除 MAX_INTERMEDIATE_HIDDEN 上限:在 mega_moe_tiling_arch22.cpp 的 CheckWeight2Input 中,删除了 MAX_INTERMEDIATE_HIDDEN = 3072 的上限校验,仅保留下限 MIN_INTERMEDIATE_HIDDEN 检查,同时修复了对齐校验中误用 N 而非 n2 的问题,使得 >3072 的中间隐藏层大小可以合法通过 tiling 校验。

  • 增加编译期 UB 容量静态断言:在三个 BlockEpilogue 特化中新增 BUFFER_SIZE 常量表达式,通过 static_assert(BUFFER_SIZE < ArchTag::UB_SIZE, ...) 在编译期验证分块后的缓冲区不会超出 UB 总容量,避免运行时溢出。

  • 调度策略类型增加 Activation 别名:在 dispatch_policy_custom.hpp 中为 EpilogueAtlasA2PerTokenDequantSwigluQuant、EpilogueAtlasA2W4A8PostPerTokenDequantSwigluQuant、EpilogueAtlasA2PerTokenDequantSwigluQuantInt8 和 EpilogueAtlasA2PerTokenDequantSwigluQuantBF16 四个策略分别添加了 using Activation = Catlass::Epilogue::SwigluActivation,使 epilogue 可通过策略获取激活类型。

  • 量化路径改为两趟处理:对于带量化的 epilogue 变体,第一趟遍历所有 tile 计算整行的 rowAbsMax,第二趟重新计算每个 tile 并使用统一的 quantMultiplier 进行量化和写出,保证了 per-token 动态量化的全局一致性。

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

CLA Signature Pass

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

likedislike
CANN-robot
CANN-robotCollaborators
Jul 17 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
*/*/README.md ✅ 蒋礼锐, 俞郑中, 吴瑶 (3/2) ✅ 吴瑶 (1/1)
*/*/op_host/*_def.cpp ✅ 王永光, 蒋礼锐, 俞郑中 (3/2) ✅ 王永光 (1/1)
mc2 ✅ 蒋礼锐, 俞郑中 (2/2) ✅ 蒋礼锐, 俞郑中 (2/1)
sig-ops-transformer ✅ 蒋礼锐, 俞郑中 (2/2) ✅ 俞郑中, 蒋礼锐 (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
284 messages are collapsed here。 See more
CANN-robot
CANN-robotCollaborators
Aug 7 Comments:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
ZhuXueDoc

likedislike
jiang-lirui
jiang-liruiCollaborators
Aug 10 Comments:

/approve
/lgtm

likedislike
CANN-robot
CANN-robotCollaborators
Aug 10 Comments:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
ZhuXueDoc

likedislike
CANN-robotCANN-robotCollaborators
Aug 10 Added label: lgtm
CANN-robotCANN-robotCollaborators
Aug 10 Merged pull request