Open
test: QAT FP8 整改用例(切片 2/9) #202
zhaiyaxing001Add on 22 hours ago
test: QAT FP8 整改用例(切片 2/9) #202
Open
zhaiyaxing001Add on 22 hours ago
zhaiyaxing001
zhaiyaxing001
22 hours ago

一、背景

QAT 迁移系列切片 2/9(前置:切片 1 = PR #10 已合入;本次增量合入:+73 行,单文件,纯测试迁移无 patch)。

二、变更

test/quantization/test_qat.py 新增 3 方法 5 实例(FP8 整改迁移):

方法(实例数) 测试内容 上游(v0.18.0) 本仓整改 适配原因(为何改) 验证结果 失败原因及后续措施 保持不变
test_quantize_api_fp8_fp8(2) FP8 QAT 全链路数值正确性:Float8DynamicActivationFloat8WeightConfig 下 prepare(fake-quant 前向)输出对照一步 PTQ 基线(SQNR≥15);convert 后 linear1/linear2/sub.linear 权重均为 Float8Tensor 且输出与 PTQ 逐位一致 subTest 组织粒度参数;CUDA/sm89/MI300 多重硬件门控 设备 NPU;subTest→parametrize;复用切片 1 前移的 _test_quantize_api_against_ptq helper 对照 PTQ 设备 NPU——系列目标即用例解耦,上游仅 sm89/MI300 可跑、NPU 零覆盖;subTest→parametrize——迁移对齐上游的是语义与命名,执行组织遵循本仓测试基建:subTest 为单节点子例,不进实例枚举(收集数不可见、无法逐实例对账)、不能按实例 ID 筛选重跑;parametrize 使 PerTensor/PerRow 成为独立实例、与全链 @parametrize + instantiate_parametrized_tests 矩阵一致,参数空间与上游完全一致;复用 helper——切片 1 已前移,PTQ 对照判据单一来源、避免复制 A5 蓝区 2P 通过 — 粒度参数空间(PerTensor/PerRow);prepare SQNR≥15、convert 逐位一致
test_float8_fake_quantize(2) Float8FakeQuantizer 前向伪量化数值正确性:fp8 量化/反量化往返输出对照 Float8Tensor.from_hp().dequantize() 参照(SQNR>16) 纯 CPU 张量执行 Float8FakeQuantizer 输入放置 NPU 设备(bf16);数值对照 Float8Tensor 反量化 上游为纯 CPU 张量,在本仓跑不出 NPU 链路——不上设备则迁移无意义;bf16 为 NPU 原生低精度入口 dtype(与上游输入一致,fp8 量化由 FakeQuantizer 内部完成);对照 Float8Tensor 反量化——fake quant 语义即量化/反量化往返,from_hp().dequantize() 为同语义参照实现,SQNR>16 判据沿用上游 A5 蓝区 2P 通过 — SQNR>16 判据;粒度参数
test_fake_quantizer_enabled_attribute(1) FakeQuantizer.enabled 门控语义:False 时输出与输入逐位一致(直通)、True 时输出改变(执行量化)——Int4 权重假量化器开/关两态 + Float8 假量化器关态直通 纯 CPU 张量 Float8 路径输入 NPU 化;Int4 路径保持 CPU(仅 ATen 算子、设备无关) Float8 路径 NPU 化——enabled 门控语义需在真实设备输入上验证;Int4 保持 CPU——仅用 ATen 算子、设备无关,且 int4 ATen 算子族(_convert_weight_to_int4pack 等)无 NPU 实现(能力矩阵已定案),上设备会因算子缺口失败而非语义失败;Float8 仅覆盖 disabled 直通——enabled 路径需 fp8 算子面,由 test_float8_fake_quantize 承接,避免同实例混入设计内失败 A5 蓝区 1P 通过 — enabled=False 直通/True 量化语义断言

三、功能验证

  • A5 蓝区(950DT/torch 2.15/CANN 驱动 25.1.rc3.2,2026-11-25):收集 32 实例
    (链条 27→32 与设计一致);切片 2 5P 全过;同跑切片 1 复跑 21P/6F——6F 为
    MX forward e5m2×6(950DT 原生 _scaled_mm 不支持 e5m2 矩阵乘,先保留登记issue,后续随策略补齐)。

四、资料变更

含自 pytorch/ao(BSD-3-Clause)test/quantization/test_qat.py 迁移适配用例,方法名
与上游对齐、适配点见 docstring;无新增第三方依赖。

五、Checklist

likedislike
Merge blocked
zhaiyaxing001zhaiyaxing001
22 hours ago Created pull request, commit 83ddbddc
zhaiyaxing001zhaiyaxing001
22 hours ago Associated issue: [Test]: 补充 QAT 量化感知训练 NPU 测试(FP8/INT4/INT8/INTx),[RFC] KernelPreference 扩展:新增原生内核成员 ASCEND
ascend-robotascend-robotCollaborators
22 hours ago Added label: ascend-cla/yes
ascend-robot
ascend-robotCollaborators
22 hours ago 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.
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)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
repo-Ascend/torchao-ascend ❌ (0/2)(You can also ask: wanglijun55, chujinjin, chengpeng25, jishuangfeng, weixin_38374194) ❌ (0/1)(You can also ask: li_jing_hw, liangsongwei, chujinjin, 褚博宁, 楚浩田)

💡 Tip:

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

CLA Signature Pass

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

likedislike
zhaiyaxing001
zhaiyaxing001
22 hours ago Comments:

compile

likedislike
zhaiyaxing001zhaiyaxing001
22 hours ago Pre merge succeeded (commit_id: ce2e6b0b6292ce1ae08e4470109c40688e7b0095)
AtlasAccountAtlasAccountCollaborators
22 hours ago Added label: ci-pipeline-running
AtlasAccountAtlasAccountCollaborators
22 hours ago Removed label: ci-pipeline-running
AtlasAccountAtlasAccountCollaborators
22 hours ago Added label: ci-pipeline-passed
AtlasAccount
AtlasAccountCollaborators
22 hours ago Comments:
流水线 PR-pipeline_torchao_npu#319 [ commitID:4d43fde8 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_x86 ✅ COMPLETED >>>
恶意代码检查 Antipoison ✅ COMPLETED >>>
编码安全与规范检查 pre-commit ✅ COMPLETED >>>
开源片段检查 SCA ✅ COMPLETED >>>
流水线 PR-pipeline_torchao_npu ✅ COMPLETED >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员[wujinyuan1, wanglijun55, wss_321]评论有效
  • compile : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
zhaiyaxing001zhaiyaxing001
34 minutes ago Modify description of pull request
zhaiyaxing001zhaiyaxing001
24 minutes ago Modify description of pull request
zhaiyaxing001zhaiyaxing001
1 minute ago Modify description of pull request