已开启
[Feature]:_make_chunk_sort_map_kernel #323
guofanfeng23创建于 9月10日
9月10日 添加了label:feature
9月10日 修改了issue 的描述
9月10日 修改了issue 的描述
9月10日 修改了issue 的描述
9月10日 修改了issue 的描述
9月10日 修改了issue 的描述
9月10日 修改了issue 的描述
9月10日 修改了issue 的描述
9月10日 修改了issue 的描述
9月10日 修改了issue 的描述
9月10日 修改了issue 的描述
9月10日 修改了issue 的描述
9月10日 修改了issue 的描述
9月28日 关联了里程碑:MindSpeed 26.3.0
提交提案之前,请先检索仓库内是否已有相同的提案,如已有请在同一提案中进行讨论。
💻 需求背景
_make_chunk_sort_map_kernel根据split_sizes和sorted_indices生成row_id_map,供后续 copy kernel 完成 MoE token dispatch。原实现按 token block 与所有 expert 的 cumulative split 做二维比较和 reduction。随着 expert 数增大,临时向量规模随
token × expert增长,存在较高 UB 占用。当前现状
算子_make_chunk_sort_map_kernel 接入整网中有偶现的ub overflow ,但单算子又不复现,所以整改修改算子实现
期望实现的功能内容
希望通过修改算子算法,减少ub 占用
修改方案
将 make kernel 改为 expert-tile 实现:
BLOCK_TOKENS=128切分;pid和运行时 vector core 数进行 tile 轮转分配;row_id_map;该方式避免了原有 token-expert 二维临时矩阵,UB 占用主要由固定 tile 大小决定。
测试结果
精度验证
参考实现使用
torch.split + torch.catmegatron的小算子标杆,并通过:torch.testing.assert_close( actual, expected, rtol=0.0, atol=0.0, equal_nan=True, )已覆盖以下场景:
以上用例均通过,输出与参考实现完全一致,且 row_id_map 为合法 permutation。
内存安全验证
在 Ascend 910B3 上使用 mssanitizer 验证:
memcheck 未发现 target kernel 的 illegal read/write,racecheck 未发现跨 program 重叠写问题。
性能结果
测试指标为 _make_chunk_sort_map_kernel 的 device kernel time,使用Ascend 910B3 、warmup 5 次后采样。
Shape 原二维版本 Expert-tile 版本 加速比
当前性能数据仅针对 make kernel,不包含完整 sort API 的 host、cumsum、scatter 和 copy kernel 时间。完整端到端收益还需要结合实际 MoE 模型继续验证。
欢迎加入社区,感谢您对社区的贡献 🎉!