Skip to content

perf(compile): opt FP8 into the static-cache compile and make the bar trace-clean + measured (#4739) - #4754

Merged
Qubitium merged 3 commits into
mainfrom
fix/issue-4739
Nov 17, 2026
Merged

Qubitium merged 3 commits into
mainfrom
fix/issue-4739

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

What

#4727 gates transformers' static-cache auto-compile on every quantized linear declaring SUPPORTS_COMPILE = True, but left TorchFP8Linear out. FP8 is the format that gains the most from the compile, so an FP8 generate(cache_implementation="static") silently ran eager — the exact 4x regression #4669 was supposed to remove.

The issue's second half (AWQ graph breaks) has been fixed on main since: #4737 added the decode-range guard, which checks torch.compiler.is_compiling() before tensor_cache_key(), so tensor.is_inference() is no longer reached during tracing. Re-measured on current main @ ebe5558a: AwqTorchLinear traces with 0 graph breaks, fullgraph=True succeeds, and the compiled static-cache decode is 3.7x faster (0.174 s -> 0.047 s, 1 graph). Its opt-in is therefore correct and is kept.

Fixes #4739.

Changes

  • TorchFP8Linear.SUPPORTS_COMPILE = True — fullgraph=True traces clean (host-visible constants only; the decoded-weight bound is a load-time cache) and the compiled static-cache decode is 2.3-3.4x faster.
  • FP8MlxQuantLinear.SUPPORTS_COMPILE = False — the Metal holder dispatches to native MXFP8 kernels, which were never traced or timed; it must not inherit the Torch opt-in.
  • BaseQuantLinear.SUPPORTS_COMPILE docstring + docs/generation-compile-policy.md: the bar is now explicitly zero-break fullgraph=True trace AND a measured win, with corrected per-kernel evidence.
  • docs/kernel-compile-matrix.md regenerated (FP8 compiled generation: no -> yes).
  • tests/test_generation_compile_policy_4669.py: FP8 declares True, AWQ stays True, MLX FP8 does not inherit.
  • New tests/kernels/test_compile_capability_4739.py: module-level trace-clean + timing for FP8 and AWQ, and a full FP8 model test that the static-cache compile is kept, is deterministic run to run, and beats eager.

Evidence (GB10, sm_121, torch 2.15.0+cu132, transformers 5.22.1)

run dynamic static static, disable_compile=True graphs breaks
FP8 before (declares False) 0.123 s 0.126 s 0.126 s 0 0
FP8 after (declares True) 0.123 s 0.055 s 0.126 s 1 0
AWQ_TORCH on current main 0.171 s 0.047 s 0.174 s 1 0
  • tests/kernels/test_compile_capability_4739.py -> 3 passed (FP8 module: 0 breaks, 2.9x faster; AWQ module: 0 breaks, fullgraph succeeds; full FP8 model: compile kept, 2.3x faster, deterministic).
  • tests/test_generation_compile_policy_4669.py + tests/kernels/test_kernel_compile_protocol.py -> 36 passed, 118 skipped.
  • ruff check gptqmodel docs tests clean.

Residual: compiling FP8 changes the reduction order, so a compiled greedy decode can pick a different token from eager on some weights (deterministic run to run; disable_compile=True reproduces the dynamic tokens exactly). This is documented in the policy doc and is the same behaviour AWQ already has.

…ster (#4739)

TorchFP8Linear traces clean under fullgraph=True and its compiled static-cache
decode is 2.3x faster than eager on sm_121, but #4727 left it opted out, so FP8
static-cache generation silently stayed eager. AwqTorchLinear was the only
opt-in, yet tensor_cache_key() calls tensor.is_inference(), a hard dynamo graph
break: fullgraph=True fails and compiling it is 20-30% slower.

The declaration now requires both halves -- a zero-graph-break fullgraph trace
and a measured win -- and each kernel is judged by that bar.
# Conflicts:
#	docs/generation-compile-policy.md
#	gptqmodel/nn_modules/qlinear/torch_awq.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant