You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[PERF] Regression from #5230 (fix of #5211): NF12Linear.dequantize_weight's is_inference() check graph-breaks every compiled CPU forward - declared CPU INDUCTOR not reached, fullgraph fails, compiled forward 1.3-1.4x slower #5299
Found on main @ c03416c, CPU (host of an RTX 4090 box; torch 2.15.0+cu132, inductor).
What is wrong
#5230 (fix of #5211) made NF12Linear.dequantize_weight() return _as_normal_tensor(weight...) (gptqmodel/nn_modules/qlinear/nf12.py, end of dequantize_weight). _as_normal_tensor calls tensor.is_inference(). The CPU forward's wide path calls dequantize_weight() on every call (_forward_impl, weight = self.dequantize_weight(device=x.device, dtype=compute_dtype)).
Dynamo cannot trace tensor.is_inference() (Unsupported: Encountered tensor.is_inference() during tracing ... This graph break is fundamental). So every compiled NF12 CPU forward now graph-breaks between the decode and the matmul, and fullgraph=True compilation fails. NF12Linear still declares SUPPORTS_COMPILE_LEVEL_BY_DEVICE = {"cpu": COMPILE_LEVEL.INDUCTOR}.
The buffers are already made non-inference at install time (the other _as_normal_tensor calls in pack/load_quant_result). The decoded result then only becomes an inference tensor when the caller itself runs under inference_mode, and that is harmless for that caller. So the wrapper on the return value is the only part that breaks the graph.
The existing tests already catch it: both are red on main, deterministic 3/3, and bisected to 77c4797ff.
tests/kernels/test_kernel_compile_levels_cpu.py::test_cpu_kernel_reaches_declared_cpu_level[NF12Linear]
AssertionError: NF12Linear: declares CPU INDUCTOR but the probe reported eager=True graph_breaks=1 ... max=EAGER
tests/kernels/test_kernel_compile_levels_cpu.py::test_nf12_cpu_compiles_after_post_init_without_an_eager_call
torch._dynamo.exc.Unsupported: Encountered tensor.is_inference() during tracing
Suggested fix
Drop _as_normal_tensor from the dequantize_weight return value: the buffers are already normal, and no_grad decode under grad mode yields a normal tensor. If a caller still needs it, skip the check while compiling (if not torch.compiler.is_compiling()). Keep the #5211 grad-mode tests and the two compile-level tests green together.
Severity: medium for performance. Results are correct, but the declared CPU compile level is no longer reached, and fullgraph compiles of NF12 models fail.
Stop wrapping the decoded NF12 weight in _as_normal_tensor on every forward so dynamo can trace the CPU path; add/keep the compile-level and fullgraph regressions green.
Activity
Qubitium commentedon Nov 19, 2026
Agent claim released:
agent-fb5145b84190finished this issue.Pull request: #5309
Stop wrapping the decoded NF12 weight in _as_normal_tensor on every forward so dynamo can trace the CPU path; add/keep the compile-level and fullgraph regressions green.
fix(nf12): keep tensor.is_inference() out of the compiled forward (#5299