mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #5418] [Engine] fix layer-major prefill overflowing the group-scratch row cap #5417
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#5417
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/5418
Author: @WilliamStone
Created: 11/6/2026
Status: 🔄 Open
Base:
main← Head:fix/lm-group-cap-scratch📝 Commits (1)
b621394prefill: cap layer-major expert groups at the group-scratch row cap📊 Changes
1 file changed (+4 additions, -2 deletions)
View changed files
📝
src/prefill/prefill.cpp(+4 -2)📄 Description
This bug was first isolated in the Speedy fork (DevDock-AI/Speedy); the fix was submitted there and accepted as DevDock-AI/Speedy PR #4. This PR upstreams the same change. Both
G = m.T * Ksites are unchanged onorigin/mainand tagv0.2.11.Problem
Long prompts (~29K tokens and up) crash mid-prefill on the layer-major path with
STRATA_PF_GROUP_SCRATCH=1: the engine stops and the server returns HTTP 503 (the engine stopped unexpectedly). Other prompt sizes may surface as an HTTP 400 instead, depending on where the overflow lands in memory.Root cause
STRATA_PF_GROUP_SCRATCHallocates the per-group MoE scratch (GU/H/Hq) forgroup_cap_rows()rows — 15,872 rows with T=8192. The layer-major path still packed expert entries withG = m.T * K(81,920 here), so a routed group over the cap ran as one range.swigluwrote rows past the end ofm.Hintom.Hq; quantize then read the overwrittenHqscales as inf, the down GEMM produced 0x7fffffff NaN rows, andmoe_scatter_addcarried them intoacc.Evidence from the fork's instrumented runs (2×GPU, CUDA0(Nvidia 3060): layers 0–23 / CUDA1(Nvidia 5070): layers 24–47; same code path):
Fix
Use
min(m.T * K, m.group_cap)forGin bothlm_prepare()(routing-table sizing, so the tables match the entries) andlm_experts()(entry packing). Oversized groups now fall back to the existing sub-range splitting, which already assertsnra <= m.group_cap. Withm.group_cap == 0(scratch off or fused layout) the expression reduces to the oldm.T * K, so the non-scratch path is unchanged.Validation
All on a clean v0.2.10 build (CUDA 13.4, arch
86;120, Windows 11, RTX 3060 + RTX 5070 2×12 GB, layer split 24,qwen3.8-flash-next-iq3_s,--prefill auto→ chunk 8192):STRATA_PF_GROUP_SCRATCH=1, unpatched: a ~29.7K-token prompt →prefill mmq: gather_native: an illegal memory access was encounteredon the first super-chunk.STRATA_PF_GROUP_SCRATCH=0, unpatched: completes — 63,784 prompt tokens, 974 tok/s prefill.STRATA_PF_GROUP_SCRATCH=1, patched: the same ~29.7K prompt completes (611 tok/s cold, ~1s warm via prompt cache); a 63,784-token prompt also completes (766 tok/s).Limits / not run
STRATA_PREFILL_LAYER_MAJOR=1forces it on one GPU, where the sameG/cap mismatch applies — two cards are not required to hit this.STRATA_PF_GROUP_SCRATCH=0after the patch was verified by code inspection only (m.group_cap == 0⇒G == m.T * K, identical to the previous expression) for the non-scratch path; a runtime scratch-off run on the unpatched build is listed above.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.