Repository navigation
Description
Found on main @ e75181d, RTX 4090 (sm_89, torch 2.15 + CUDA 13.2) and Radeon AI PRO R9700 (gfx1201, torch 2.16 + ROCm 10.1).
What is wrong
This is the #4984 class, for the two portable kernels that #5006 opted out with a recorded reason that does not hold.
QQQTorchLinear(gptqmodel/nn_modules/qlinear/qqq.py:714-722) keepsSUPPORTS_COMPILE = Falsewith the reason "static-cache generate recompiles per step (172 graphs, 24-115 breaks) and is 1.3-8x slower than eager". That number comes from [PERF] #4669/#4739 compile policy keeps bitsandbytes (and MACAQ_TORCH) eager: static-cache generate 2.2-3.5x slower (9x for MacaqLinear) though the kernel traces as 1 graph with 0 breaks #4984's measurement of the AUTOQQQLinearCUDA kernel. On the torch kernel, a static-cachegenerate()compiles to 1 graph with 0 breaks and decodes 2.6-4.2x faster than the eager path the policy forces. perf(cpu): make NF12, Paro and QQQ inductor-ready on CPU #5075 then made the packed QQQ op traceable, so the copied reason is stale.VPTQLinear(vptq_torch.py:57-65) states "The portable torch path has not been timed undergenerate(), so it keeps the conservative policy until someone measures it". Measured: 1 graph, 0 breaks, 2.7-4.5x faster compiled.
Both are AUTO selections in common configs. On ROCm, AUTO loads every QQQ checkpoint as QQQTorchLinear and every VPTQ checkpoint as VPTQLinear, because the CUDA kernels cannot run there. On CUDA, a QQQ checkpoint loaded in bf16 also goes to QQQTorchLinear, since QQQLinear is fp16-only. So generate(cache_implementation="static") on those setups silently drops to the eager path (_kernels_support_compile() -> disable_compile=True) and is several times slower than it needs to be.
Qwen2.5-0.5B-Instruct checkpoints, 4 left-padded prompts x 32 greedy tokens, steady-state (3rd run). static is the default policy, which runs eager for these kernels. forced adds disable_compile=False.
| device | ckpt / backend | kernel (AUTO pick?) | dtype | static (policy) | forced compile | graphs / breaks |
|---|---|---|---|---|---|---|
| R9700 | QQQ / AUTO | QQQTorchLinear (yes) | fp16 | 3.36 s | 1.29 s | 1 / 0 |
| R9700 | VPTQ / AUTO | VPTQLinear (yes) | fp16 | 0.896 s | 0.333 s | 1 / 0 |
| 4090 | QQQ / AUTO | QQQTorchLinear (yes) | bf16 | 1.99 s | 0.47 s | 1 / 0 |
| 4090 | QQQ / QQQ_TORCH | QQQTorchLinear | fp16 | 2.11 s | 0.48 s | 0 breaks |
| 4090 | VPTQ / VPTQ_TORCH | VPTQLinear | fp16 | 0.71 s | 0.157 s | 0 breaks |
| 4090 | VPTQ / VPTQ_TORCH | VPTQLinear | bf16 | 0.706 s | 0.158 s | 1 / 0 |
Tokens are not bit-identical between compiled and eager, which is normal for an inductor-fused model. Layer-level compiled vs eager is 0 to 1.3e-4 relative (my torch.compile check of the same layers, with no fp64 nodes and the dtype preserved). The first compiled call costs 21-46 s on the 4090 and 72-124 s on the R9700. This is the same one-off cost that #5006 accepted for BnB and MACaQ.
Related data for TorchLinear, which is the ROCm AUTO kernel for every GPTQ checkpoint. A per-class flag cannot express what it needs: bf16 traces clean and wins (R9700 AUTO bf16 0.99 s -> 0.333 s; 4090 GPTQ_TORCH bf16 0.80 s -> 0.177 s), but fp16 recompiles 173 graphs on a data-dependent guard (Eq(u0, 0)) and loses (R9700 0.79 s -> 3.05 s, 4090 0.62 s -> 3.27 s). So keeping it off is right for fp16 and wrong for bf16.
Repro
import torch, time
from gptqmodel import GPTQModel, BACKEND
m = GPTQModel.load("<QQQ 4-bit Qwen2.5-0.5B-Instruct>", backend=BACKEND.AUTO, dtype=torch.float16, device="cuda:0") # ROCm -> QQQTorchLinear
tok = m.tokenizer; tok.padding_side = "left"
enc = tok(["The capital of France is", "def fibonacci(n):", "Hello", "In 1905, Albert Einstein published four papers"], return_tensors="pt", padding=True).to("cuda:0")
def run(**kw):
torch.cuda.synchronize(); t = time.time()
m.generate(**enc, max_new_tokens=32, min_new_tokens=32, do_sample=False, cache_implementation="static", **kw)
torch.cuda.synchronize(); return time.time() - t
for _ in range(3): a = run() # policy: eager
for _ in range(3): b = run(disable_compile=False) # forced compile
print(a, b) # R9700: 3.36 vs 1.29 ; same pattern for VPTQ (0.896 vs 0.333)Suggested fix
- Opt
QQQTorchLinearandVPTQLinearin (SUPPORTS_COMPILE = True, empty reason), or re-measure and record the real reason. Do not keep the reason copied fromQQQLinear. - For
TorchLinear, either remove the fp16 data-dependent guard (theEq(u0, 0)break on the fused Ada/ROCm path), or let_kernels_support_compile()ask the instance for its runtime dtype (asupports_compiled_generation()refinement, likesupports_graph_capture()), so bf16 can opt in. tests/kernels/test_compile_policy_levels_4984.pyre-measures traces only. A model-level timing check for each AUTO kernel per device would catch a stale reason.
Severity
Performance only, with no wrong output. Static-cache decode is 2.6-4.5x slower than available for QQQ and VPTQ on ROCm AUTO and for QQQ bf16 on CUDA AUTO.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 18, 2026
Agent claim released:
agent-fb5145b84190is no longer working on this issue.The issue is free to claim.
Blocked on this host, no code change made. Validating this needs a QQQ and a VPTQ checkpoint, and building either requires the native JIT extension; this host has no CUDA toolkit (no nvcc, no /usr/local/cuda, CUDA_HOME unset), so
QQQ: failed to build torch.ops JIT extensionaborts quantize. The fix itself is a measured perf-policy flip (SUPPORTS_COMPILE for QQQTorchLinear/VPTQLinear), and AGENTS.md requires a measured win on the hardware it claims, so it must not be flipped blind. VPTQLinear already records its graph-capture measurement on GB10 (sm_121), so a host with nvcc could finish this quickly; the ROCm half of the issue additionally needs gfx1201.Qubitium commentedon Nov 18, 2026
Agent claim released:
agent-4e3a0639ecaffinished this issue.Pull request: #5171
QQQTorchLinear and VPTQLinear now opt into the static-cache compile with measured reasons (4.3x / 5.0x decode on 4090); VPTQCudaLinear and the MLX QQQ kernel re-declare False explicitly.
perf(qqq,vptq): opt portable torch kernels into compiled generation (#…
fix(vptq): skip the per-layer compile when the GIL is disabled (#5228) (