Repository navigation
Description
Found on main @ 3867c82, RTX 5090 (sm_120), torch 2.15.0+cu132, transformers 5.22.
What is wrong
The #4669/#4739 generation compile policy (BaseQModel._kernels_support_compile() -> _generation_compile_kwargs(), gptqmodel/models/base.py:3348-3416) only keeps Transformers' static-cache auto-compile when every quantized linear declares SUPPORTS_COMPILE = True. Today only TorchFP8Linear and AwqTorchLinear do.
Two kernels that meet the documented bar are left out (docs/generation-compile-policy.md: a fullgraph trace with zero graph breaks and a measured win):
BitsAndBytesLinear(the AUTO kernel for every BnB checkpoint on CUDA). It declaresSUPPORTS_COMPILE_LEVEL = COMPILE_LEVEL.CUDAGRAPH, measured on 4090/5090/R9700 (qlinear/bitsandbytes.py:455-462), but inheritsSUPPORTS_COMPILE = False(qlinear/__init__.py:387).MacaqLinear(BACKEND.MACAQ_TORCH, the portable MACaQ path). It declaresCUDAGRAPH(qlinear/macaq.py:66-69) and also inheritsFalse.
So generate(cache_implementation="static") on a BnB model is forced to eager (disable_compile=True). The compile it suppresses runs as one graph with zero breaks and is 2.2-3.5x faster. This is the same failure mode #4739 reported for FP8, which #4754 fixed for FP8 only.
Measurements
4 left-padded prompts, 48 greedy new tokens (min_new_tokens=48), GPTQModel.generate, steady-state seconds per call (second or third call). "forced" is the same call with disable_compile=False.
| model / kernel | dtype | dynamic | static, default policy | static, forced compile | dynamo | speedup |
|---|---|---|---|---|---|---|
Qwen2.5-0.5B-Instruct BnB 4-bit (BitsAndBytesLinear) |
fp16 | 0.568 | 0.604 | 0.174 | 1 graph, 0 breaks | 3.5x |
| same | bf16 | 0.609 | 0.644 | 0.192 | 1 graph, 0 breaks | 3.4x |
Llama-3.2-1B-Instruct BnB 4-bit (BitsAndBytesLinear) |
fp16 | 0.382 | 0.411 | 0.186 | 1 graph, 0 breaks | 2.2x |
| same | bf16 | 0.427 | 0.436 | 0.195 | 1 graph, 0 breaks | 2.2x |
Qwen2.5-0.5B-Instruct MACaQ (MACAQ_TORCH, MacaqLinear) |
fp16 | 7.03 | 6.67 | 0.73 | 1 graph, 0 breaks | 9x |
- First compiled call: 11-17 s for BnB and 122 s for MacaqLinear. That is the usual one-off compile cost FP8/AWQ_TORCH already pay (55 s for AWQ_TORCH here).
- Greedy tokens: fp16 BnB compiled == eager on all 4 rows (both models). In bf16 and for MACaQ, some rows diverge after a near-tie. This is the same compiled-reduction-order effect the policy doc already accepts for FP8/AWQ.
- The Llama rows and the Qwen bf16 row were measured while another job shared the GPU. The ratio holds either way.
For comparison, in the same harness the policy is correct for every other AUTO kernel on sm_120: Marlin GPTQ/AWQ, GGUF Triton, NF12, VPTQ CUDA, QQQ, ParoLinear, MACaQ Triton, GPTQ_TORCH, GPTQ_TRITON and PARO_TRITON. A forced compile there is 1.3-8x slower, with 24-115 breaks or 172 recompiled graphs, so keeping them eager is right. FP8 and AWQ_TORCH (opted in) give 0.166 s vs 0.86 s and 0.259 s vs 1.475 s, as expected.
Repro
import torch
from gptqmodel import GPTQModel
m = GPTQModel.load("<Qwen2.5-0.5B-Instruct quantized with BitsAndBytesConfig(bits=4)>", device="cuda:0", dtype=torch.float16)
tok = m.tokenizer
enc = tok(["The capital of France is", "Write a short poem about the ocean and the moon, in four lines:",
"def fibonacci(n):", "In 1905, Albert Einstein published four papers that changed physics. The first one"],
return_tensors="pt", padding=True, padding_side="left").to("cuda:0")
kw = dict(max_new_tokens=48, min_new_tokens=48, do_sample=False, cache_implementation="static")
print(m._kernels_support_compile()) # False -> policy adds disable_compile=True
m.generate(**enc, **kw) # 0.604 s (eager)
m.generate(**enc, **kw, disable_compile=False) # first call ~17 s, then 0.174 s, 1 dynamo graph, 0 graph breaksSuggested fix
Opt BitsAndBytesLinear in: SUPPORTS_COMPILE = True, with the evidence line and a row in the docs/generation-compile-policy.md table, as #4754 did for FP8. MacaqLinear qualifies by the same bar. AUTO picks MACaQ Triton on CUDA, so it matters less there, but the compiled torch path (0.73 s) even beats eager Triton (0.89 s). More generally, a kernel declaring SUPPORTS_COMPILE_LEVEL >= INDUCTOR with SUPPORTS_COMPILE = False should need a recorded reason (a measured loss). Otherwise the two declarations drift apart again.
Test that should have caught it
tests/test_generation_compile_policy_4669.py covers only the FP8/AWQ opt-ins and a graph-breaking kernel. A GPU test should check every kernel declaring CUDAGRAPH: static-cache compiled vs eager on a tiny model, failing when compiled is faster but the policy disables it. tests/kernels/test_kernel_compile_protocol.py could also flag CUDAGRAPH + SUPPORTS_COMPILE=False without a documented reason.
Severity
Medium perf: static-cache generation on every bitsandbytes model is 2.2-3.5x slower than it could be by default, and users have no hint to pass disable_compile=False, since the policy warning says compiling "would be slower than eager".
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-4984is working on this issue now.Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-53ba17eb4d83finished this issue.Pull request: #5006
opt BitsAndBytesLinear and MacaqLinear into the static-cache compile policy, with measurements
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-root-4984finished this issue.Pull request: #5006 (squash-merged as
291738fc8)Fix
BitsAndBytesLinearandMacaqLinearnow declareSUPPORTS_COMPILE = True, sogenerate(cache_implementation="static")keeps transformers' auto-compileinstead of adding
disable_compile=True.The general drift is codified: a kernel declaring
SUPPORTS_COMPILE_LEVEL >= INDUCTORmust either opt in or record the measuredloss in the new
SUPPORTS_COMPILE_EAGER_REASON.QQQTorchLinear,ParoTritonLinear,VPTQLinear,AwqGEMVTritonLinearandAwqGEMVTorchLinearnow record theirs;MacaqTritonLinear(graph breaks ontorch.cuda.device_count()) and the two MLX holders keep an explicitFalse.tests/kernels/test_kernel_compile_protocol.pyrejects a silent opt-out anddocs/kernel-compile-matrix.mdpublishes the reason column.Measured on this host (PG506, sm_80, torch 2.15.0.dev+cu130)
Qwen2.5-0.5B quantized to BitsAndBytes NF4 (168 modules), 4 left-padded
prompts x 48 greedy tokens, fp16, median of the last three calls:
Greedy tokens identical across dynamic/eager/compiled on all four rows.
Tests
origin/main:6 failed, 15 passed(2 hardwarere-measures + the static registry sweep + 3 policy cases)
86 passed(protocol + policy + new hardware file + docs contract),3 passedfor the new file on GPU 7tests/kernels/test_kernel_compile_levels_quant.py:13 passed, 4 skipped,identical to the unmodified-
mainruntests/test_bitsandbytes.py+tests/test_bnb_hf_refusal_4664.py:36 passed, 19 skipped; all CI checks green before the squash mergeWorktrees and branch removed.
fix(generate): stop forcing trace-clean kernels eager (ModelCloud#4984)…