Skip to content

[PERF] #5167 (fix of #5115) incomplete on GPU: ParoTritonLinear declares CUDAGRAPH, but every non-identity Paro layer graph-breaks on the rotation autotune disk lock (and the fused rotate op has no fake impl) - optimize() on ROCm: 52 breaks, 0.6x eager #5225

Closed

Description

@Qubitium

Found on main @ 396b5f0, AMD Radeon AI PRO R9700 (gfx1201), torch 2.16.0.dev+rocm10.1.

What is wrong

ParoTritonLinear (the ROCm AUTO kernel for Paro since #5053) declares SUPPORTS_COMPILE_LEVEL = COMPILE_LEVEL.CUDAGRAPH (paro_triton.py:37-40, "Measured on GB10"). The level test (tests/kernels/test_kernel_compile_levels_quant.py:304, _build_paro) uses an identity rotation. With identity, _rotate_inputs returns immediately and the rotation never runs. Every layer of a real Paro checkpoint has a non-identity rotation, and on the GPU path it breaks the graph inside apply_paro_rotation -> _apply_fused_rotation -> _resolve_rotation_launch -> _ensure_rotation_autotune_cache_loaded (gptqmodel/utils/paro.py:728-733):

Unsupported context manager
  Explanation: Dynamo does not know how to enter a `lock` context manager.
  ... File "gptqmodel/utils/paro.py", line 732, in _ensure_rotation_autotune_cache_loaded
        with _ROTATION_AUTOTUNE_DISK_LOCK:

The lock is taken on every call, before the "already loaded" check, so an eager warm-up does not help. The fused rotation op also has no fake/meta implementation (Operator does not support running with fake tensors).

This is the GPU half of #5115. #5167 fixed only the CPU rotation path (tensor_cache_key, bool(valid.any()), the AVX512 JIT lookup) and its test also covers only CPU.

Repro

Qwen2.5-0.5B-Instruct (2 layers) quantized with ParoConfig(bits=4, group_size=128) and reloaded with AUTO, which gives ParoTritonLinear on ROCm. Batch of 4 prompts, 32 new tokens, static cache:

m = GPTQModel.load(ckpt, backend=BACKEND.AUTO, dtype=torch.float16)
gen = lambda: m.generate(**enc, max_new_tokens=32, do_sample=False, cache_implementation="static")
gen(); gen()                         # eager: 0.106 s
m.optimize(); counters.clear()
gen(); gen(); gen()                  # compiled: 0.177 s
# torch._dynamo.utils.counters: graph_break=52, unique_graphs=50

The compiled run is 0.6x eager speed, with 52 graph breaks. The break reasons are the lock context manager above and the fake-tensor-less rotation op. A single real down_proj layer compiled fullgraph=True with backend="eager" fails the same way, so the measured level is EAGER against the declared CUDAGRAPH. Explicit torch.cuda.graph capture does work, and replay is bitwise equal to eager.

Suggested fix

Severity

Medium-low. SUPPORTS_COMPILE = False keeps the HF auto-compile off, but optimize() on any Paro model makes ROCm decode 1.7x slower, and the declared level is false for every real checkpoint.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-4e3a0639ecaf is working on this issue now.

    Started 2026-11-18T14:28:06Z. The claim expires 4.0h after this comment is last edited (heartbeat). Other agents: do not start this issue while the claim is live.

    Scope: make ParoTritonLinear actually graph-capturable: remove the rotation-autotune disk-lock graph break and give the fused rotate op a fake/meta implementation (or drop the CUDAGRAPH claim if it cannot be met), with 0-break evidence and a perf check on GPU

  2. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-4e3a0639ecaf finished this issue.

    PR: #5258 — base main, head 23d82d19f (branch fix/5225-paro-triton-cudagraph), 7 files, +361/−4.

    Fix

    Both breaks are gone for a non-identity layer:

    1. _ensure_rotation_autotune_cache_loaded checks the per-device loaded flag before taking _ROTATION_AUTOTUNE_DISK_LOCK, and _resolve_rotation_launch is trace-safe: while compiling it reads the process-local launch cache lock-free, and a cold shape returns the native legacy launch config instead of reading disk or benchmarking. A cold JIT build is also kept out of the trace (_rotation_extension_ready_for_call), with ParoLinear.optimize() prewarming it so the compiled graph keeps the fused op.
    2. rotation.cu registers Meta implementations for rotate, rotate_pair, rotate_pair_grad and grad_theta, returning exactly the metadata the CUDA kernels allocate, so fake-tensor tracing no longer raises Operator does not support running with fake tensors.

    ParoTritonLinear._select_plan returns the default plan while compiling instead of timing kernels on the host. The compile-level test now builds a non-identity rotation with group_size=128, which is why the false CUDAGRAPH claim previously passed.

    Evidence (RTX 5090 sm_120, torch 2.15.0+cu132)

    4-layer ParoTritonLinear model, optimize(backend="inductor"):

    tree breaks graphs compiled vs eager output
    pristine upstream/main (7fcb03e85) 14 4 0.292 ms 0.47x maxdiff 0.0
    this PR 0 1 0.104 ms 1.37x maxdiff 0.0

    Single non-identity layer: red 1 break / 2 graphs and fullgraph=True fails; green 0 breaks / 1 graph with exact match under eager, aot_eager, inductor and reduce-overhead CUDA-graph capture.

    • New tests/kernels/test_paro_triton_cudagraph_5225.py: 5 passed (5 failed pre-fix).
    • test_paro.py + test_kernel_compile_levels_quant.py + new file: 82 passed, 3 skipped.
    • docs/paro.md documents the contract; ruff clean.

    Not verified: ROCm/gfx1201 hardware (the Meta impls are pure ATen metadata and the guards are device-independent, but the 0-break measurement is CUDA); the real ParoQuant checkpoint is not in the offline cache, so the model-level bench uses the same layer construction as tests/kernels/test_paro.py.

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