mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #5108] [CLOSED] [Engine] prefill: room after the MMQ row table for ggml's stream-k fixup read (Xid 31 on long prompts) #5310
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5310
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/5108
Author: @quantforge-br
Created: 11/3/2026
Status: ❌ Closed
Base:
main← Head:fix/mmq-ids-overread📝 Commits (1)
8d5c059prefill: room after the MMQ row table for ggml's stream-k fixup read (Xid 31, "prefill copy_i32: an illegal memory access" on long prompts)📊 Changes
1 file changed (+14 additions, -5 deletions)
View changed files
📝
src/prefill/prefill.cpp(+14 -5)📄 Description
Problem and result
On a two-GPU CUDA layer split, a long prompt can end the engine with
prefill copy_i32: an illegal memory access was encountered. The kernel logs Xid 31 (FAULT_PDE,ACCESS_TYPE_VIRT_READ) on the second card.copy_i32is not the kernel that faults: it is the firstcheck()after the fault.The cause is a read past the end of the MMQ row table
ids_identity. ggml'smul_mat_q_stream_k_fixup(ggml/src/ggml-cuda/mmq.cuh:1353at the pinned3cf03257) loadsids_dst[col_low + jt*J + j]for a whole J-column tile before it compares the tile with the expert's rows. The main kernel skips an empty tile first; the fixup only skips its writes. Its tiles run toceil(max_rows / J) * Jfor every expert of the launch, so a fixup block in an empty tile of a late expert reads past the end of the table. llama.cpp takes this buffer from a padded pool. Strata allocates it at its exact size (T * Krows, inPrefill::carve). When the table ends a 2 MiB chunk, the read faults on the next, unmapped chunk.Before, on our setup: 2 of 30 fresh ~235k-token prompts crashed, and the 4 crashing texts we found crash every time. After: the same 30 prompts and the 4 texts all pass. Details below.
Since 0.2.11 (engine 0.1.57) more cards take this path by default. On compute capability 8.0 and up, Unsloth UD-Q4/Q5/Q6_K_XL files read the prompt on MMQ, and their gate/up and down products pass this same table as
ids(prefill.cpp:5702and:5717at9f7d977d). The pinned ggml turns stream-k on for Q4_K, Q5_K and Q6_K in its Ampere config, and sm_120 uses the Ampere rows. So this fix covers those files too, with no extra change. @Norhiro pointed this out in a comment below. We checked it in the source only; we have not run a K-quant pack.Related discussion
No open issue reports this cause. Threads with the same error line that may be this bug. None is confirmed, because we did not run the reporters' setups:
prefill copy_i32: an illegal memory accesson long prompts, CUDA layer split (RTX 3080 Laptop + RTX 3070 Laptop). The reporter found that all 9 crashes they traced were on the second stage. An earlier log there also showsprefill mmq: mul_mat_q: an illegal memory access. The issue was closed in the tracker reset without a cause. The R9700 (RDNA4) reports in the same thread cannot be this read: no RDNA MMQ config in the pinned ggml uses stream-k.copy_i32line) and #5051 (single RTX 3080 Ti Laptop, Xid 31FAULT_PDE, layer-major prefill). Weaker matches: neither log names the faulting kernel, and the #5051 fault address is not at the start of a 2 MiB chunk.Approach
The table now has
T * K + T + 256rows (mmq_ids_rows) instead ofT * K. The size is the same incarveand inbytes_needed_impl. The identity is written over all rows, at the three places that write it (bind_stage_helper,run_impl,lm_run).Why this bound: from an expert's first row the fixup reads at most
ceil(max_rows / J) * Jrows. An expert takes at most one row per token (max_rows <= T), and J is at most 128 in every MMQ config of the pinned ggml. So every read ends before rowT * K + T + 128. The main kernel's read of up toJ - 1rows after an expert's last row also stays inside. WithT = 3072andK = 10the slack is 13.3 KB of VRAM per stage. The rows pastT * Kare never routed to, so the products do not change.A guard in ggml's fixup (
if (jt*J >= col_diff) return;before theidsload) would remove the read at its source. That is a change to the pinned llama.cpp code, so it is not in this PR.Validation
Environment: Linux 7.2, 2x RTX 3090 24 GB (sm_86, no NVLink, 270 W cap), driver 615.78.08, CUDA 13.4. Model: ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-Coder-GGUF IQ1_M (native pack, shipped Coder expert profile). Engine args:
--layer-split 24 --prefill 3072 --max-context 262144 --kv int8 --expert-cache auto --spec 4 --spec-min-p 0.7 --mtp <rt> --pool-workers 15 --vram-reserve-mib 1536 --mmap-experts --trim-stage-weights, withSTRATA_PREFILL_LAYER_MAJOR=0. Build: CUDA, Release,CMAKE_CUDA_ARCHITECTURES=86,STRATA_NATIVE_EXPERTS=ON. Prompts: synthetic texts of 234,296-234,941 tokens, a fresh text per seed, 0 reused tokens. Xid lines were read fromjournalctl -k.Passed:
8d5c059eonmainffa80d73(engine 0.1.56): the 4 texts that crash unpatched builds and 2 fresh prompts, 6 runs. All answered, 0 Xid. Prompt read 4,460-4,565 tok/s.4b9e05a2(engine 0.1.51), the same commit before its rebase:0x1f200000, the start of a 2 MiB chunk), withprefill copy_i32: an illegal memory access was encountered.7dd5cf18(engine 0.1.49.2):compute-sanitizer --tool memcheckon one crashing text. Unpatched:Invalid __global__ read of size 4 bytesinmul_mat_q<IQ2_S,128>(mmq.cuh:1131) and inmul_mat_q_stream_k_fixup<IQ2_S,96>(mmq.cuh:1353), each a few bytes "after the nearest allocation ... of size 123.136 bytes" (123,136). That allocation is the table: 3072 × 10 × 4 bytes plus the 256 bytes thattake()already adds. These reads stay inside the mapped chunk, so they do not fault by themselves; the run under the sanitizer did not reach the read that faults. Patched:ERROR SUMMARY: 0 errorsover 165,888 tokens (54 chunks). The client's timeout ended the run under the sanitizer.ffa80d73, with the ROCm that setup installs for gfx110X (AMD's TheRock wheelsrocm[libraries,devel]==7.10.0a20251120: HIP 7.2.53210, Clang 22). We have no AMD GPU, so nothing ran.setup.py's HIP engine build (-DSTRATA_ENABLE_HIP=ON -DSTRATA_PREFILL_MMQ=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON -DCMAKE_HIP_ARCHITECTURES=gfx1100), host GCC 16.2:stratabuilds and links on both commits, and the patched binary printsstrata 0.1.56.prefill.cppgives the same 312 warnings on both, so the patch adds none.docs/AMD_HIP.md(-DSTRATA_HIP_GFX906=ON -DCMAKE_HIP_ARCHITECTURES=gfx906), clang with GCC 15.3's libstdc++:prefill.cppcompiles on both commits with the same 306 warnings. (With GCC 16's libstdc++ the base already stopped earlier: its<format>does not compile under HIP's__noinline__macro, first insrc/core/weights.cpp.)Failed: none caused by this patch. The gfx906 backend's
stratadoes not link, on this head or on its baseffa80d73:src/core/dflash2.cppcallscudaDeviceGetStreamPriorityRangeandcudaStreamCreateWithPriority, whichinclude/strata/platform/hip_compat/does not map. This came in with3ae2123band is still onmain9f7d977d; it is outside this PR.Not run:
main9f7d977dstill allocates the table atT * Krows, and this branch merges onto it without conflicts.prefill.cppis host C++ in both HIP backends, so it compiles the same for every architecture.sycl/src/prefill/prefill.cppis a separate file.--prefill 3072on this pack happens to end the table about 7.4 KB before a 2 MiB chunk boundary on the second card. Any layout that ends the table near a chunk boundary can fault.Limits
T + 256rows past an expert's first row, which holds for the pinned ggml (J <= 128). A ggml update that raises the largest J would need a larger slack.pp->identinset_peer,--peer-device) is also allocated at its exact size. This PR does not change it, and we do not run--peer-device.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.