Pull Request has been successfully merged by CANN-robot.
(Thank you for cpy_123456's contribution.)变更摘要
此 PR 主要引入了 useGatherCopy 优化路径,在 SCATTER 索引模式下通过预先构建 gather 索引来实现 gather 风格的拷贝,减少不必要的数据搬运开销。同时重构了 FP8 PerGroup 量化流程,将原来的单一 ComputeFp8GroupQuantVF 函数拆分为 vfComputeAmax、vfComputeRoundScale、vfComputeData 三个独立阶段,并用整数指数最大值 fp8Emax_ 替代浮点最大值 fp8MaxValue_ 以提升计算效率。此外,简化了 RowIdxGather 类的实现(移除 Pipe/Queue 依赖),并扩展了多个量化模式对 gather-copy 路径的支持。
主要改动
-
新增
useGatherCopy控制字段: 在MoeInitRoutingV3Arch35TilingData结构体中新增useGatherCopy成员,并在ExpertTokensCount、MoeV3GatherFP8GroupQuant、MoeGatherOutMxfp8Quant、MoeV3GatherOutMxfp8、RowIdxGather等类中读取该字段以决定走 gather-copy 还是 scatter-copy 路径。 -
FP8 PerGroup 量化流程重构: 将
moe_v3_gather_fp8_group_quant.h中的ComputeFp8GroupQuantVF单一模板函数拆分为三个独立函数:vfComputeAmax(按组计算 amax)、vfComputeRoundScale(基于整数指数计算 roundScale 和 invScale)、vfComputeData(使用 invScale 进行量化),并用整数常量FP8_GROUP_E4M3_EMAX/FP8_GROUP_E5M2_EMAX替代原来的浮点FP8_GROUP_E4M3_MAX_VALUE/FP8_GROUP_E5M2_MAX_VALUE,新增amaxBuffer_和invScaleBuffer_两个临时缓冲区。 -
双路径拷贝支持(ScatterCopy / GatherCopy): 将
MoeV3GatherFP8GroupQuant::CopyExpandedXAndQuant拆分为ScatterCopyExpandedXAndQuant和GatherCopyExpandedXAndQuant两个方法;在GatherCopyExpandedXAndQuant中增加hasValidOut检查,跳过全部索引为 -1 的无效行;在moe_v3_gather_mxfp8_quant.h和moe_v3_gather_out_mxfp8.h中同样新增useGatherCopy_并以!useGatherCopy_替代原先的rowIdxType_ == SCATTER作为分发条件。 -
RowIdxGather简化与扩展: 移除TPipe、TQue等依赖,直接用asc_vf_call<ComputeSimt>完成索引映射;当useGatherCopy_且rowIdxType_为非零时,将expandedRowIdx的内容拷贝到 workspace 中的 gather 索引缓冲区,而非直接写回expandedRowIdx,支持后续的 gather-copy 流程。 -
扩展入口调度逻辑: 在
moe_init_routing_v3_apt.cpp中,将 GATHER 模式的RowIdxGather调用条件扩展至 MXFP8、FP8Group、StaticQuant、DynamicQuant、Int4Quant、HIF8、MXFP4、FP8PerBlock 等全部量化模式;同时新增 SCATTER 模式下当useGatherCopy为真时也调用RowIdxGather的分支。


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 |
|---|---|---|
| moe | ✅ guoqiuhao, 宋恺 (2/2) | ✅ guoqiuhao, 宋恺 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
cpy_123456, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/approve


描述
性能优化:mxfp8量化、透传、group量化
文件 变更类型
moe_init_routing_v3_tiling_arch35.cpp Tiling 逻辑:新增 useGatherCopy 决策、UB 预算修正、Workspace 精简
moe_init_routing_v3_arch35_tiling_def.h Tiling 数据结构:新增 useGatherCopy 字段
moe_v3_gather_mxfp8_quant.h MXFP8 量化 kernel:新增 GatherCopy 模式 + hasValidOut 跳过
moe_v3_gather_fp8_group_quant.h FP8 Group 量化 kernel:计算流水线重构 + GatherCopy 模式
moe_v3_gather_out_mxfp8.h MXFP8 透传 kernel:新增 GatherCopy 模式 + hasValidOut 跳过
moe_v3_row_idx_gather.h RowIdxGather:移除 TPipe、支持 useGatherCopy 反向映射
moe_v3_expert_tokens_count.h ExpertTokensCount:适配 useGatherCopy 的 workspace 初始化
moe_init_routing_v3_apt.cpp Kernel 调度:适配 RowIdxGather 新接口、SCATTER 模式支持
test_moe_init_routing_v3_arch35_tiling.cpp 单测适配
关联的Issue
https://gitcode.com/cann/ops-transformer/issues/3950
测试
st && 二级冒烟
文档更新
不涉及
类型标签