[PR #5030] [CLOSED] [Engine] dsv41: size the dense dequantizer's staging slot by the block, not by Q5_K's span #5291

Closed
opened 2026-11-07 16:34:06 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5030
Author: @cuzlin226
Created: 11/2/2026
Status: ❌ Closed

Base: main ← Head: fix/dq-rows-q6k-span


📝 Commits (1)

  • e2837e4 dsv41: size the dense dequantizer's staging slot by the block, not by Q5_K's span

📊 Changes

1 file changed (+14 additions, -3 deletions)

View changed files

📝 src/dsv41/ds4_iq.cu (+14 -3)

📄 Description

Problem and result: on a gfx11 device (RX 7900 XTX) a conversation switch could end in illegal memory access and a dead request path. The gfx11 default dense dequantizer, dq_rows_kernel<T>, sizes its per-warp shared staging slot for the Q5_K span (44 uint4 = 704 B) and copies kSpan / 16 uint4 into it. For Q6_K the span is 4 * 210 = 840 B (53 uint4), so every warp writes 136 B past its slot — into the next warp's slot, and past the array for the last warp — and the truncated kSpan / 16 (52) also drops the last 8 B of the fourth superblock. The decoded dense Q6_K weights come out as garbage whose FP16 conversion overflows to inf; a GEMM on them returns NaN, the router's top-k then leaves 0x7FFFFFFF in its output (NaN never compares greater), and moe_sort_kernel<false> reads vs[0x7FFFFFFF], which is a protection fault on ROCm. After this change the same run passes and the dequantized weights contain no inf.

Related discussion: Niko1221/Strata#4350 (root cause, probes and the single-variable evidence).

Approach: size the staging slot from the type instead of the Q5_K constant (kSpanU4 = (kSpan + 15) / 16), index each warp's slot by it, and copy the tail of a span that is not a multiple of 16 bytes by byte instead of reading past the row. The staging path, the decode indexing and every other type's numbers are unchanged: Q2_K 21, Q3_K 28, Q4_K 36, Q5_K 44 uint4 are what they were, and Q6_K becomes 53. Shared memory per block grows only for Q6_K (8 warps: 5632 -> 6784 B).

Validation (engine 0.1.55 tree at c62d5e3a1, RX 7900 XTX / gfx1100, ROCm 7.2, single card, tp 1, a maya-ds4 pack with Q6_K dense tensors):
Passed: cmake --build build-hip --target strata-dsv41 -j 8 (HIP), clean.
Passed: the five-request reproduction from #4350 (A x3 chained, one interleaved conversation, then A again with its full history) under three settings — DS4_DQ_OLD unset (gfx11 default), DS4_DQ_OLD=1 (old kernel forced), DS4_DQ_OLD=0 (the coalesced kernel). All three finish with no illegal memory access; before the change the first two faulted 5/5.
Passed: the dequantized Q6_K block (k=8192, n=5120) is now bit-identical between DS4_DQ_OLD=1 and DS4_DQ_OLD=0 (FNV-1a over all 8,388,608 halves = d5cadd2ca2a3e840 in both, same first values), so the staged path produces exactly what the coalesced kernel produces. Before the change the same block from the old kernel held 17,920 NaN and 558,114 inf halves.
Not run: a CUDA build. The kernel is HIP-only (dq_use_old_kernel() returns false elsewhere) and this machine has no CUDA device; the change is inside a template body a CUDA build still compiles, but I did not build it.
Not run: gfx1151. Its default is the same kernel (the gfx11 prefix), and #4825 reports a moe_sort_kernel<false> fault there, so it is the likely second beneficiary; I could not test it.

Limits: the Q6_K dense-GEMM path is the one that reproduced this — a pack whose dense tensors are Q6_K and whose prompt reaches the chunked dense GEMM. A Q5_K dense tensor uses exactly the 44-uint4 span and keeps its current behavior. The route_kernel NaN guard discussed in #4350 is a separate hardening change and is not part of this one.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/5030 **Author:** [@cuzlin226](https://github.com/cuzlin226) **Created:** 11/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/dq-rows-q6k-span` --- ### 📝 Commits (1) - [`e2837e4`](https://github.com/Niko1221/Strata/commit/e2837e437576bc13faf2027e0842f4f3ebd6e693) dsv41: size the dense dequantizer's staging slot by the block, not by Q5_K's span ### 📊 Changes **1 file changed** (+14 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/dsv41/ds4_iq.cu` (+14 -3) </details> ### 📄 Description Problem and result: on a gfx11 device (RX 7900 XTX) a conversation switch could end in `illegal memory access` and a dead request path. The gfx11 default dense dequantizer, `dq_rows_kernel<T>`, sizes its per-warp shared staging slot for the Q5_K span (44 `uint4` = 704 B) and copies `kSpan / 16` `uint4` into it. For Q6_K the span is `4 * 210 = 840 B` (53 `uint4`), so every warp writes 136 B past its slot — into the next warp's slot, and past the array for the last warp — and the truncated `kSpan / 16` (52) also drops the last 8 B of the fourth superblock. The decoded dense Q6_K weights come out as garbage whose FP16 conversion overflows to `inf`; a GEMM on them returns `NaN`, the router's top-k then leaves `0x7FFFFFFF` in its output (NaN never compares greater), and `moe_sort_kernel<false>` reads `vs[0x7FFFFFFF]`, which is a protection fault on ROCm. After this change the same run passes and the dequantized weights contain no `inf`. Related discussion: Niko1221/Strata#4350 (root cause, probes and the single-variable evidence). Approach: size the staging slot from the type instead of the Q5_K constant (`kSpanU4 = (kSpan + 15) / 16`), index each warp's slot by it, and copy the tail of a span that is not a multiple of 16 bytes by byte instead of reading past the row. The staging path, the decode indexing and every other type's numbers are unchanged: Q2_K 21, Q3_K 28, Q4_K 36, Q5_K 44 `uint4` are what they were, and Q6_K becomes 53. Shared memory per block grows only for Q6_K (8 warps: 5632 -> 6784 B). Validation (engine 0.1.55 tree at `c62d5e3a1`, RX 7900 XTX / gfx1100, ROCm 7.2, single card, tp 1, a maya-ds4 pack with Q6_K dense tensors): Passed: `cmake --build build-hip --target strata-dsv41 -j 8` (HIP), clean. Passed: the five-request reproduction from #4350 (A x3 chained, one interleaved conversation, then A again with its full history) under three settings — `DS4_DQ_OLD` unset (gfx11 default), `DS4_DQ_OLD=1` (old kernel forced), `DS4_DQ_OLD=0` (the coalesced kernel). All three finish with no `illegal memory access`; before the change the first two faulted 5/5. Passed: the dequantized Q6_K block (k=8192, n=5120) is now bit-identical between `DS4_DQ_OLD=1` and `DS4_DQ_OLD=0` (FNV-1a over all 8,388,608 halves = `d5cadd2ca2a3e840` in both, same first values), so the staged path produces exactly what the coalesced kernel produces. Before the change the same block from the old kernel held 17,920 `NaN` and 558,114 `inf` halves. Not run: a CUDA build. The kernel is HIP-only (`dq_use_old_kernel()` returns false elsewhere) and this machine has no CUDA device; the change is inside a template body a CUDA build still compiles, but I did not build it. Not run: gfx1151. Its default is the same kernel (the `gfx11` prefix), and #4825 reports a `moe_sort_kernel<false>` fault there, so it is the likely second beneficiary; I could not test it. Limits: the Q6_K dense-GEMM path is the one that reproduced this — a pack whose dense tensors are Q6_K and whose prompt reaches the chunked dense GEMM. A Q5_K dense tensor uses exactly the 44-`uint4` span and keeps its current behavior. The `route_kernel` NaN guard discussed in #4350 is a separate hardening change and is not part of this one. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:34:06 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5291
No description provided.