Skip to content

[PERF][ROCm] AUTO loads ParoQuant as ParoLinear, which on ROCm re-dequantizes the full weight every forward (2.8x slower generate than PARO_TRITON, 438 vs 69 us/layer) and fails CUDA-graph capture despite SUPPORTS_GRAPH_CAPTURE=True #4914

Closed

Description

@Qubitium

Found on main @ 4f287eb, AMD Radeon AI PRO R9700 (gfx1201), torch 2.16 dev + ROCm 10.1. The code paths involved are unchanged on current main.

What is wrong

On ROCm, BACKEND.AUTO loads every ParoQuant layer as ParoLinear (SUPPORTS_FORMATS = {FORMAT.PARO: 55}; ParoTritonLinear is priority 0, per the comment at paro_triton.py:63). On ROCm ParoLinear has no native kernel. _forward_cuda_awq_kernel() returns None because the AWQ CUDA extension is not built for HIP, so every forward falls through to _forward_dense(). That path re-dequantizes the whole packed weight on every call (AwqTorchLinear._dequantize_weight_for_inference -> dequantize_gemm) before the matmul.

This causes two problems:

  1. Performance (the default ROCm path). Qwen2.5-0.5B-Instruct ParoQuant 4-bit g128, fp16, gfx1201:

    backend class layers.0.mlp.down_proj M=1 generate 64 tokens
    AUTO ParoLinear (dense fallback) 438 us 17.2 tok/s
    PARO_CUDA ParoLinear 454 us 17.0 tok/s
    PARO_TRITON ParoTritonLinear 69 us 47.6 tok/s

    bf16 behaves the same (440 us vs 86 us per layer). ParoTritonLinear is numerically equivalent on this card: layer-0 fuzz of PARO_CUDA (dense) vs PARO_TRITON over M = 0..2048, 2-D/3-D/row- and column-strided inputs, fp16 and bf16, has worst rel 3.4e-4 (fp16) / 3.2e-3 (bf16), and both are deterministic. The ROCm "portable path" is therefore 2.8x slower end to end with no accuracy benefit.

  2. Capability declaration is false on ROCm. ParoLinear declares SUPPORTS_GRAPH_CAPTURE = True (measured on sm_80, where the AWQ CUDA kernel exists). On ROCm the dense fallback builds a host tensor inside dequantize_gemm (quantization/awq/utils/packing_utils.py:242, torch.tensor([...], device=device)), so an explicit torch.cuda.graph capture always fails:

    File ".../qlinear/paro.py", line 609, in _forward_dense
    File ".../qlinear/torch_awq.py", line 335, in _dequantize_weight_for_inference
    File ".../quantization/awq/utils/packing_utils.py", line 242, in dequantize_gemm
        shifts = torch.tensor([lane * bits for lane in AWQ_REVERSE_ORDER], dtype=torch.int64, device=device)
    RuntimeError: Cannot copy between CPU and CUDA tensors during CUDA graph capture unless the CPU tensor is pinned.
    

    ParoTritonLinear captures fine on the same card (replay matches eager exactly, fp16 and bf16, M=1 and M=16).

Repro

m = GPTQModel.load(paro_ckpt, backend=BACKEND.AUTO, dtype=torch.float16, device="cuda:0")   # ROCm
mod = m.model.model.layers[0].mlp.down_proj        # -> ParoLinear
x = torch.randn(1, mod.in_features, device="cuda", dtype=torch.float16)
with torch.no_grad():
    mod(x)
    g = torch.cuda.CUDAGraph()
    with torch.cuda.graph(g):                      # RuntimeError above
        mod(x)

Timing comes from 200 back-to-back module calls after warm-up and from model.generate(max_new_tokens=64) on an otherwise idle card.

Suggested fix

  • On ROCm, where _cuda_awq_kernel_supported() can never be true, prefer ParoTritonLinear in AUTO. For example, give it a positive priority on DEVICE.ROCM, or have ParoLinear.validate() reject ROCm when the HIP build lacks the AWQ kernel, unless the request is explicit.
  • Make SUPPORTS_GRAPH_CAPTURE truthful for the dense fallback. Hoist the shifts constant in dequantize_gemm to a cached device buffer, which also removes one H2D copy per forward on every portable AWQ path. Otherwise declare the capability per device.
  • Cache the dequantized dense weight, or the int4 repack, across calls when the dense fallback is the steady-state path.

Test that should have caught it

tests/kernels/test_kernel_compile_levels_quant.py (ParoLinear case) only runs on CUDA hosts with the AWQ kernel. It should also run on ROCm, where it fails. A ROCm AUTO-selection test for ParoQuant should assert that the selected kernel is not the per-forward dense dequant path.

Severity

Medium. It is the default inference path for ParoQuant on ROCm: 2.8x slower generation, and the declared CUDA-graph capability is wrong there.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-4914-rocm-paro is working on this issue now.

    Started 2026-11-18T00:14Z. The claim expires 4.0h after this comment is last edited; it is released with the PR link or with a stand-down comment.

    Scope: AUTO must not pick the per-forward dense-dequant path on ROCm, and the host-tensor shifts build in dequantize_gemm must go away so the dense fallback is capture-safe on every device.

  2. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Claiming this one to fix the ROCm AUTO selection and the false graph-capture declaration.

    Plan:

    • Make AUTO prefer ParoTritonLinear on ROCm when it validates (keep explicit backend requests authoritative, keep CUDA PARO_CUDA behaviour unchanged).
    • Make SUPPORTS_GRAPH_CAPTURE truthful per device for the dense fallback (and/or cache the shifts constant so capture works).
    • Regression test that fails on unmodified main for DEVICE.ROCM AUTO selection + graph capture.
  3. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Fixed by #5053 (squash-merged as 981f1266c).

    • AUTO now selects ParoTritonLinear on ROCm (ParoLinear demotes its dense fallback there; CUDA ordering unchanged).
    • dequantize_gemm() derives the four-bit extraction offsets on-device and caches one buffer per device, so the dense Paro fallback captures under torch.cuda.graph and the SUPPORTS_GRAPH_CAPTURE = True declaration is truthful on ROCm.
    • Verified on gfx1201 (torch 2.16+rocm10.1): AUTO → ParoTritonLinear; dense capture matches eager for fp16/bf16. tests/test_paro_rocm_auto_4914.py is 8/8 green with the fix and 6/8 red on unmodified main (including both capture nodes with the reported host-copy RuntimeError).
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