Skip to content

[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

Closed

Description

@Qubitium

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:

  1. FP8 regressed about 4x. TorchFP8Linear is the AUTO kernel for FP8 checkpoints. It compiles cleanly: 1 graph, 0 graph breaks, same tokens. [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's own follow-up comment shows the same (FP8_TORCH 0.77 s eager -> 0.175 s static on a 4090). Because it keeps the default SUPPORTS_COMPILE = False, generate(cache_implementation="static") on an FP8 model now silently runs eager.
  2. 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

import time, torch
from gptqmodel import GPTQModel, BACKEND
from torch._dynamo.utils import counters
m = 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")
def run(**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(); return round(time.time() - t, 3), sum(counters["graph_break"].values())
run(); print("dynamic", run())
for _ in range(3): print("static (policy)", run(cache_implementation="static"))
for _ in range(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:

checkpoint / kernel dynamic static, #4727 policy static, compile forced (disable_compile=False, = pre-#4727) graph breaks tokens == dynamic
Qwen2.5-0.5B-Instruct FP8 (FP8Config()), AUTO = TorchFP8Linear, fp16 0.551 0.541-0.562 (compile skipped) 0.123-0.153 0 (1 graph) yes
AWQ-Llama-3.2-1B-g128-gemm, AWQ_TORCH = AwqTorchLinear, fp16 0.90-0.94 1.10-1.22 (compiled, policy allows it) same 28 (tensor.is_inference()) yes
same, bf16 1.00 1.09-1.13 same 28 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.

Suggested fix

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.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-53ba17eb4d83 finished this issue.

    Pull request: #4754

    Fixing the compile-capability inversion introduced by #4727 (FP8 lost its speedup, AWQ_TORCH opted in wrongly)

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