Repository navigation
fix(generate): stop forcing trace-clean kernels eager (#4984) - #5006
Conversation
`BaseQModel._kernels_support_compile()` turns transformers' static-cache
auto-compile off unless every quantized linear declares `SUPPORTS_COMPILE`.
`BitsAndBytesLinear` and `MacaqLinear` both declare
`SUPPORTS_COMPILE_LEVEL = CUDAGRAPH` (a `fullgraph=True` trace with zero graph
breaks) but inherited the `False` default, so
`generate(cache_implementation="static")` added `disable_compile=True` and ran
the eager path.
Measured on this host (PG506, sm_80, torch 2.15.0.dev+cu130): Qwen2.5-0.5B
quantized to BitsAndBytes NF4, 4 left-padded prompts x 48 greedy tokens.
before: static default 1.795 s, static eager 1.779 s, forced compile 0.607 s
(1 graph, 0 breaks) - the default path lost 2.9x
after: static default 0.367 s (1 graph, 0 breaks), static eager 2.012 s
- the default path now takes the compiled route (5.5x)
`MacaqTritonLinear` breaks the graph on `torch.cuda.device_count()` and keeps
`SUPPORTS_COMPILE = False`. The two MLX holders
(`BitsAndBytesMlxQuantLinear`, `MacaqMlxQuantLinear`) re-declare `False` for
their native Metal matmuls instead of inheriting the Torch opt-in.
The general drift is codified: a kernel that reaches `INDUCTOR` or higher must
either opt in or record the measured loss in the new
`SUPPORTS_COMPILE_EAGER_REASON`. `QQQTorchLinear`, `ParoTritonLinear`,
`VPTQLinear` and the two GEMV kernels now record theirs.
`tests/kernels/test_kernel_compile_protocol.py` enforces the pairing,
`docs/kernel-compile-matrix.md` publishes the reason column, and
`tests/kernels/test_compile_policy_levels_4984.py` re-measures the trace on real
hardware.
Regression test: 6 failed / 15 passed on unmodified `origin/main`, all pass
with the fix.
7d95c1a to
130b08b
Compare
|
Independent verification on GB10 (sm_121), torch 2.15, tiny 2-layer Llama with 4-bit NF4
3.0x with the default policy, identical greedy tokens, one graph. The |
What this fixes
Closes #4984.
BaseQModel._kernels_support_compile()(the #4669/#4739 policy) disablestransformers' static-cache auto-compile unless every quantized linear declares
SUPPORTS_COMPILE.BitsAndBytesLinearandMacaqLinearboth declareSUPPORTS_COMPILE_LEVEL = CUDAGRAPH- they trace withfullgraph=Trueto onegraph with zero breaks - but inherited the
Falsedefault, sogenerate(cache_implementation="static")silently addeddisable_compile=Trueand ran the eager path.Measured before / after
Qwen2.5-0.5B-Instruct quantized to BitsAndBytes NF4 (168 modules, all
BitsAndBytesLinear), 4 left-padded prompts x 48 greedy tokens, fp16, PG506(sm_80), torch 2.15.0.dev+cu130, one shared GPU. Steady state = median of the
last three calls.
disable_compile=True)The policy was the whole difference: on main the default path was the eager
path (1.795 s) while the compiled path it suppressed was 2.9x faster. After the
opt-in the default path takes the compiled route (5.5x vs eager in that
process). Greedy tokens are identical across dynamic/eager/compiled on all four
rows here; the first compiled call costs 18-35 s of compile time.
The general rule
A kernel declaring
SUPPORTS_COMPILE_LEVEL >= INDUCTORhas a traceable,lowerable forward, which is half of the documented bar. It must now answer the
other half explicitly: opt in, or record the measured loss in the new
SUPPORTS_COMPILE_EAGER_REASON. Silent opt-outs are rejected bytests/kernels/test_kernel_compile_protocol.py, and the reason is published indocs/kernel-compile-matrix.md.Recorded reasons (all
CUDAGRAPHlevel, all measured/known losses at themodel level):
QQQTorchLinear- static-cache generate recompiles per step (172 graphs,24-115 breaks), 1.3-8x slower than eager
ParoTritonLinear- same model-level loss; the single-layer trace is cleanVPTQLinear- no measured static-cache win for the portable torch pathAwqGEMVTritonLinear/AwqGEMVTorchLinear- explicit-selection-only andCPU-only paths, never timed under
generate()MacaqTritonLinearbreaks the graph ontorch.cuda.device_count()and keepsFalse(below the floor, so no reason needed).BitsAndBytesMlxQuantLinearandMacaqMlxQuantLinearre-declareFalseso they do not inherit the Torchopt-in for their native Metal matmuls.
Tests
New
tests/kernels/test_compile_policy_levels_4984.py(hardware re-measure +static registry sweep) and three cases in
tests/test_generation_compile_policy_4669.py.Red on unmodified
origin/main(test files copied into a detachedorigin/mainworktree, fix absent):6 failed, 15 passedtest_a_trace_clean_kernel_is_not_forced_eager[BitsAndBytesLinear]-"traces to CUDAGRAPH with 0 graph breaks ... yet SUPPORTS_COMPILE is False and
no SUPPORTS_COMPILE_EAGER_REASON is recorded"
test_a_trace_clean_kernel_is_not_forced_eager[MacaqLinear]- sametest_every_compile_capable_kernel_pairs_its_policy_with_a_reason- 7kernels listed
test_kernel_declarations-assert False is True where False = BitsAndBytesLinear.SUPPORTS_COMPILEtest_a_compile_capable_kernel_keeps_the_auto_compile- the policy harnessreturns
Falsefor aMacaqLineartest_a_compile_capable_opt_out_must_record_its_reason- helper missingGreen with the fix
tests/kernels/test_kernel_compile_protocol.py+tests/test_generation_compile_policy_4669.py+tests/kernels/test_compile_policy_levels_4984.py:66 passed(CPU),3 passedfor the new file on GPU 7tests/kernels/test_kernel_compile_levels_quant.py(GPU, 17 families):13 passed, 4 skipped- identical to the unmodified-mainrun (13 passed, 4 skipped), so no level declaration changed behaviourtests/kernels/test_compile_capability_4739.py,tests/kernels/test_static_cache_compile_4669.py,tests/test_docs_contract_refs.py:20 passed, 4 skippedtests/test_bitsandbytes.py,tests/test_bnb_hf_refusal_4664.py:36 passed, 19 skippedruff checkclean on every changed Python filedocs/kernel-compile-matrix.mdregenerated withpython -m tests.kernels.gen_compile_matrix(idempotent on re-run)Files
gptqmodel/nn_modules/qlinear/bitsandbytes.py,macaq.py- opt ingptqmodel/nn_modules/qlinear/__init__.py-SUPPORTS_COMPILE_EAGER_REASONgptqmodel/nn_modules/qlinear/_compile_support.py- the reason/level pairinghelper and
COMPILE_POLICY_FLOORgptqmodel/nn_modules/qlinear/{qqq,paro_triton,vptq_torch,gemv_awq,mlx}.py-recorded reasons / explicit opt-outs
gptqmodel/models/base.py- policy usessupports_compiled_generation()docs/generation-compile-policy.md,docs/kernel-compile-matrix.md,tests/kernels/gen_compile_matrix.pytests/kernels/test_compile_policy_levels_4984.py(new),tests/kernels/test_kernel_compile_protocol.py,tests/test_generation_compile_policy_4669.py