Repository navigation
fix(paro): address wide-prefill offsets and dispatch long prefills to cuBLAS (#5096) - #5164
Merged
Merged
Conversation
… cuBLAS (#5096) Two independent 32-bit assumptions ended a single prefill once rows x out_features passed 2^31, or the activation itself passed rows x in_features > 2^31: - paro_gemm_kernel computed K * offsets_am and N * offs_cm from int32 row vectors, so the fused Triton GEMM wrapped the address and faulted with cudaErrorIllegalAddress / hipErrorIllegalAddress. - ParoLinear called the native split-K AWQ GEMM for every row count. Its store is 64-bit since the AWQ wide-offset fix, but it still allocates one FP32 partial slab per split, so a long prefill paid split_k x the output in transient memory and was slower than dequantize + cuBLAS from ~640 rows. Widen both Triton row vectors to int64, and give ParoLinear the AwqGEMMLinear large-M dispatch: above 640 rows dequantize the packed grid, run cuBLAS with an FP32 reduction and add the stored bias before one output cast. Below the threshold the native kernel is unchanged. Adds regressions in tests/kernels/test_paro.py that build rows x out_features and rows x in_features just above 2^31 with only the tail rows nonzero, assert the dispatched route and oracle agreement, and keep a short-prefill control on the native kernel. Fixes #5096
ZX-ModelCloud
force-pushed
the
fix/5096-paro-wide-prefill-offsets
branch
from
November 18, 2026 07:13
bc621f6 to
481516d
Compare
Qubitium
marked this pull request as ready for review
November 18, 2026 07:17
This was referenced Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5096.
Two independent 32-bit assumptions in the Paro GPU prefill path faulted the
device (and, on the default CUDA path, wasted VRAM) once a single forward
produced more than 2^31 output elements (
rows x out_features), or theactivation itself exceeded
rows x in_features > 2^31.Confirmed on current
mainbefore the change:paro_gemm_kernel(gptqmodel/quantization/paro/modules/triton/gemm.py:255,:308) builtK * offsets_amandN * offs_cmfrom int32 vectors, so thefused Triton GEMM wrapped the address and raised
CUDA error: an illegal memory access was encountered/hipErrorIllegalAddress.ParoLinear._forward_cuda_awq_kernelfed the native split-K AWQ GEMM forevery row count. The underlying
row_offset * OCstore is already 64-bit(the AWQ wide-offset fix, fix(awq): address wide-prefill output and activation offsets in 64 bits #5149), so no crash remains there, but the kernel
still allocates one FP32 partial slab per split: at 32k rows it peaked at
3266 MiB for a 297 MiB output and was 2.2x slower than dequantize + cuBLAS.
What Changed
paro_gemm_kernel: buildoffsets_amandoffs_cmfrompid_m.to(tl.int64)so A and C row addresses stay 64-bit. Shapes below 2^31keep identical arithmetic.
ParoLinear: add_PARO_AWQ_DENSE_MIN_ROWS = 640and theAwqGEMMLinear-style large-M dispatch. Above 640 rows the layer dequantizesthe packed grid, runs cuBLAS with an FP32 reduction, adds the stored bias in
FP32 and casts once. Below the threshold the native kernel is unchanged. The
route is a module constant, not an environment switch, and the reconstructed
weight exists only for the dispatched call (no retained dense copy).
docs/paro.md: new "Native prefill dispatch and wide offsets" mechanismpage section with the old/new flow and the measured table.
Behaviour changes: a prefill above 640 rows uses a different (faster, smaller)
kernel. Accuracy is unchanged within output rounding (2e-5 relative against the
FP32 packed-grid oracle).
Tests
Red/green (both trees at the same base, tests copied into the pre-fix tree):
New nodes:
test_paro_triton_prefill_stores_rows_above_int32_element_count,test_paro_triton_prefill_reads_activations_above_int32_row_stride_product,test_paro_cuda_long_prefill_matches_the_dense_oracle[float16, bfloat16],test_paro_cuda_short_prefill_keeps_the_native_kernel,test_paro_cuda_long_prefill_stores_rows_above_int32_element_count.Oracle: the independent FP32 packed-grid dequantization
(
_fp32_awq_oracle). Long-prefill output is compared against the oraclerounded to the same output dtype (bounded by 4 output ULPs) plus a visible
error bound against the FP32 oracle, so mandatory output rounding is measured
separately from kernel error.
Skipped/not verified: ROCm coverage is the two Triton boundary cases only; the
native CUDA dispatcher tests are CUDA-only by design. The Triton fix is not
exercised on Hopper/Blackwell tiles.
Model Support / Module Plan
Not applicable: no
MODEL_MAP, definition, alias, or module-plan change.Logic Flow Documentation
docs/paro.mdrepeats the diagrams in the"Native prefill dispatch and wide offsets" section, titled for the
mechanism.
README.mdalready linksdocs/paro.md.mechanism.
README.mdalready linksdocs/paro.md.Old flow (
main):flowchart TD A["ParoLinear.forward"] --> B["_forward_cuda_awq_kernel (paro.py:753)"] B --> C{"native shape and device contract?"} C -- "No" --> Z["portable paths: AVX512 / ATen / dense"] C -- "Yes" --> F["native split-K AWQ GEMM for every row count"] F --> P["one FP32 partial slab per split"] P --> H["sum / fused reduce then store with row_offset * OC"]flowchart LR A["ParoTritonLinear prefill"] --> B["paro_gemm_kernel (gemm.py:227)"] B --> C["offsets_am = pid_m * BLOCK_SIZE_M (int32)"] B --> D["offs_cm = pid_m * BLOCK_SIZE_M (int32)"] C --> E["a_ptrs = K * offsets_am + offsets_k"] D --> F["c_ptrs = N * offs_cm + offs_cn"] E --> G["wrapped A row address above 2^31"] F --> H["wrapped C row address above 2^31"] style G fill:#fce8e6,stroke:#a33,color:#111 style H fill:#fce8e6,stroke:#a33,color:#111New flow:
flowchart TD A["ParoLinear.forward"] --> B["_forward_cuda_awq_kernel(rotated)"] B --> C["_cuda_awq_kernel_supported(compute_dtype)"] C --> D{"native shape and device contract?"} D -- "No" --> Z["portable paths: AVX512 / ATen / dense"] D -- "Yes" --> E{"rows > _PARO_AWQ_DENSE_MIN_ROWS (640)?"} E -- "No" --> F["native split-K AWQ GEMM"] E -- "Yes" --> G["_forward_dense_batch: dequantize + cuBLAS, FP32 reduce, bias, one cast"] F --> H["output"] G --> H Z --> H classDef wide fill:#e8f4ff,stroke:#36c,color:#111 class G wide style Z stroke-dasharray: 4 2flowchart LR A["ParoTritonLinear prefill"] --> B["paro_gemm_kernel"] B --> C["offsets_am = pid_m.to(int64) * BLOCK_SIZE_M"] B --> D["offs_cm = pid_m.to(int64) * BLOCK_SIZE_M"] C --> E["a_ptrs = K * offsets_am + offsets_k"] D --> F["c_ptrs = N * offs_cm + offs_cn"] E --> G["64-bit A row address"] F --> H["64-bit C row address"]Review Requirements
_forward_denseepilogue is reused.Kernel Accuracy Requirements
the CUDA-only dispatcher tests ran on NVIDIA only, and that limit is
stated above.