Merged
A3 Dispatchv2算子的Win区支持rank旋转偏移,解决HCCS端口HASH极化问题 #10004
song-xinyi-001Add on Aug 13
A3 Dispatchv2算子的Win区支持rank旋转偏移,解决HCCS端口HASH极化问题 #10004
Merged
Merged fromDeleted :masterintocann/ops-transformermaster
Pull Request has been successfully merged by CANN-robot.
(Thank you for song-xinyi-001's contribution.)Aug 13 Created pull request, commit 8b258238
atomgit-bot
Aug 13 Comments:
Aug 13 Comments:
变更摘要
本 PR 主要针对 A3 Dispatchv2 算子在 Win 区写入/读回地址上的寻址逻辑,通过引入“源 rank 槽位旋转”来缓解 HCCS 端口 HASH 极化问题。改动集中在 mc2/moe_distribute_dispatch_v2/op_kernel/arch22/moe_distribute_dispatch_v2_full_mesh.h:将原本仅依赖源 rank(epRankId_)的槽位计算改为 ((epRankId_ + toRankId) % epWorldSize_),使同一源 rank 发往不同目的 rank 的 Token 地址在窗口内对角错峰,避免因窗口基址 2MB 对齐导致目的地址 bit[9~20] 恒为 0 而引发的单端口极化;同时在弹性场景下回退为原非旋转寻址,并在读回侧增加配对旋转。
主要改动
SendToMoeExpert写入地址改为旋转槽位:rankGM偏移由expertPerSizeOnWin_ * (epRankId_ * moeExpertNumPerRank_ + dstExpertId % moeExpertNumPerRank_)改为expertPerSizeOnWin_ * (((epRankId_ + toRankId) % epWorldSize_) * moeExpertNumPerRank_ + dstExpertId % moeExpertNumPerRank_),将目的 rank(toRankId)纳入槽位计算,使发往不同目的 rank 的地址不再都 2MB 对齐。- 第二处写入路径同步旋转:以
curExpertCnt计算偏移的写路径同样将槽位因子由epRankId_改为((epRankId_ + toRankId) % epWorldSize_),与第一条写路径保持一致的旋转寻址。 - 弹性场景回退非旋转:两处写路径在
hasElasticInfoFlag_为真时,均回退为原epRankId_ * moeExpertNumPerRank_的非旋转偏移,与读回侧守卫保持对称。 - 读回侧寻址配对旋转:
GetLocalWindowSrcDataBlockIdx在非isShareExpertRankFlag_且非hasElasticInfoFlag_时,将srcDataBlockIdx由srcExpertId % epWorldSize_ * localExpertNum + srcExpertId / epWorldSize_改为(srcExpertId + epRankId_) % epWorldSize_ * localExpertNum + srcExpertId / epWorldSize_,与写侧旋转槽位配对。


Incorrect?
Aug 13 Added label: cann-cla/yes
CANN-robot
Aug 13 Comments:
Aug 13 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 |
|---|---|---|
| mc2 | ✅ liuboxi, chenjunjian11 (2/2) | ✅ liuboxi (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
song-xinyi-001, thanks for your pull request. All authors of the commits have signed the CLA. 👍


CANN-robot
Aug 13 Comments:
Aug 13 Comments:
87 messages are collapsed here。 See more
Aug 13 Added label: ci-pipeline-passed
chenjianjun11
Aug 13 Comments:
Aug 13 Comments:
/lgtm


liuboxi
Aug 14 Comments:
Aug 14 Comments:
/approve


Aug 14 Added label: lgtmapproved
Aug 14 Merged pull request
背景:
A3 HCCS链路端口 hash 取目的地址 bit[9~20];由于窗口基址 2MB 对齐致 bit[9~20]=0;无旋转时固定源→多目的的 bit[9~20] 全同 → 单端口极化。
解决思路
旋转各源 rank 在目的Rank 的Win区排布(token保存位置),在目的窗内对角错峰;解决同源Rank在发送Token到不同目的Rank时,因目的地址bit[9~20]相同导致的HASH极化,可大幅降低 HCCS 端口哈希碰撞;
具体方案
旋转Win区Slot:slot = ((S+D)%W)*E + localExp(S=发端rank=epRankId_,D=目的rank=toRankId,W=epWorldSize_),Win区地址引入目的Rank后,同一个Rank发往不同Rank的Token,目的地址加入了expertPerSizeOnWin_ 偏移量,不再都2MB对齐,HCCS获取地址bit[9~20]作为HASH因子,不完全一致,确保能HASH开。
旋转有效条件:槽位步长 E=expertPerSizeOnWin_=axisMaxBS_×hCommuSize_ 需不等于2MB(确保发往不同Rank的Token地址在2MB大页维度上不对齐),绝大部分配置场景都能满足该约束。