Skip to content

[PERF] Regression from #5164 (fix of #5096): ParoLinear's 640-row dense dispatch makes 641-~2000-token prefills 1.1-2.1x slower per layer on 7-8B shapes (1.29x end-to-end at 768 tokens on Llama-3.2-1B) #5210

Closed

Description

@Qubitium

Found on main @ 396b5f0, RTX 4090 (sm_89), torch 2.15 + CUDA 13.2.

What is wrong

#5164 (fix of #5096) added a row-count dispatch to ParoLinear (gptqmodel/nn_modules/qlinear/paro.py, _PARO_AWQ_DENSE_MIN_ROWS = 640). Above 640 rows the layer dequantizes the packed weight and calls cuBLAS. At or below 640 it keeps the native split-K AWQ GEMM. The threshold was tuned only on Qwen2.5-0.5B shapes (K/N = 896/4864 and 4864/896, docs/paro.md). Even that table shows the native kernel still ahead at 1024 rows for 4864/896.

On 7-8B projection shapes the native kernel stays faster up to about 1500-2500 rows. So every prefill between 641 and roughly 2000 tokens now runs 1.1-2.1x slower per layer than before #5164. For down_proj-like shapes (K=14336) it also uses more peak memory, because it materializes the full dequantized weight (112 MiB) instead of the small split-K partials.

Per-layer timing: synthetic ParoLinear built like tests/kernels/test_paro.py::_paro_module (bits 4, g128, bias). Both routes run in the same process by toggling _PARO_AWQ_DENSE_MIN_ROWS (10**9 = the old always-native behaviour), interleaved, min of 2x5 timings:

dtype K x N M=641 M=768 M=1024 M=2048 M=4096
fp16 4096 x 4096 0.238 -> 0.438 ms (1.84x) 1.65x 1.30x 0.95x 0.65x
fp16 4096 x 14336 1.026 -> 1.629 ms (1.59x) 1.42x 1.10x 0.79x 0.64x
fp16 14336 x 4096 0.754 -> 1.475 ms (1.96x), peak 50 -> 132 MiB 1.76x 1.49x 1.03x 0.81x
bf16 4096 x 4096 1.75x 1.70x 1.17x 0.94x 0.76x
bf16 4096 x 14336 1.50x 1.43x 1.17x 0.78x 0.67x
bf16 14336 x 4096 2.06x, peak 50 -> 132 MiB 1.72x 1.60x 1.16x 0.82x

(ratio = dense route / native route; M=512 is unchanged at 1.00-1.03x.)

Whole model, a real ParoQuant 4-bit Llama-3.2-1B-Instruct checkpoint (AUTO -> ParoLinear), one prefill through model.model, same toggle:

seq fp16 native -> new bf16 native -> new
512 16.20 -> 16.21 ms (1.00x) 1.00x
768 24.94 -> 32.23 ms (1.29x) 1.28x
1024 33.36 -> 35.40 ms (1.06x) 1.04x
1536 0.93x 0.94x
2048 0.83x 0.84x
4096 0.71x 0.72x

The large-M win (and the #5096 crash fix) is real. The regression is the 641 to ~1500-2000 row band, which covers ordinary prompt lengths, and it is larger on 7-8B shapes than on the 1B model above.

Repro

import torch, sys
sys.path.insert(0, "tests/kernels")
import test_paro as T
import gptqmodel.nn_modules.qlinear.paro as P
m = T._paro_module(14336, 4096, 128, torch.float16)          # down_proj-like
x = torch.randn(641, 14336, device="cuda", dtype=torch.float16)
def ms():
    with torch.inference_mode():
        for _ in range(3): m(x)
        a, b = torch.cuda.Event(True), torch.cuda.Event(True); a.record()
        for _ in range(10): m(x)
        b.record(); b.synchronize(); return a.elapsed_time(b) / 10
P._PARO_AWQ_DENSE_MIN_ROWS = 10**9; print("native", ms())   # 0.754 ms
P._PARO_AWQ_DENSE_MIN_ROWS = 640;   print("dense ", ms())   # 1.475 ms

Suggested fix

Make the threshold shape-aware, or at least raise it. The dequantize cost is about K*N and does not shrink with M, so the crossover row count grows with the layer size: about 640-1024 for 896x4864, and about 1500-2500 for 4096-wide projections on sm_89. Two options: dispatch on rows > max(640, c * something(K, N)), or use a small per-(K, N, dtype, arch) measured table. #5096's real concern (2^31 elements, split_k x output transient memory) only appears at tens of thousands of rows, so a threshold of about 2048 would keep the crash fix with no loss on any shape measured here. Please also re-measure on sm_120 and gfx1201.

Test that should have caught it

tests/kernels/test_paro.py checks only the route and the oracle. The docs/paro.md validation table uses only 0.5B shapes, and its own 4864/896 row shows native ahead at 1024 rows. A dispatch benchmark on 7-8B shapes (4096/14336) across M = 512-4096 would have shown the band.

Severity

Medium (perf). This is the CUDA AUTO path for every ParoQuant model, and the band covers typical prompt prefill lengths: up to 2x slower per layer on 8B shapes, 1.29x end to end on a 1B model at 768 tokens. Output is unaffected.

🤖 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-18T13:35:24Z. 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: remove the ParoLinear 640-row dense dispatch cliff: 641-2000-token prefills regressed 1.1-2.1x per layer after #5164; pick the dispatch so a 768-token prefill is not slower than before, with before/after timing on 7-8B shapes

  2. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

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

    PR: #5250 — base main, head c1541a0e1 (branch fix/5210-paro-dispatch), 3 files, +227/−33.

    Fix

    ParoLinear's dense/split-K crossover is now shape-aware: paro_awq_dense_min_rows(in_features, out_features) anchors 2400 rows at 4096x4096 and scales with the aspect/width fit (clamped to 2048–4096), resolved once per layer in post_init. The 641–2000-row band therefore keeps the native split-K AWQ GEMM on 7–8B projections, while wide prefills (>~2500–3000 rows) still take the dense route that #5096 needs. docs/paro.md is rewritten with the measured crossovers and the new table.

    Evidence (RTX 5090, per layer, min-of-6x10, interleaved)

    K/N M native #5164 (>640) new
    4096/4096 641 0.164 ms 0.326 (2.00x) 0.165 (1.01x)
    4096/14336 641 0.630 1.117 (1.77x) 0.630 (1.00x)
    14336/4096 641 0.521 1.101 (2.12x) 0.522 (1.00x)
    14336/4096 4096 3.380 3.242 3.019 (0.89x)

    End-to-end equivalent 16-layer Paro stack, FP16: seq 768 14.40 / 23.53 (1.63x) / 14.41 (1.00x) ms; seq 2048 42.14 / 40.12 / 37.54 (0.89x). Peak memory on down_proj-like 14336x4096 at M=641 drops 154 → 50 MiB.

    tests/kernels/test_paro.py 62 passed, 1 skipped; Paro family 417 passed, 9 skipped (one order-dependent test deselected, passes alone); ruff clean.

    Not verified: sm_89/gfx1201 re-measurement (fit is conservative vs the issue's sm_89 crossovers); real ParoQuant Llama-3.2-1B checkpoint not in the offline cache, so the e2e used a same-shape stack.

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