Merged
feat: all_gather_matmul_v2支持mxfp4量化 kernel实现 #7193
dbtzyAdd on Jun 18
feat: all_gather_matmul_v2支持mxfp4量化 kernel实现 #7193
Merged
Pull Request has been successfully merged by CANN-robot.
(Thank you for dbtzy's contribution.)Jun 18 Added label: stat/needs-squash
Jun 18 Added label: cann-cla/yes
CANN-robot
Jun 18 Comments:
Jun 18 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 |
|---|---|---|
| */*/op_api/aclnn*.h | ✅ 汤磊, 刘丹 (2/2) | ✅ 汤磊 (1/1) |
| */*/op_host/*_def.cpp | ✅ 汤磊, 刘丹 (2/2) | ✅ 汤磊 (1/1) |
| mc2 | ✅ 刘丹, captainmiaow (2/2) | ✅ 刘丹 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
tongzy1242, thanks for your pull request. All authors of the commits have signed the CLA. 👍


Jun 22 Pre merge succeeded (commit_id: 6308f52794e16ce53a90a41e3659e969f0d57ef9)
326 messages are collapsed here。 See more
Jul 9 Removed label: ci-pipeline-running
Jul 9 Added label: ci-pipeline-passed
captainmiaow
Jul 9 Comments:
Jul 9 Comments:
/lgtm


Jul 9 Added label: lgtm
Jul 9 Merged pull request
描述
新增AllGatherMatmul算子mxfp4量化单算子通路。解决了AllGatherMatmul算子无法对输入数据类型是float4_e2m1的数据类型做MX量化的缺陷。
关联的Issue
#3257
测试
本地开发者自验证和RDV验证通过
文档更新
类型标签
代码检视报告 — PR #7193
检视概览
检视统计
发现问题(HIGH 置信度)
[GEN-4.2] 魔鬼数字 — FP4 PR 变更中存在两处裸数字常量
问题描述:FP4 PR 变更中存在两处魔鬼数字(未命名的裸数字常量),违反"禁止使用魔鬼数字\字符串"规则。虽然注释解释了含义,但按编码规范应使用命名常量。
代码片段 1(mc2/all_gather_matmul_v2/op_host/op_tiling/all_gather_matmul_tiling_base.cpp 行 671-678):
uint64_t AllGatherMatmulTilingBase::CalcGatherLen(uint32_t dimA, uint32_t dimB, uint64_t alignAddrLen) { // FP4每字节存放2个元素,按元素数/2计字节数;其余dtype按元素数*dtypeSize if (CheckSupportDtype(args_.geAType, FP4_DTYPE_SUPPORT_LIST)) { return mc2tiling::AlignUp(static_cast<uint64_t>(dimA) * static_cast<uint64_t>(dimB) / 2U, alignAddrLen); } return mc2tiling::AlignUp(dimA * dimB * args_.inputDtypeSize, alignAddrLen); }/ 2U是裸数字,语义为"FP4每字节含2个数据元素",但未定义为命名常量。Kernel侧已定义PF4_DATA_NUM_PER_BYTE = 2(common.h:46),Host侧应引用或定义等价常量。代码片段 2(mc2/all_gather_matmul_v2/op_host/op_tiling/arch35/all_gather_quant_bmm_tiling.cpp 行 690-702):
CutResult AllGatherQuantBmmTiling::GetTilingResult() { AllGatherMMFitBalanceTiling tileFormulate(args_, KernelType::ALL_GATHER, TopoType::STANDARD_CARD); CutResult result = tileFormulate.GetTiling(); if (isFp4_) { AdjustCutResultForHCCL(result, args_.mValue, args_.kValue / EVEN_ALIGN, 1, args_.rankDim, opName_); } else { AdjustCutResultForHCCL(result, args_.mValue, args_.kValue, args_.inputDtypeSize, args_.rankDim, opName_); } return result; }1是裸数字,语义为"FP4通信时dtypeSize=1字节"。对比 else 分支使用args_.inputDtypeSize命名变量,FP4分支直接硬编码1是魔鬼数字。假设检验证据:
正向证据:
/ 2U裸数字未定义为命名常量1裸数字硬编码 dtypeSizePF4_DATA_NUM_PER_BYTE常量可用负向证据:
/ 2U的语义1的语义可从函数参数名推断自信值 = 40+40+20+15-15-15 = 85% ≥ 70% → 判定违规
修复建议:
constexpr uint64_t FP4_DATA_NUM_PER_BYTE = 2;(或引用已有定义),替换 CalcGatherLen 中的/ 2U为/ FP4_DATA_NUM_PER_BYTEconstexpr uint64_t FP4_COMM_DTYPE_SIZE = 1;或类似命名常量,替换裸数字1FP4_COMM_BYTE_SIZE = 1和FP4_ELEMENT_PER_BYTE = 2,集中管理 FP4 编码常量需关注(建议改进)
SEC-3.5 防御性 null 检查建议
问题描述:
CheckMXFP4Input中scaleInv1Desc通过GetOptionalInputDesc获取后直接解引用(->GetDataType()),虽上游CheckInputValid()已校验非null,但建议在本函数内添加防御性null检查以增强鲁棒性。代码片段(mc2/all_gather_matmul_v2/op_host/op_tiling/arch35/all_gather_quant_bmm_tiling.cpp 行 151-162):
auto scaleInv1Desc = context_->GetOptionalInputDesc(SCALE_INV1); OP_TILING_CHECK(args_.kValue % EVEN_ALIGN != 0, OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(...), return ge::GRAPH_FAILED); OP_TILING_CHECK((!args_.isBTrans), ...); OP_TILING_CHECK((scaleInv1Desc->GetDataType() != ge::DataType::DT_FLOAT8_E8M0), ...); // 直接解引用建议修复:
OP_TILING_CHECK(scaleInv1Desc == nullptr, OP_LOGE(opName_, "scale1 is nullptr in mxfp4 scene"), return ge::GRAPH_FAILED); OP_TILING_CHECK((scaleInv1Desc->GetDataType() != ge::DataType::DT_FLOAT8_E8M0), ...);GEN-4.2 低风险建议 — CalcGatherLen
/ 2U命名常量化/ 2U虽有注释解释,建议改为命名常量提升可读性和维护性。这与上面的 FAIL 发现一致(同一条例,同一代码位置)。通过条例
高危安全(SEC/TOPK 安全类):
SEC-1.1, SEC-1.2, SEC-1.3, SEC-2.1, SEC-2.2, SEC-2.3, SEC-3.1, SEC-3.3, SEC-3.5, SEC-3.4, SEC-4.1, SEC-4.2, SEC-9.1, SEC-10.3, SEC-10.4, SEC-10.5, SEC-5.1~5.4, SEC-8.1~8.3, SEC-11.1~11.4, TOPK-8
TOPK:
TOPK-1, TOPK-2, TOPK-3, TOPK-4, TOPK-5, TOPK-6, TOPK-7, TOPK-10, TOPK-12
领域规则(MC2):
MC2-01, MC2-02, MC2-03, MC2-04, MC2-09, MC2-13, MC2-14, MC2-15, MC2-17, MC2-18
性能(PERF/PREC/TIL):
PERF-2, PERF-7, PREC-2, TIL-1, TIL-2, TIL-3
通用规范(GEN/API):
GEN-1.1, GEN-4.3, GEN-5.2, GEN-7.1, GEN-14.4, API-12
核心 FP4 逻辑验证结论