Merged
mxfp8量化(quant2\3\16\17提升33.5%)、透传(quant-1提升20.7%)、group量化(quant4\5\14\15提升65.8%) #9199
mxfp8量化(quant2\3\16\17提升33.5%)、透传(quant-1提升20.7%)、group量化(quant4\5\14\15提升65.8%) #9199
Merged
cpy_123456Add on Jul 27
cpy_123456
cpy_123456Collaborators
Jul 27

描述

性能优化: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 && 二级冒烟

文档更新

不涉及

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for cpy_123456's contribution.)
cpy_123456cpy_123456Collaborators
Jul 27 Created pull request, commit 6954b03b
atomgit-bot
atomgit-bot
Jul 27 Comments:

变更摘要

此 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 的分支。

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Jul 27 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Jul 27 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
moe ✅ guoqiuhao, 宋恺 (2/2) ✅ guoqiuhao, 宋恺 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies 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. 👍

likedislike
CANN-robotCANN-robotCollaborators
Jul 27 Set juyangokok,monologue815,chen-linxin4,yu-xinjie62,jiang-lirui,Allan_Yu,songkai111,liudan12,cc-z,mabing1118,guoqiuhao as approver
105 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Jul 28 Added label: ci-pipeline-passed
songkai111
songkai111Collaborators
Jul 28 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Jul 28 Added label: lgtm
CANN-robotCANN-robotCollaborators
Jul 28 Closed associated issue
CANN-robotCANN-robotCollaborators
Jul 28 Merged pull request