已合并
megamoe优化,改成主E模式 #1466
zy_tt创建于 17 天前
megamoe优化,改成主E模式 #1466
已合并
zy_tt创建于 17 天前
zy_tt成员
17 天前

描述

本 PR 将 A3 MegaMoE 从阶段主序的 expert 间 overlap,改为 Expert 主序的阶段间 overlap,对 AIC/AIV 做固定分组 + 动态扩缩组,减少 AIV 搬运对 AIC 计算的带宽抢占。

原因: 基线 overlap 下 AIC 已接近满载,但 Dispatch/Combine 的 AIV 搬运仍与 GMM 争用 HBM;Unpermute 还要等全部 rank Combine 结束,尾部流水被拉长。大 M(512+)空间更大。

方法:

  1. AIC 分组动态调度
    物理核 0..15(16 个 AIC)做 GMM1,16..23(8 个 AIC)做 GMM2。前 fullAicGmm1ExpertCount=2 个 expert 用满 24 个 AIC 打 GMM1;之后 GMM1 缩到 16 核。GMM1 结束后,16 个 AIC 并入 GMM2,尾部 expert 由 24 核一起算。合组时刻由 GMM1 实际结束时间决定,不是写死最后几个 expert。

  2. AIV 分组与延后 Combine
    核 0..15 的 AIV0 做 Dispatch、AIV1 做 SwiGLU;核 16..23 的 AIV0 做 Combine(8 核)。Combine 数据量约为 Dispatch 的 2 倍,用 combineStartAfterGmm2Expert 按 shape 延后启动(M=16/128 等 3,M=1024/2048 等 2,M=32/64/512 不等待),避免和 Dispatch 抢同一段带宽。

  3. Unpermute 两阶段启动
    各 source rank Combine 达到 unpermutePhase1ReadyExpertCount 后,前 32 个 AIV 先处理已就绪数据;本卡 Combine 完成后,再加入 16 个 AIV,48 核处理剩余部分。不再整体等待所有 rank Combine 结束。

  4. 阶段同步
    组内用单向 software doorbell(arrival → coordinator 取共同进度 → ready)。epoch 按 expert 单调递增,支持 GMM1 24→16、GMM2 8→24 扩缩组。跨 rank 同样只等自己需要的 DataReady,不做全 rank barrier。

目标 shape:K=7168、N=4096、topK=8、expertPerRank=16,EP8/EP16。

测试

在 A3 上对 canonical shape 做了 EP8 / EP16、M=16~2048 的精度 + 性能对比(相对基线 overview.md 版本)。

A3 EP8

M 基线 avg (us) 优化 avg (us) 差值 (us) 加速率
16 584.09 573.08 -11.01 +1.88%
32 601.39 588.30 -13.09 +2.18%
64 634.77 627.77 -7.00 +1.10%
128 695.31 696.04 +0.73 -0.10%
512 1394.90 1234.03 -160.87 +11.53%
1024 2251.61 2016.18 -235.43 +10.46%
2048 4285.13 3756.88 -528.25 +12.33%

小 case 略有收益,大 case 约 10%~12%。

A3 EP16

M 基线 avg (us) 优化 avg (us) 差值 (us) 加速率
16 584.52 579.02 -5.50 +0.94%
32 605.18 600.38 -4.80 +0.79%
64 633.47 636.46 +2.99 -0.47%
128 717.26 707.30 -9.96 +1.39%
512 1337.57 1190.04 -147.53 +11.03%
1024 2261.64 1964.26 -297.38 +13.15%
2048 4380.82 3714.16 -666.66 +15.22%

小 case 基本持平或略优,大 case 约 11%~15%。

文档更新

  • 新增 kernels/manual/a2a3/dispatch_mega_combine/overview_v1.md:V1 overlap 原则、AIC/AIV 分组、expert 流水、tiling 参数表、同步模型及 EP8/EP16 性能对比
  • 新增 overlap 图:docs/figures/megamoe/v1_2048_overlap_pipeline.png(对比基线 2048_16rank_overlap_pipeline.png

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 zy_tt 的贡献)
Zzy_tt成员
17 天前 创建了 pull request,commit 94edf88b
CANN-robotCANN-robot成员
17 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
17 天前 评论:

CLA Signature Pass

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

likedislike
CANN-robot
CANN-robot成员
17 天前 评论:

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
docs echo_stone, HuangXingYuan_777 (2/2) echo_stone (1/1)
repo-cann/pto-isa echo_stone, HuangXingYuan_777 (2/2) echo_stone (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robot成员
17 天前 将zhangjian_hz11,csjlchen,bluesky901,changxianyu,Zhanghaijian,syfeng,yinjie27_,zhoubotcam,HuangXingYuan_777,linjiashu,WenboCodes,qukelin,ChanKaLok,kerwinair,echo_stone设为评审人
此处折叠了87条消息 查看更多
liulei成员
16 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
16 天前 添加了label:approved
代码行星
代码行星成员
16 天前 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
16 天前 添加了label:lgtm
CANN-robotCANN-robot成员
16 天前 合入了pull request