已开启
feat: 补充昇腾 950 低精度量化用例 #107
feat: 补充昇腾 950 低精度量化用例 #107
已开启
wesseI创建于 21 天前
wesseI
wesseI
21 天前

昇腾 950 硬件低精度用例补充

背景

昇腾 950(Ascend 950PR/950DT)相比前代硬件新增了多种低精度量化能力(MXFP8/MXFP4、int4 packed、fp8 KV cache 等)。本 PR 基于实机(Ascend950PR ×8,CANN 9.1.0,torch_npu 2.9.0.post2)逐一验证后,为 npu-kernelbench/data/kernel_generator 补充低精度测试用例,并做必要的 definition 适配。

全部 33 条新增用例均在 950 实机上通过评测管线验证,调用无异常,输出无 NaN/Inf。

一、新增用例(33 条)

算子 用例 精度场景 说明
level4/FusedInferAttentionScore 051~062(12 条) int8 / int4 / fp8 KV 伪量化 decode 场景(Q_S=1)、BSH layout、分离式 key/value_antiquant_scale;051~058 int8 KV(fp16/bf16 × MHA/GQA),059~060 float8_e4m3fn KV,061~062 int4(int32 packed,H 维缩 8 倍)
level4/GroupedMatmulSwigluQuantV2 051~052(2 条) MXFP8 x/weight=float8_e4m3fn,scale 以 int8 位模式承载 e8m0;051 多分组、052 单分组
level4/QuantMatmul 058~059(2 条) fp8_e4m3fn / fp8_e5m2 双输入 fp8 量化矩阵乘
level4/WeightQuantBatchmatmul 049~050(2 条) int4 权重(perchannel) weight 为 int32(每元素 8 个 int4),fp16/bf16 双场景
level2/KvRmsnormRopeCache 051~052(2 条) int8 量化 KV cache k_cache/ckv_cache 为 int8,配 k_rope_scale/c_kv_scale 等量化参数
level2/SwigluQuant 053~054(2 条) int4 量化输出 dst_type="int4"(quint4x2 packed)
level1/DynamicQuant 043~044(2 条) int4 量化输出 dst_type="int4"(quint4x2 packed)
level1/Cat 052~053(2 条) fp8 拼接 float8_e4m3fn / float8_e5m2
level1/Add、Sort、TopK、Cumsum、Scatter、Index、Gather 各 1 条(7 条) int8 低精度覆盖补充

二、workload.jsonl 之外的修改及必要性

1. level4/GroupedMatmulSwigluQuantV2/definition.json

  • reference 增加 950 MX 量化分支:新增 x_dtype/weight_dtype/weight_scale_dtype/x_scale_dtype 参数透传与字符串→dtype 解析(_resolve_dtype)。
    必要性:MX 量化需要向 npu_grouped_matmul_swiglu_quant_v2 声明 fp8/fp4 dtype,原 reference 无此通路;算子对扩展 dtype 按对象 identity 校验,必须取 torch_npu 注册的 dtype 对象。
  • reference 增加设备分支(_soc_is_950:950 上跳过 weight 的 NZ 格式转换。
    必要性:950 强制回退 allow_internal_format,NZ 内部格式不可用,原有强制 NZ 转换导致全部 50 条存量 int8 用例在 950 上失败;改为设备分支后 950 走 ND 通路(25 条存量用例恢复可运行),其他设备行为不变。
  • outputs 从 2 个减为 1 个(仅主输出)
    必要性:MX 量化的第二输出为 float8_e8m0fnu scale,评测器数值比对需将其转 float32,而 torch_npu 的 copy 算子缺少 e8m0 实现(报 561103),比对必然失败;仅声明主输出可规避。存量用例在 950 上本就跑不通,此调整无实际比对损失。

2. level1/DynamicQuant/definition.json

  • reference 增加 dst_type 参数透传与字符串→dtype 映射("int4"torch.quint4x2);inputs 声明顺序与 run 签名对齐(评测管线按位置传参)。
  • 必要性npu_dynamic_quant 的 dst_type 只接受 torch dtype 对象,workload 标量需映射;int4 量化输出依赖该参数。

3. level4/WeightQuantBatchmatmul/definition.json

  • reference 增加分支:weight.dtype == int32 时自动调用 npu_convert_weight_to_int4pack 转换为硬件打包布局。
  • 必要性:int4 权重必须是硬件专用的打包布局,静态 workload 无法直接构造合法位模式,需在 reference 内做数据预处理。

4. level4/QuantMatmul/definition.json

  • reference 增加分支:int32 输入(int4 场景)且 scale 为 float32 时,自动经 npu_trans_quant_param 转换为 int64 格式。
  • 必要性:int4 场景下算子要求 scale 为 UINT64/INT64(传 float32 报 561103),此为文档 Method 2 的标准做法。

5. level4/FusedInferAttentionScore/definition.json

  • 仅 inputs 描述更新(key/value 支持 int8/int4/fp8 量化、antiquant_scale shape 约束)。
  • 必要性:纯描述变更,不影响行为;供生成 kernel 的模型正确理解低精度输入约定。

6. level2/SwigluQuant/definition.json

  • 仅 outputs 描述补充 int4 packed 说明。
  • 必要性:纯描述变更,不影响行为。

三、跨平台说明

如需在 A2/A3 评测建议按 uuid 过滤。后续可考虑为 Workload 增加 platform 字段,以支持用例按硬件平台过滤。

likedislike
合并受阻
atomgit-bot
atomgit-bot
21 天前 评论:

变更摘要

本 PR 基于昇腾 950(Ascend 950PR/950DT,CANN 9.1.0、torch_npu 2.9.0.post2)实机验证,为 npu-kernelbench/data/kernel_generator 补充 33 条低精度量化用例,并对相关 definition.json 的 reference 做适配。新增用例覆盖 FusedInferAttentionScore(int8/int4/fp8 KV 伪量化、decode 场景)、GroupedMatmulSwigluQuantV2(MXFP8)、QuantMatmul(fp8 双输入)、WeightQuantBatchmatmul(int4 权重)、KvRmsnormRopeCache(int8 KV cache)、SwigluQuant/DynamicQuant(int4 量化输出)、Cat(fp8 拼接)以及 Add/Sort/TopK/Cumsum/Scatter/Index/Gather(int8)等算子。同时为 GroupedMatmulSwigluQuantV2DynamicQuantWeightQuantBatchmatmulQuantMatmul 的 reference 增加 950 低精度通路(dtype 解析、设备分支、int4 打包与 scale 格式转换等),FusedInferAttentionScoreSwigluQuant 仅更新输入/输出描述。

主要改动

  • 新增 33 条低精度 workload 用例:在 8 个算子的 workload.jsonl 中追加 int8/int4/fp8 用例,如 FusedInferAttentionScore-051~062(BSH layout、key_antiquant_scale/value_antiquant_scale、int8/fp8 KV 及 int32 packed int4)、GroupedMatmulSwigluQuantV2-051~052(MXFP8,scale 以 int8 位模式承载 e8m0)、QuantMatmul-058~059(fp8)、WeightQuantBatchmatmul-049~050(int4 权重)等;Cumsum 文件同时完成 JSON 格式化,新增 Cumsum-052 int8 用例。
  • GroupedMatmulSwigluQuantV2/definition.json 适配 950 MX 量化:reference 新增 x_dtype/weight_dtype/weight_scale_dtype/x_scale_dtype 参数透传与 _resolve_dtype 字符串→dtype 解析(含 float8_e8m0fnu 等 torch_npu 专属 dtype),新增 _soc_is_950 设备分支使 950 跳过 NZ 格式转换(dequant_mode != 2 时才转 NZ),并将 outputs 由 2 个减为 1 个以规避 float8_e8m0fnu scale 输出的比对问题。
  • DynamicQuant/definition.json 增加 dst_type 支持:reference 增加 dst_type 参数透传及字符串→dtype 映射("int4"torch.quint4x2),inputs 声明补充 group_index/dst_type 并与 run 签名对齐,支撑 043~044 两条 int4 输出用例。
  • WeightQuantBatchmatmul/definition.json 增加 int4 权重转换:reference 在 weight.dtype == torch.int32 时自动调用 npu_convert_weight_to_int4pack 转为硬件打包布局,支撑 049~050 int4 权重用例(fp16/bf16 双场景)。
  • QuantMatmul/definition.json 增加 scale 格式转换:reference 在 int32 输入(int4 场景)且 scale 为 float32 时自动经 npu_trans_quant_param 转为 int64 格式,满足算子对 scale 的要求;FusedInferAttentionScoreSwigluQuant 的 definition 仅更新 key/value 低精度约定及 int4 packed 输出描述。
likedislike
不准确?
atomgit-bot
atomgit-bot
21 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
ascend-robotascend-robot成员
21 天前 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
21 天前 评论:

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.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.


PR Approval Progress

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)

Module Approval Details

module lgtm status approve status
repo-Ascend/ascendc-kernelgen-data 赵林林 (1/2)(You can also ask: 张琪家, 李星辰, 陈小刚, 文一晴, 祖全真) 赵林林 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
zhaolinlin成员
20 天前 评论:

/approve

likedislike
ascend-robotascend-robot成员
20 天前 添加了label:approved