Repository navigation
perf(cpu): make NF12, Paro and QQQ inductor-ready on CPU - #5075
Merged
Merged
Conversation
- Register FakeTensor impls for the CPU JIT extension ops (the shared AVX512 int4 GEMM and the packed QQQ kernel) so dynamo can trace them; inductor emits the real CPU call as an extern kernel. The AVX512-BF16 GPTQ/AWQ fused paths now lower as well, not only their dense fallbacks. - NF12: resolve the exponent base to a Python int at `post_init()` and select escaped groups in `nf12_codec.decode` with a static-shape gather instead of `bool(mask.any())` / `int(index.max())` host reads. The compiled decode is bit-exact against eager, including checkpoints with escape rows. - Paro: skip the CPU transform RLock and the `_ensure_cpu_layout` rewrite while tracing and read the eager-built layout; pre-resolve the CPU kernels in `post_init()`. The AVX512-BF16 path (bias included) and the bias-free ATen path reach `INDUCTOR`. A biased FP16/BF16 ATen layer stays the documented #4068 break; compiling before the first eager forward takes the traceable dense reference instead. - QQQTorchLinear: publish the resolved packed kernel handle alongside the packed cache during the eager warmup and read both while tracing; a compile before any eager call falls back to the traceable `torch._int_mm` path. - `awq.packing_utils._awq_shifts`: derive the cached shift table without the Python lock while tracing (it is a pure function of device/bits). - Declare the CPU levels (`NF12Linear`, `ParoLinear`, `QQQTorchLinear` -> `INDUCTOR`), stop `compile_policy_reason()` from attributing an inherited reason to a `NOT_APPLICABLE` MLX subclass, and add cold-compile plus compiled-decode regression tests.
Qubitium
marked this pull request as ready for review
November 18, 2026 02:08
This was referenced Nov 18, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 18, 2026
…5102) (#5171) QQQTorchLinear copied its SUPPORTS_COMPILE=False reason (172 graphs, 24-115 breaks, 1.3-8x slower) from the AUTO QQQLinear FP16 CUDA kernel; #5075 made the packed QQQ torch op traceable, so the reason was stale. VPTQLinear recorded that the portable path had never been timed. Measure both on RTX 4090 (sm_89, torch 2.15.0+cu132), Qwen2.5-0.5B, 4 prompts x 32 greedy tokens, static-cache generate(): QQQTorchLinear bf16 AUTO: 2.08 s -> 0.48 s (4.3x), 1 graph, 0 breaks VPTQLinear fp16 VPTQ_TORCH: 0.705 s -> 0.142 s (5.0x), +1 model graph, 0 breaks Opt both in and clear the stale reasons. VPTQCudaLinear and QQQMlxQuantLinear inherit from these kernels, so they re-declare the opt-out instead of inheriting the win (the fused CUDA kernel recompiles to 23 graphs / 33 breaks and is 1.7x slower than eager). TorchLinear is unchanged: bf16 wins (4.5x) but fp16 recompiles to 173 graphs and is 6.3x slower, and its policy flag and compile level are both class attributes today. Adds a regression test that is red on a978bf1 and the mechanism docs page with before/after and decision-gate diagrams.
This was referenced Nov 19, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to the merged #5070.
NF12Linear,ParoLinear,QQQTorchLinearandTorchQuantEmbeddingsnow reachINDUCTORon the CPUnightly (
torch 2.16.0.dev20261021+cpu) withfullgraph=True(zero graphbreaks). With this, every runnable CPU-capable kernel is
INDUCTOR.The shared AVX512 int4 GEMM also lowers for its BF16 fused paths now, not only
for the dense/ATen fallbacks.
Measured CPU levels (
tests/kernels/compile_probe.py, CPU-only host):NF12LinearEAGERINDUCTORParoLinearEAGERINDUCTORQQQTorchLinearCUDAGRAPHINDUCTORTorchQuantEmbeddingsEAGERINDUCTORTorchCpuAvx512Linear/TorchCpuAvx512AwqLinearINDUCTORINDUCTOR(BF16 fused path)What Changed
gptqmodel/extension.py: newregister_fake()helper. The CPU JITextensions define their kernels with
TORCH_LIBRARY+ atorch::kCPUimplementation but no Meta kernel, so dynamo refused to trace them
("Operator does not support running with fake tensors"). FakeTensor impls
are now registered for the shared AVX512 int4 GEMM and the packed QQQ
kernel; inductor still emits the real CPU call as an extern kernel.
post_init()resolves the exponent base to a Python int (the bufferstays a tensor so a checkpoint round trip keeps it exact), and
nf12_codec.decodeselects escaped groups with a static-shape gatherinstead of
bool(mask.any())/int(index.max())host reads. The compileddecode is bit-exact against eager, including checkpoints with escape rows.
_ensure_cpu_layoutrewrites are skippedwhile tracing; the traced forward reads the layout the eager warmup built.
post_init()pre-resolves the CPU kernels so a cold trace never loads anextension through importlib. The AVX512-BF16 path (bias included) and the
bias-free ATen int4pack path reach
INDUCTOR. A biased FP16/BF16 layer onthe ATen path still needs the documented [BUG] Follow-up on #4060/#4062: model.optimize() TypeError on all CPU AUTO kernels, torch.compile int4pack LoweringException for fp16+bias (regression) and bf16, max_memory still ignored with device="cuda:0" #4068 FP32 cast (eager-only); a
compile before the first eager forward takes the traceable dense reference.
QQQTorchLinear: the eager warmup publishes the resolvedqqq_int4handlewith the packed CPU cache; a traced forward reads both instead of calling
_qqq_cpu_kernel()(importlib) and_packed_weight_for_cpu()(RLock +checkpoint rewrite). A compile before any eager call falls back to the
traceable
torch._int_mmpath.TorchQuantEmbeddings: the row-decode path re-keyed its index metadatawith
tensor_cache_key(is_inference()is a hard graph break). A tracedforward now reads the metadata the eager warmup built; without a warmup it
takes the whole-table
F.embedding(dequantize_weight())path. Both reachINDUCTOR(graph_breaks=0).awq.packing_utils._awq_shifts: derive the cached shift table without thePython lock while tracing (it is a pure function of device/bits).
_compile_support.compile_policy_reason()no longer attributes an inheritedreason to a
NOT_APPLICABLEMLX subclass (the matrix showed the torchparent's CPU loss reason on MLX rows once the parents gained one).
BF16 AVX512 fused paths, both embedding decode paths, cold-compile coverage
for QQQ/Paro/NF12, and a compiled-vs-eager NF12 decode test with escape
rows.
Tests
Environment:
torch 2.16.0.dev20261021+cpu, Python 3.14, CPU-only host (noCUDA),
numpy 2.5.4.--noconftestis used locally because this host has asource build of the Hugging Face
kernelspackage andtests/conftest.pyputstests/onsys.path, sotests/kernelsshadows it.Skips / limits
INDUCTOR. The twoEAGERentries are by design:GGUFCppKernelcalls ggml throughctypes(no torch graph; also unmeasurable here because
llama-cpp-pythonisabsent), and
TorchInt8AwqLinearis retired at construction.documented [BUG] Follow-up on #4060/#4062: model.optimize() TypeError on all CPU AUTO kernels, torch.compile int4pack LoweringException for fp16+bias (regression) and bf16, max_memory still ignored with device="cuda:0" #4068 eager-only break; this mirrors the existing
TorchFusedLinear/TorchAtenLineardeclarations.tests/test_validate_nf12.py::test_perf_helpers_synchronize_requested_gpufails on this CPU-only host (
torch.cuda.Eventdummy base class); it needsa CUDA device and is unrelated to this change.