Merged
GMM支持a8w4支持新的数据类型: support float4 e1m2 for mx a8w4 #8748
GMM支持a8w4支持新的数据类型: support float4 e1m2 for mx a8w4 #8748
Merged
zhangzhizhuoAdd on Jul 15
zhangzhizhuo
zhangzhizhuoCollaborators
Jul 15

描述

GroupedMatmul WeightNz MX量化A8W4场景原支持 FLOAT4_E2M1 权重,本PR新增对 FLOAT4_E1M2 权重类型的支持。

主要修改如下:

  • 扩展ACLNN接口的数据类型校验,支持FLOAT8_E4M3FN × FLOAT4_E1M2。
  • 扩展GroupedMatmul算子注册、InferShape和Tiling的数据类型判断。
  • Kernel新增E1M2位解码参数,右移位数由E2M1的2调整为3,并使用对应的位掩码。
  • 复用已有E2M1通路的数据搬运、Tiling、Buffer和WeightNz计算流程。
  • 保持原有E2M1行为不变。

关联的Issue

关联Issue:https://gitcode.com/cann/ops-transformer/issues/3948
https://gitcode.com/cann/ops-transformer/issues/3176

测试

已补充以下测试:二级冒烟

测试结果:新增用例及存量回归用例通过。

文档更新

更新aclnnGroupedMatmulWeightNz.md:

  • 补充FLOAT4_E1M2支持类型。
  • 补充对应的输入组合、Shape及约束说明。
  • 保持原有文档结构和场景描述方式。

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for zhangzhizhuo's contribution.)
zhangzhizhuozhangzhizhuoCollaborators
Jul 15 Created pull request, commit 4f59ec9a
atomgit-bot
atomgit-bot
Jul 15 Comments:

变更摘要

本PR主要扩展了GMM(Grouped MatMul)在MX A8W4场景下的权重数据类型支持,新增 float4_e1m2(FP4 E1M2)格式。改动覆盖了API校验、infershape检查、tiling策略和内核计算等环节,使 FP4_E1M2 与已有的 FP4_E2M1 遵循相同的NZ格式对齐约束、tiling配置和代码路径,仅在kernel层面通过编译期常量分派不同的移位量和掩码进行比特级解码。

主要改动

  • API层权重对齐与校验扩展:在 aclnn_grouped_matmul.cpp 的 TransWeightToNzCheckAlign 和 CheckWeightQuantGMMWeightNz 中,将 DT_FLOAT4_E2M1 的所有判断条件同步扩展为也支持 DT_FLOAT4_E1M2,使新类型复用相同的4-bit对齐逻辑和 Fp8_e4m3fn-Fp4_e1m2-BF16/Fp16 组合校验。
  • Checker与Infershape中的类型识别:在 IsMxA8W4NZ() 及相关形状/参数校验函数中,新增对 DT_FLOAT4_E1M2 的判断分支,确保该类型在权重量化场景下同样满足32B对齐、antiquantScale和perTokenScale约束。
  • Tiling策略复用:在 GroupedWeightQuantBatchMatmulTiling 的 SetMatMulTiling、SetTilingKey、IsMxA8W4 和 CheckUnsupportedRemainingCases 中,将 weightDtype_ == DT_FLOAT4_E1M2 纳入MxA8W4分支,使其复用E2M1的 mxTypePara 配置、MTE模板和NZ格式约束。
  • Kernel层比特解码适配:在 basic_block_vf_mx.h 中新增 E1M2_SHIFT_RIGHT_SIZE = 0x3 和 E1M2_AND_MASK = 0x8E 常量,并在 AntiQuantMxA8W4NzNkVf 函数中通过 IsSameType 编译期判断选择对应的移位量与掩码,实现E1M2格式的比特级解包。
  • 宏与编译条件更新:在 grouped_matmul_utils.h 的 V310_GMM_ANTI_QUANT 宏中增加 ORIG_DTYPE_WEIGHT == DT_FLOAT4_E1M2 条件,确保新类型正确启用反量化宏。
likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Jul 15 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Jul 15 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) ✅ 陈娇 (1/1)
*/*/op_host/*_def.cpp ✅ 汤磊, 蒋礼锐 (2/2) ✅ 汤磊 (1/1)
gmm ✅ kknan, 陈康, 蒋礼锐 (3/2) ✅ kknan (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Jul 15 Set chenkang30,juyangokok,monologue815,chaotang233,wuyi_huawei,chen-linxin4,jiang-lirui,Allan_Yu,gitee-duhuiping,claire8090,liudan12,shi-rui,gitcode-chenjiao,cc-z,kknan,Ww7012,zhouwenfang,wenxin_fight,mabing1118,wuyao51511,caiwenwen as approver
95 messages are collapsed here。 See more
chen-kang30
chen-kang30Collaborators
Jul 31 Comments:

/lgtm

likedislike
jiang-lirui
jiang-liruiCollaborators
Jul 31 Comments:

/lgtm

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