Skip to content

fix(nf12): keep tensor.is_inference() out of the compiled forward (#5299) - #5309

Merged
Qubitium merged 1 commit into
mainfrom
fix/nf12-dequant-compile-5299
Nov 19, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/nf12-dequant-compile-5299

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #5299. Regression from #5230 (which fixed #5211).

Problem

NF12Linear.dequantize_weight() ended with
_as_normal_tensor(weight.to(dtype=dtype).contiguous()), and _as_normal_tensor
calls tensor.is_inference(). Dynamo cannot trace that call ("This graph break
is fundamental"), so every compiled NF12 CPU forward graph-broke between the
decode and the matmul, fullgraph=True raised Unsupported, and
test_cpu_kernel_reaches_declared_cpu_level[NF12Linear] reported EAGER while the
kernel declares COMPILE_LEVEL.INDUCTOR.

Change

Verification

tests/kernels/test_kernel_compile_levels_cpu.py   # both previously red nodes now pass
tests/test_nf12_grad_mode_forward_5211.py         # the #5211 contract still holds
  • test_cpu_kernel_reaches_declared_cpu_level[NF12Linear] and
    test_nf12_cpu_compiles_after_post_init_without_an_eager_call: red on main
    (Unsupported: Encountered tensor.is_inference()), green here.
  • torch.compile(forward, backend="inductor", fullgraph=True) now compiles on a
    2048x2048 bf16 CPU layer (was torch._dynamo.exc.Unsupported).
  • NF12 suites: 97 passed, 124 skipped (test_nf12_codec,
    test_nf12_escape_bounds, test_gptqmodel_nf12_api, test_nf12_moe_offsets,
    test_validate_nf12, test_nf12_kernel_manifest,
    test_checkpoint_resume_nf12_macaq_4792), plus the compile-level file and the
    grad-mode contract (60 passed).

New tests/test_nf12_forward_no_inference_probe_5299.py (3 nodes) monkeypatches
torch.Tensor.is_inference to raise: the eager forward and
dequantize_weight() must not call it, and post_init() must normalise buffers
installed under InferenceMode. All three fail on main.

Note on timing: at M=4 on this host the compiled-vs-eager ratio is
decode-dominated and within noise, so the evidence here is the graph-level
probe (INDUCTOR reached, fullgraph compiles) rather than a wall-clock delta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment