Pull Request has been successfully merged by CANN-robot.
(Thank you for ranczhw's contribution.)变更摘要
该 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 动态量化的全局一致性。


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


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


/approve
/lgtm


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


描述
megamoe A2 A3 支持不同的激活类型,支持situ,swigluoai,swiglustep
放开了 intermediateHidden 最大值的限制
ep最大目前支持到了128
关联的Issue
测试
文档更新
类型标签