Skip to content

fix(paro): pick the native Triton kernel on ROCm AUTO and make the dense fallback graph-capturable (#4914) - #5053

Merged
Qubitium merged 1 commit into
ModelCloud:mainfrom
Qubitium:fix/4914-paro-rocm
Nov 18, 2026
Merged

Qubitium merged 1 commit into
ModelCloud:mainfrom
Qubitium:fix/4914-paro-rocm

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Closes #4914.

Problem

ParoLinear declares SUPPORTS_FORMATS = {FORMAT.PARO: 55} and its fast path is the CUDA-only AWQ GEMM extension. On ROCm _cuda_awq_kernel_supported() is always false, so every forward fell through to _forward_dense() and re-dequantized the whole packed weight:

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

ParoTritonLinear is the native ROCm path but kept priority 0, which opts a kernel out of AUTO selection entirely. The same dense fallback also built its extraction offsets with torch.tensor([...], device=...), a host-to-device copy that an explicit torch.cuda.graph capture rejects — so SUPPORTS_GRAPH_CAPTURE = True was false on every ROCm host.

Fix

  • ParoTritonLinear: positive declared priority (AUTO-eligible) plus a device-aware auto_select_priority() that outranks ParoLinear on ROCm and stays behind the measured PARO_CUDA kernel on CUDA.
  • ParoLinear: auto_select_priority() demotes the per-forward dense fallback on ROCm only. Explicit BACKEND.PARO_TRITON requests are unchanged.
  • dequantize_gemm(): derive the four-bit extraction offsets with device-side arithmetic and cache one buffer per device. This removes one H2D copy from every portable AWQ forward and makes the dense Paro path capturable, so the SUPPORTS_GRAPH_CAPTURE = True declaration is truthful on ROCm.

Verification

Radeon AI PRO R9700 (gfx1201), torch 2.16.0.dev+rocm10.1:

  • AUTO selects ParoTritonLinear on ROCm; on a CUDA build the ordering still puts ParoLinear first.
  • Dense ParoLinear forward survives torch.cuda.graph capture with output matching eager, fp16 and bf16.
  • tests/test_paro_rocm_auto_4914.py: 8/8 pass with the fix; 6/8 fail on unmodified main, including both capture nodes with RuntimeError: Cannot copy between CPU and CUDA tensors during CUDA graph capture.
  • tests/kernels/test_paro.py, tests/test_paro.py, tests/kernels/test_selection.py, tests/kernels/test_kernel_compile_protocol.py: 401 passed, 298 skipped.
  • tests/kernels/test_awq_dequantize_tiling.py, test_awq_torch.py, test_awq_runtime_dtype_storage.py: 155 passed, 5 skipped.
  • tests/test_rocm_backend_gating.py: one pre-existing unrelated failure (MarlinLinear message wording) also red on main.

No CUDA behaviour change: the PARO_CUDA kernel keeps the higher rank and Triton remains an explicit backend on CUDA.

…nse fallback graph-capturable (ModelCloud#4914)

`ParoLinear` declares `SUPPORTS_FORMATS = {FORMAT.PARO: 55}` and its fast path
is the CUDA-only AWQ GEMM extension. On ROCm `_cuda_awq_kernel_supported()` is
always false, so every forward fell through to `_forward_dense()` and
re-dequantized the whole packed weight: 438 us vs 69 us per layer, 17.2 vs
47.6 tok/s on Qwen2.5-0.5B ParoQuant (gfx1201). `ParoTritonLinear` is the
native ROCm path but kept priority 0, which opts a kernel out of AUTO
selection entirely.

- Give `ParoTritonLinear` a positive declared priority and a device-aware
  `auto_select_priority()`: it outranks `ParoLinear` on ROCm and stays behind
  the measured CUDA kernel on CUDA. `ParoLinear` demotes itself on ROCm, where
  its dense fallback is the only reachable path. Explicit
  `BACKEND.PARO_TRITON` requests are unchanged.
- `dequantize_gemm()` built its four-bit extraction offsets with
  `torch.tensor([...], device=...)`, a host-to-device copy that an explicit
  `torch.cuda.graph` capture rejects. Derive the constant with device-side
  arithmetic and cache one buffer per device, which also removes one H2D copy
  from every portable AWQ forward. The dense Paro path now captures with
  output matching eager, so `SUPPORTS_GRAPH_CAPTURE = True` is truthful on
  ROCm as well.

Verified on a Radeon AI PRO R9700 (gfx1201, torch 2.16+rocm10.1): AUTO now
selects `ParoTritonLinear`, and a dense `ParoLinear` forward survives capture
for fp16 and bf16. `tests/test_paro_rocm_auto_4914.py` fails on unmodified
`main` (6 of 8 nodes red, including both capture cases with the reported
`Cannot copy between CPU and CUDA tensors during CUDA graph capture`).
@Qubitium
Qubitium merged commit 981f126 into ModelCloud:main Nov 18, 2026
4 checks passed
@Qubitium
Qubitium deleted the fix/4914-paro-rocm branch November 18, 2026 00:45
Qubitium added a commit that referenced this pull request Nov 18, 2026
#5094) (#5180)

`_awq_shifts()` builds `_AWQ_SHIFTS_CACHE` with device arithmetic so a capture
does not need a host-to-device copy (#5053). Device work inside a capture is
recorded, not run, so a table first built there holds uninitialized memory
(zeros). Because the table was published immediately, an abandoned capture left
every later eager AWQ dense dequant decoding with those zeros; a capture that
succeeded but had not been replayed had the same problem for an eager call in
between.

Only publish from an eager call. A capture now gets a fresh uncached table that
is recorded into the graph and is valid on replay; the next eager call derives
and publishes the real one. The fast path is unchanged: a warm eager call still
returns the one cached tensor with no allocation or H2D copy.

The shared `dequantize_gemm()` fixes `AwqTorchLinear`, `ParoLinear`'s dense
path, and the CPU kernels. `AwqTorchLinear` now declares
`SUPPORTS_GRAPH_CAPTURE = True`, which a first-call capture/replay test measures.

Tests: tests/test_awq_shift_capture_5094.py covers an abandoned capture, an
eager call before replay, a replayed first-call capture, AwqTorchLinear,
dense ParoLinear, the CPU kernel, and eager table reuse.

Co-authored-by: GPTQModel Agent <[email protected]>
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