Open
fix: Float8Tensor NPU 融合量化增加设备门控,CPU 输入回落上游实现 #193
fix: Float8Tensor NPU 融合量化增加设备门控,CPU 输入回落上游实现 #193
Open
TTTIAN998Add on 2 days ago
TTTIAN998
TTTIAN998
2 days ago

修改方案

F26(test_quant_api_npu.py)中 2 个用例 ERROR:

NotImplementedError: Could not run 'npu::npu_dynamic_quant' with arguments from the 'CPU' backend.
'npu::npu_dynamic_quant' is only available for these backends: [PrivateUse1, Meta, ...]

根因:torchao_ascend 的 Float8Tensor 融合量化入口 _try_npu_native_quant 缺设备门控——上游 torchao 没有这段代码(它是 torchao_ascend 为 NPU 加的融合路径),CPU 输入也被送进 npu_dynamic_quant / npu_dynamic_block_quant,而 torch_npu 的这两个算子只注册了 PrivateUse1(NPU)与 Meta 后端,无 CPU kernel,直接抛错。

触发路径:上游 0.18 新增的 test_quantize_reapply_is_noop 为 CPU 用例(CPU 模型直接 quantize_),镜像到 NPU 环境后经 Float8Tensor.from_hp patch 走到融合路径时命中。

修复(3 行):_try_npu_native_quant 开头增加设备门控——非 NPU 输入返回 None,沿用该函数既有的回落机制走上游纯 torch 实现:

if hp_tensor.device.type != "npu":
    return None

NPU 输入路径零改动;CPU/Meta 输入回落上游实现(CPU 上本就可用)。

验证结论

验证环境:Ascend 950(A5)、CANN 9.2.0、torch 2.11.0+cpu、torch_npu 2.11.0.post3。

  • npu_dynamic_quant CPU 报错残留:0(修复前 2 处)
  • F26 全量 49 例:errors 6 → 5(消除的 2 个即本修复目标;修复后回落路径暴露 reapply_noop 的量化子类 dispatch 缺算子问题,属另一独立待修项,与设备门控无关)
  • failures=1、skipped=2 不变,无新增失败
likedislike
Merge blocked
TTTIAN998TTTIAN998
2 days ago Created pull request, commit 422bcc11
ascend-robotascend-robotCollaborators
2 days ago Added label: ascend-cla/yes
ascend-robot
ascend-robotCollaborators
2 days 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: wangzhenwu, ll-pen, weixin_38374194, liangsongwei, 楚浩田) ❌ (0/1)(You can also ask: 褚博宁, 楚浩田, chengpeng25, wanglijun55, li_jing_hw)

💡 Tip:

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

CLA Signature Pass

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

likedislike
TTTIAN998
TTTIAN998
2 days ago Comments:

/ai review

likedislike
TTTIAN998
TTTIAN998
2 days ago Comments:

/ai help

likedislike
atomgit-bot
atomgit-bot
2 days ago Comments:

AtomGit AI 助手使用指南

在 PR 评论中使用命令即可触发。支持在普通评论和代码行评论中使用。

功能 命令 说明
代码审查 /ai review 检查代码质量、潜在问题、安全风险
PR 摘要 /ai summary 生成 PR 变更内容的结构化摘要
代码解释 /ai explain 解释代码变更的逻辑和意图
自由提问 @atomgit-bot <问题> 询问关于本 PR 的任何问题
帮助 /ai help 显示此帮助信息

免责声明

AI 助手可能存在误判,请结合自身判断。可以对评论点 👍 或 👎 帮助我们改进。

likedislike
Incorrect?