Open
fix: Float8Tensor NPU 融合量化增加设备门控,CPU 输入回落上游实现 #193
fix: Float8Tensor NPU 融合量化增加设备门控,CPU 输入回落上游实现 #193
Open
TTTIAN998Add on 2 days ago
Total: 1 files changed+8-0
@@ -41,6 +41,14 @@ def _try_npu_native_quant(
41 PerBlock,41 PerBlock,
42) -> tuple | None:42) -> tuple | None:
43 """Return ``(qdata, scale)`` from a fused NPU kernel, or ``None`` to fall back."""43 """Return ``(qdata, scale)`` from a fused NPU kernel, or ``None`` to fall back."""
44+ # NPU fused kernels are only registered for PrivateUse1 (and Meta): a CPU
45+ # input would raise ``NotImplementedError: Could not run
46+ # 'npu::npu_dynamic_quant' with arguments from the 'CPU' backend``.
47+ # Fall back to the upstream pure-torch implementation for non-NPU inputs,
48+ # keeping upstream device-agnostic (CPU) tests working.
49+ if hp_tensor.device.type != "npu":
50+ return None
51+ 
44 if hp_value_lb is not None or hp_value_ub is not None:52 if hp_value_lb is not None or hp_value_ub is not None:
45 return None53 return None
46 54