You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[PERF] #4727 (fix of #4669) inverted the compile policy: FP8 static-cache generate lost its ~4x compile speedup (TorchFP8Linear compiles clean but isn't opted in); the only opted-in kernel, AwqTorchLinear, graph-breaks on every layer (tensor_cache_key is_inference/id/data_ptr) and is 20-30% slower compiled on sm_120 #4739
Found on main @ b225a43, RTX 5090 (sm_120, torch 2.15, transformers 5.22).
#4727 (the #4669 fix) turns off transformers' static-cache auto-compile unless every quantized linear declares BaseQuantLinear.SUPPORTS_COMPILE = True. Only AwqTorchLinear declares it (nn_modules/qlinear/torch_awq.py:39). On this card both halves of that choice measure the wrong way round:
The one kernel that opted in still breaks the graph on every layer, and is slower compiled.AwqTorchLinear.forward calls tensor_cache_key() (nn_modules/qlinear/_runtime_cache.py:32; used at torch_awq.py:209 and :309-312). That function calls tensor.is_inference(), id() and data_ptr() on every forward, which is the same class of host-side guard [PERF] generate(cache_implementation="static") is 2-4x SLOWER than eager on every default CUDA kernel (HF auto-compile graph-breaks on each quantized linear: no fake impls, data_ptr/id() guards); model.optimize() compiles nothing that generate() runs #4669 called out for TorchLinear. Dynamo stops at Encountered tensor.is_inference() during tracing: 28 breaks for a 16-layer Llama, and fullgraph=True fails outright. It also recompiles per projection shape (self.out_features == 2048, scales size mismatch). With static cache on the 5090 it is 20-30% slower than eager. The opt-in rested on one 4090 number (1.36 -> 0.76 s) and a GB10 run that was itself mixed (0.168 s eager vs 0.157-0.257 s static).
Repro
importtime, torchfromgptqmodelimportGPTQModel, BACKENDfromtorch._dynamo.utilsimportcountersm=GPTQModel.load(ckpt, backend=BACKEND.AUTO, dtype=torch.float16, device="cuda:0")
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")
defrun(**kw):
counters.clear(); torch.cuda.synchronize(); t=time.time()
out=m.generate(**enc, max_new_tokens=32, min_new_tokens=32, do_sample=False, **kw)
torch.cuda.synchronize(); returnround(time.time() -t, 3), sum(counters["graph_break"].values())
run(); print("dynamic", run())
for_inrange(3): print("static (policy)", run(cache_implementation="static"))
for_inrange(3): print("static, disable_compile=False", run(cache_implementation="static", disable_compile=False))
Steady-state seconds per generate() (warm-up/first compile excluded), with tokens compared to the dynamic cache:
no (bf16 rounding; module-level eager vs compiled differs by 1 ulp)
disable_compile=True gives 0.91 s for AWQ_TORCH, i.e. the eager speed.
Module level (torch.compile(Wrap(AwqTorchLinear)), 512x1024 and 2048x2048, M in {1, 4, 17, 64}): default and reduce-overhead produce 6 graph breaks per 3 shapes, all at _runtime_cache.py:32. fullgraph=True raises Unsupported: Encountered tensor.is_inference() during tracing.
test_static_cache_compile_4669 should cover an FP8 checkpoint (compile kept, faster than eager) and assert counters["graph_break"] == 0 for every kernel that declares SUPPORTS_COMPILE.
Severity
Medium (perf). Static-cache decode on FP8 models, the format that benefited most from compile, is now about 4x slower than before #4727, silently. The opted-in AWQ_TORCH path is a pessimization on sm_120.
Activity
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-53ba17eb4d83finished this issue.Pull request: #4754
Fixing the compile-capability inversion introduced by #4727 (FP8 lost its speedup, AWQ_TORCH opted in wrongly)
test(compile): drop the duplicate FP8 warm-up assignment (#4739)
perf(compile): opt FP8 into the static-cache compile and make the bar…