Merged
matmul_reduce_scatter_v2 add mxfp4 quant scene #8596
琪亚娜的圈外男友Add on Jul 10
matmul_reduce_scatter_v2 add mxfp4 quant scene #8596
Merged
琪亚娜的圈外男友Add on Jul 10
琪亚娜的圈外男友
琪亚娜的圈外男友Collaborators
Jul 10

描述

MatmulReduceScatterV2新增mxfp4量化场景

关联的Issue

https://gitcode.com/cann/ops-transformer/issues/3704

测试

本地验证,rdv验证

文档更新

mc2/matmul_reduce_scatter_v2/docs/aclnnMatmulReduceScatterV2.md

类型标签

PR #8596 检视报告

PR: matmul_reduce_scatter_v2 add mxfp4 quant scene
检视日期: 2026-07-13
变更文件: 10 | +95 / -39

一、变更概述

为 matmul_reduce_scatter_v2 算子新增 MXFP4(FLOAT4_E2M1)量化场景支持,同时将 reduceScatter 通信上限从 16 次调整为 63 次。

二、检视结论

级别 数量
严重 0
建议 3

结论:可合入。 无阻塞性问题,建议项可后续 PR 跟进。

三、建议项(不阻塞合入)

[建议1] CheckGroupSize 错误消息未覆盖 MXFP4

文件: quant_bmm_reduce_scatter_tiling.cpp:147

"The value of groupSize must be [1, 1, 32] in mxfp8 scene"

MXFP4 复用同一检查路径,错误消息仅提及 "mxfp8",建议更新为 "mxfp"。

[建议2] COMMMODE_INDEX 冗余定义

文件: quant_bmm_reduce_scatter_tiling.cpp:75

constexpr uint32_t COMMMODE_INDEX = 10;

该常量在此文件中无引用,matmul_reduce_scatter_tiling_base.cpp:46 已有同名定义。建议删除。

[建议3] FP4 DTypeSize 设为 1 可补充说明

文件: reduce_scatter_fit_balance_tiling.h:33-36

FLOAT4_E2M1 为 4bit 类型,DTypeSize 设为 1 byte(影响 L2 cache 计算和 isQuantMatmul_ 判定)。若为硬件打包对齐需要,建议补充注释说明。

四、正确修改确认

以下修改经深入验证,确认逻辑正确:

  1. 文档描述:第 21 行列出支持的数据类型和量化方式,后续章节详细描述各量化模式与数据类型的对应关系,结构清晰无歧义。
  2. op_def.cpp DtypeList 组合:新增 3 组 FLOAT4_E2M1(自身配对),x1/x2/bias/scale/output 各列表长度一致对齐,组合正确。
  3. TPL_INPUT 从 bool 改为 uint8_t:模板参数空间扩展合理,ASCENDC_TPL_2_BW 位宽足以容纳 3 个值(0/1/2),kernel 中 if constexpr 比较均为 uint8_t 对比,编译无歧义。
  4. tiling key 注册:FP4 仅在 MXFP 场景(scaleType=1)注册 INPUT_TYPE_IS_FP4,与 kernel 中 MXFP 路径一致,pertensor/perblock 路径不涉及 FP4,逻辑正确。
  5. isMxfp4_ 设置时机:在 SetScene() 的 MXFP_MODE 分支内设置,在 MxfpSceneParamCheck() 和 GetTilingKey() 中使用,时序正确(SetScene → CheckInput → MxfpSceneParamCheck → GetTilingKey)。
  6. HCCL 限制 16→63:使用独立常量 REDUCE_SCATTER_V2_HCCL_NUM_LIMIT 替代共享的 ALL_GATHER_HCCL_NUM_LIMIT,避免影响其他算子,设计合理。
  7. CheckMxScaleDim 错误消息改进:将变量名替换为 ceilDiv(xDim, 64) 表达式,提升用户可读性。
  8. API 层 CheckLowAccuracyCase:FP4 与 HIFLOAT8 共用"类型必须相同"约束,符合文档约束规则。
  9. MXFP4 kValue 偶数校验:MxfpSceneParamCheck 中新增 args_.kValue % EVEN_ALIGN != 0 检查,与文档约束一致。
  10. Kernel 预处理条件扩展:#if 条件新增 DT_FLOAT4_E2M1 分支,正确复用 FP8/HIF8 的 quant_bmm 实现。

五、总结

PR 整体质量较好,MXFP4 场景在 API、OpDef、Tiling、Kernel 各层修改逻辑自洽,无阻塞性问题。3 个建议项均为日志/注释类优化,不影响功能正确性,可后续 PR 跟进。

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 琪亚娜的圈外男友's contribution.)
琪亚娜的圈外男友琪亚娜的圈外男友Collaborators
Jul 10 Created pull request, commit 68d6b85a
atomgit-bot
atomgit-bot
Jul 10 Comments:

变更摘要

此 PR 为 matmul_reduce_scatter_v2 算子新增 MXFP4 (DT_FLOAT4_E2M1) 量化场景的完整支持,覆盖 API 类型校验、算子定义、Tiling 参数推导、HCCL 通信限制调整及性能建模等多个层次。同时将 HCCL 通信次数上限从 16 提升至 63,并修正了部分错误日志中的尺寸描述。

主要改动

  • 新增 DT_FLOAT4_E2M1 数据类型支持: 在 aclnn_matmul_reduce_scatter_v2.cpp 的 DTYPE_SUPPORT_LIST 与 INPUT_SUPPORT_TYPE_LOW_ACCURACY 中加入 DT_FLOAT4_E2M1;在 matmul_reduce_scatter_v2_def.cpp 的 Input/Output 类型列表中为 x1、x2、bias 及 scale 等输入追加对应的 DT_FLOAT4_E2M1 或配套的 scale 类型组合。
  • MXFP4 场景识别与参数校验: 在 QuantBmmReduceScatterTiling 中新增 isMxfp4_ 标志位;SetScene() 在检测到 x1/x2 均为 DT_FLOAT4_E2M1 时将该标志置为 true;MxfpSceneParamCheck() 中强制 MXFP4 场景下 x1/x2 类型必须相同且 kValue 必须为偶数,否则报错。
  • 引入 INPUT_TYPE_IS_FP4 并适配 Tiling Key: 在 matmul_reduce_scatter_v2_apt_tiling_key.h 定义 INPUT_TYPE_IS_FP4 = 2 并加入模板选择列表;GetTilingKey() 在 isMxfp4_ 为真时使用 INPUT_TYPE_IS_FP4 替代 INPUT_TYPE_IS_FP8 生成 tiling key,确保 kernel 模板能正确选取 MXFP4 分支。
  • 新增 MXDTYPE_SUPPORT_LIST 与 HCCL 限制调整: 在 matmul_reduce_scatter_tiling_base.h 中定义 MXDTYPE_SUPPORT_LIST(包含 DT_FLOAT8_E4M3FN、DT_FLOAT8_E5M2 和 DT_FLOAT4_E2M1),替换原有 MXFP8DTYPE_SUPPORT_LIST 引用;同时将 HCCL 通信次数上限从 16 提升至 REDUCE_SCATTER_V2_HCCL_NUM_LIMIT = 63,并更新相关校验注释与错误信息。
  • FP4 计算性能建模适配: 在 reduce_scatter_fit_balance_tiling.h 中新增 RS_FP4_COMPUTE_PER_CYCLE_RATIO = 4 常量,当 geAType 为 DT_FLOAT4_E2M1 时将矩阵 A/B 的 dtype 大小设为 1、计算类型设为 QUANT,并按 4 倍比例调整 computesPerCycle,以正确估算 FP4 场景的 compute-communication 平衡。
likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Jul 10 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Jul 10 Comments:

CLA Signature Pass

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

likedislike
CANN-robot
CANN-robotCollaborators
Jul 10 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
*/*/docs/acl*.md ✅ 陈娇, 蔡雯雯, 吴瑶 (3/2) ✅ 陈娇, 蔡雯雯 (2/1)
*/*/op_host/*_def.cpp ✅ 汤磊, 王永光 (2/2) ✅ 汤磊, 王永光 (2/1)
mc2 ✅ wang-minbo, libohao6 (2/2) ✅ libohao6, wang-minbo (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Jul 10 Set captainmiaow,monologue815,jiang-lirui,Allan_Yu,wang-minbo,tgwsakiko_,liudan12,chenjunjian11,yangzeheng,liuboxi,gitcode-chenjiao,zhouwenfang,libohao6,mabing1118,wangyongguang,macech as approver
10 event messages are collapsed here。 See more
琪亚娜的圈外男友琪亚娜的圈外男友Collaborators
Jul 10 Modify description of pull request
琪亚娜的圈外男友
琪亚娜的圈外男友Collaborators
Jul 10 Comments:

/compile

likedislike
琪亚娜的圈外男友琪亚娜的圈外男友Collaborators
Jul 10 Pre merge succeeded (commit_id: 88b286fb247a9e84f149ceeb9bf95c8f69081aa7)
CANN-robotCANN-robotCollaborators
Jul 10 Added label: ci-pipeline-running
CANN-robot
CANN-robotCollaborators
Jul 10 Comments:

流水线任务触发成功
任务链接 [564324df3fb9488388822c0bc5098452][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Pre ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental_950_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental_950_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_classify ✅ SUCCESS >>>>>
Compile_harmony-infer-chs-transformer ✅ SUCCESS >>>>>
UT_Test ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
API_Check ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>
UT_Test_report_lcov ⚠️ WARNING >>>>>

[2026-07-10 18:01:10]    CI执行结束

likedislike
chenjiao
chenjiaoCollaborators
Jul 10 Comments:

/approve

likedislike
吴瑶
吴瑶Collaborators
Jul 10 Comments:

/lgtm

likedislike
CANN-robot
CANN-robotCollaborators
Jul 10 Comments:

流水线任务触发成功
任务链接 [c6928b5f77894a259342a22d3a82a517][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_style ✅ SUCCESS >>>>>
StaticCheck_codespell ⚠️ WARNING >>>>>
StaticCheck_link_validity ✅ SUCCESS
StaticCheck_resource_existence ✅ SUCCESS
StaticCheck_tag_closed ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_checkpr ✅ SUCCESS
codecheck_precommit ⚠️ WARNING >>>>> >>>>>

[2026-07-10 17:47:52]    CI执行结束

likedislike
caiwenwen
caiwenwenCollaborators
Jul 10 Comments:

/approve

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Jul 10 Added label: api-check-pass
CANN-robotCANN-robotCollaborators
Jul 10 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Jul 10 Added label: ci-pipeline-passed
tang-lei01
tang-lei01Collaborators
Jul 10 Comments:

/approve

likedislike
wangyongguang
wangyongguangCollaborators
Jul 11 Comments:

/approve

likedislike
Beau Howard
Beau HowardCollaborators
Jul 13 Comments:

/approve

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Jul 13 Added label: approved
琪亚娜的圈外男友琪亚娜的圈外男友Collaborators
Jul 13 Modify description of pull request
wang-minbo
wang-minboCollaborators
Jul 13 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Jul 13 Added label: lgtm
CANN-robotCANN-robotCollaborators
Jul 13 Merged pull request