Merged
feat(moe): 新增 MergeChunk 算子及 ACLNN 接口 #17055
feat(moe): 新增 MergeChunk 算子及 ACLNN 接口 #17055
Merged
TiMoAdd on 4 days ago
TiMo
TiMoCollaborators
4 days ago

描述

在正式目录 moe/merge_chunk 新增 MergeChunk 算子及两段式 ACLNN 接口。当前支持两路数据,每路两个 chunk(numPaths = numChunks = 2)。输入按路优先、chunk 次优排列,每个 chunk 的两路输入共享一份专家计数。输出为两路按专家拼接的数据,以及逐专家相加的一份 INT32 计数。

关联的Issue

#8906

测试

  • 2×2 实现已在 CANN 9.3.0 下完成 ascend910b 和 ascend910_93 编译打包。
  • A2 已验证 26 条 ACLNN 回归(含非 2×2 拒绝用例),并通过 138 条 FP16/BF16 ATK 精度用例。实机结果对应提交 ae2cc7c46。
  • A3 实机验证待补充。

文档更新

新增中英文算子说明、ACLNN 接口文档及 C++ 调用示例。

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for TiMo's contribution.)
TiMoTiMoCollaborators
4 days ago Created pull request, commit 609549d9
atomgit-bot
atomgit-bot
4 days ago Comments:

变更摘要

本 PR 将实验目录中的 MergeChunk2 迁移并重构为通用的 MergeChunk 算子,核心变化是由固定“两路 × 两个 chunk”的静态签名改为“路数 × 每路 chunk 数”均可独立配置的 TensorList 接口。算子原型改为动态输入 input_chunks、group_list_chunk 与动态输出 out_chunks、out_group_list,并新增 num_paths、num_chunks 两个必填属性;Shape 推导、Host Tiling、ACLNN 接口与 Kernel 均按该通用形态重写,其中数据按“每路按专家和 chunk 顺序拼接”输出,同一 chunk 的各路共用一份专家计数并汇总输出一份 group_list。同步更新 PyTorch 入口与 pytest 用例。

主要改动

  • 算子原型与形状推导通用化: merge_chunk_def.cpp 中 MergeChunk 将六路固定输入改为 DYNAMIC 的 input_chunks/group_list_chunk 与 out_chunks/out_group_list,新增 num_paths、num_chunks 属性,并关闭 DynamicRankSupportFlag;新增 merge_chunk_shape.h 提供共享的 Layout 结构与 ReadLayout/ReadListDimensions,统一校验路数、chunk 数、专家数、行数累加与 16 对齐的特征宽度。
  • Tiling 数据与切分策略重写: merge_chunk_tiling.h 的 MergeChunkTilingData 由固定字段 t1/t2/h1/h2 改为 paths、chunks、experts 加 rowsPerCore、extraCores、hidden、rowsPerTile 数组;merge_chunk_tiling.cpp 按最长 chunk 行数决定使用核数,统一设置 tiling key 为 0,并校验 UB 容量是否满足 TOTAL_BUFFER_BYTES。
  • Kernel 改为 TensorList 驱动: 新增 merge_chunk_impl.h 的 KernelMergeChunk,通过 ListTensorDesc 解析输入、计数与输出列表,按 chunk 逐路搬运 token 并按专家偏移写出;专家计数在 PrepareExpertOffsets 中逐 chunk 累加并校验总和等于总行数,merge_chunk_limits.h 定义 MAX_PATHS、MAX_CHUNKS、MAX_EXPERTS 等上限常量与 UB 缓冲区尺寸。
  • ACLNN 接口新增: 新增 aclnnMergeChunkGetWorkspaceSize/aclnnMergeChunk,参数为 inputChunks、groupListChunk 两个 aclTensorList、numPaths/numChunks 及 outChunks、outGroupList,内部校验列表长度、dtype(FP16/BF16 与 INT32)、连续性,并复用 ReadLayout 校验输出形状与专家计数形状。
  • PyTorch 入口与用例更新: torch_extension 中 schema 变更为 merge_chunk(Tensor[] input_chunks, Tensor[] group_list_chunk, int num_paths, int num_chunks) -> (Tensor[], Tensor),新增 StorageShapeTensorList 以按 storage shape 转换 TensorList;test_aclnn_merge_chunk.py 用参数化覆盖 FP16/BF16、多路多 chunk、32 路 × 32 chunk 及专家数 1024 等场景,并校验错误的路数会返回参数错误码。
likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
4 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
4 days ago 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.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
*/*/README.md ✅ cc-z, zzzzzzyf_, kdy18482276080 (3/2) ✅ zzzzzzyf_ (1/1)
*/*/docs/acl*.md ✅ zzzzzzyf_, kdy18482276080, cc-z (3/2) ✅ zzzzzzyf_ (1/1)
*/*/op_host/*_def.cpp ✅ 汤磊, kdy18482276080, cc-z (3/2) ✅ 汤磊 (1/1)
*/*/op_host/op_api/aclnn*.h ✅ 汤磊, kdy18482276080, cc-z (3/2) ✅ 汤磊 (1/1)
moe ✅ cc-z, kdy18482276080 (2/2) ✅ kdy18482276080, cc-z (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
4 days ago Set cpy_123456,cheng_zhiwei,juyangokok,monologue815,chen-linxin4,yu-xinjie62,jiang-lirui,Allan_Yu,gitee-duhuiping,tang-lei01,songkai111,liudan12,Wei_NaChuan,gitcode-chenjiao,cc-z,kdy18482276080,xuchengyang,lwx1255555,mabing1118,wangyongguang,fengying555682,guoqiuhao,Julius47,zzzzzzyf_,caiwenwen,yanglu-1 as approver
155 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
1 day ago Added label: lgtm
周云飞
周云飞Collaborators
1 day ago Comments:

/approve

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
1 day ago Added label: approved
CANN-robotCANN-robotCollaborators
1 day ago Closed associated issue
CANN-robotCANN-robotCollaborators
1 day ago Merged pull request