Repository navigation
fix(awq): address wide-prefill output and activation offsets in 64 bits - #5149
Merged
Merged
Conversation
The AWQ GEMV, GEMV_FAST prefill and split-K reduce kernels computed several
element offsets as 32-bit products. Once a single long-context prefill produced
more than 2^31 output elements (rows x out_features), or the activation itself
passed rows x in_features > 2^31, the store wrapped to a negative offset:
- gemmv2_forward_4bit_cuda_m128n64k32 stored with row_offset * OC; the sm_80+
build silently dropped the tail rows, older arch builds faulted with
cudaErrorIllegalAddress.
- gemm_w4a16_T2 (GEMV_FAST prefill) and gemm_w4a16_T1 (split-K) stored with
write_row * N, and read the A tile with (row + cta_offset_m) * K.
- gemm_forward_4bit_cuda_m16n{128,64}k32 shared the same A and C products.
- group_gemm_forward_4bit_cuda_m16nXk32 indexed C with token_id * OC.
- fused_reduce_splitk_fp32_to_output narrowed result.numel() to int and walked
the partials with 32-bit idx/stride, so the fused reduce addressed the wrong
elements above 2^31.
Widen every affected product to int64_t. Shapes below 2^31 keep identical
arithmetic and numerics.
Adds guarded regressions in tests/kernels/test_awq_gemv_splitk.py and
tests/kernels/test_awq_cuda_fp32_reduce.py that build rows x out_features just
above 2^31 with a small K and only the tail rows nonzero, so each test stays
inside one output allocation while still crossing the boundary.
Fixes #5091
ZX-ModelCloud
marked this pull request as ready for review
November 18, 2026 06:08
14 of 15 tasks
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
The AWQ GEMV (
gemmv2), GEMV_FAST prefill and split-K reduce kernels computedseveral element offsets as 32-bit products. Once one long-context prefill
produced more than 2^31 output elements (
rows x out_features), or theactivation itself passed
rows x in_features > 2^31, the store wrapped to anegative element offset.
Confirmed on current
mainbefore the fix (each case in its own process, sincecudaErrorIllegalAddressis sticky):gemmv2_forward(split_k 1, 2)cudaErrorIllegalAddressgemmv2_forward(split_k 1)illegal addressfrom the same store in other configs)awq_fast_gemm_forward_prefillcudaErrorIllegalAddressgemmv2_forwardK-sidecudaErrorIllegalAddress/ wrong activation rowsgemm_forwardfused split-K reducecudaErrorIllegalAddressThe realistic trigger is a single long-context prefill through one MLP
projection: for Qwen2.5-7B (intermediate 18944) 113,400 tokens suffice, which is
inside the advertised 128K context.
What Changed
gptqmodel_ext/awq/quantization/gemm_cuda_gen.cugemmv2_forward_4bit_cuda_m128n64k32: C store and A row offset in 64-bit.gemm_forward_4bit_cuda_m16n128k32/m16n64k32: A row offset and C store.group_gemm_forward_4bit_cuda_m16nXk32:token_id * OCstore offset.reduce_splitk_fp32_to_output_kernelandfused_reduce_splitk_fp32_to_output:total_elements,idxandstrideare 64-bit, so the fused reduce addresses the right partial above 2^31.
gptqmodel_ext/awq/quantization_new/gemm/gemm_cuda.cugemm_w4a16_T1/gemm_w4a16_T2: A tile loads(
(ld_row + cta_offset_m) * K) and the C store (write_row * N).Shapes below 2^31 keep identical arithmetic, dispatch and numerics; the change
only widens the products. No API, configuration or storage change. Sibling
paths already correct above 2^31 were left alone:
gemm_forwardatsplit_k_iters = 1(the split-K partial base was already 64-bit) and thenon-AWQ backends. Out of scope: chunking M in the Python wrappers — the issue
offers that as an alternative, and widening the offsets keeps the kernels usable
at full prefill length.
Fixes #5091
Tests
New regressions build
rows x out_featuresjust above 2^31 with a small K(256) and only the final rows nonzero, so each case stays inside a single
output allocation while still crossing the boundary. Oracles are the existing
independent float64 dequantize-then-matmul references (GEMV/GEMV_FAST) and the
repo's
dequantize_gemmdense reference (fused reduce).Red evidence, each node run in its own process against the unpatched base:
Green with the fix, same nodes, same device:
Extra manual probes at the issue's shapes (262200 x 8192 and 130112 x 16512,
plus 262144 x 8192 and 130048 x 16512 as controls) show relative error
2.7e-4..3.6e-4 against the float64 oracle for both
gemmv2and GEMV_FAST, and2.1e-4 for the fused-reduce GEMM.
Skips: none in the runs above. Only NVIDIA sm_89 was qualified. The same
widened products serve the ROCm build, but the GEMV/GEMV_FAST paths are
CUDA-only (
AWQ_GEMV_ROCM_UNSUPPORTED) and the AWQ GEMM was not re-run on AMDhardware here.
Model Support / Module Plan
Not applicable: no model type, alias, definition, module plan or fusion
eligibility change.