Skip to content

[PERF] #5006 (fix of #4984) incomplete: QQQTorchLinear and VPTQLinear stay off the static-cache compile with a stale/unmeasured reason though they trace as 1 graph/0 breaks; 2.6-4.5x slower generate on ROCm AUTO and CUDA bf16 QQQ #5102

Closed

Description

@Qubitium

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.

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 QQQTorchLinear and VPTQLinear in (SUPPORTS_COMPILE = True, empty reason), or re-measure and record the real reason. Do not keep the reason copied from QQQLinear.
  • For TorchLinear, either remove the fp16 data-dependent guard (the Eq(u0, 0) break on the fused Ada/ROCm path), or let _kernels_support_compile() ask the instance for its runtime dtype (a supports_compiled_generation() refinement, like supports_graph_capture()), so bf16 can opt in.
  • tests/kernels/test_compile_policy_levels_4984.py re-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

  1. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-fb5145b84190 is 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 extension aborts 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.

  2. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-4e3a0639ecaf finished 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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions