[PR #5468] [Engine] q36: layer-major prompt prefill stages a layer's experts once per N chunks #5440

Open
opened 2026-11-07 16:35:12 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5468
Author: @bahooo22
Created: 11/7/2026
Status: 🔄 Open

Base: main ← Head: pr-super-chunk


📝 Commits (4)

  • 652e4df super-chunk: слой-мажорный обход промпта, эксперты слоя стейджатся один раз
  • b019e83 super-chunk: фиксы ревизии — stream_base только при активном потоке, cap N и лог
  • d721ed3 q36: super-chunk — residual x переносится в xsuper вместе с h (критический фикс)
  • f4324e0 docs: add the super-chunk prefill notes to the PR

📊 Changes

3 files changed (+342 additions, -3 deletions)

View changed files

➕ docs/research/super-chunk.md (+117 -0)
➕ docs/research/super-chunk.ru.md (+112 -0)
📝 src/qwen35/q36_engine.cu (+113 -3)

📄 Description

Problem and result

On a hybrid placement the prompt is read chunk by chunk; every chunk walks all layers and reloads each layer's experts over PCIe. On a 96k prompt, N=1 spent 8.7 s in expert H2D copies and 14.6 s in MMQ out of 103.2 s. After the change the prefill is layer-major: a layer runs over N sub-chunks (2048 tokens each) while its experts are staged once. At 96k, KAT IQ4_XS, q4_0 KV, super N=4 against N=1: 1024.0 tok/s against 800.9 (+27.9 %), TTFT -23.5 s, slots 19 -> 17; MoE 49.5 -> 23.3 s. 64k +25 %, 128k +21 %, HauhauCS IQ4_XS +22 %. STRATA_Q36_SUPER_CHUNK=4 enables it; N=1 is the old path and is bit-identical.

Design, measurements and limits: docs/research/super-chunk.md (EN/RU), included in this PR. The review findings (stream_base only with an active stream, cap N <= 8, MTP accounting, the residual-x fix) are part of this PR. Related: #3976 is the layer-major walk of the src/prefill engine; the q36 native path this PR changes does not run Prefill and has no layer-major mode. Scope agreement requested (feature).

Approach

  • forward_super: a layer runs over the super-chunk; per-chunk buffers keep their tmax size, xsuper/hsuper hold T*N rows.
  • The critical fix: forward_super wrote embeddings into xsuper but did not fill the residual x; layer() does x += mixer(h) in place, so the first sub-chunk mixed another sub-chunk's residual (garbage on any text longer than 2048, needle 0/6). Two copies around the layer (x <- xsuper[off], xsuper[off] <- x) plus the hmain update fix it; at N=1 the path is bit-identical.
  • The expert stream starts only when active (main_hybrid && use_mmq && lhy(l)); cap N <= 8 (32 MiB per 2048-token chunk); the price is logged at start.

Validation

Passed (revision f4324e03, Windows 11, CUDA 13.3, sm_86, RTX 3060 Ti 8 GiB):

  • N=1 against base: bit-identical (SHA and decode); 4k state dump of S/conv of all 30 GDN layers, hlast and KV: same SHA, cos 1.000000.
  • 96k: N=1 800.9 pp / 16.7 tg, N=4 1024.0 / 17.2 (+27.9 %), TTFT 108.9 -> 85.4 s; 64k +25 %, 128k +21 %, HauhauCS +22 %.
  • Decode step 1 after N=4: two N=4 runs identical (max_abs 0.0); N=1 vs N=4 differs at step 1 by max_abs 0.181-0.231 with the same argmax (different summation order, not a state defect).

Failed: none observed.

Not run: HIP, SYCL, Metal; models other than KAT and HauhauCS IQ4_XS; a formal unit test (the bit-exact check is a manual state dump). Draft until backends are covered.

Limits

N is capped at 8; larger N needs more VRAM for xsuper/hsuper and is not measured. A cancelled request stops at a sub-chunk boundary rather than immediately.

Scope note: this is an internal prefill optimization behind STRATA_Q36_SUPER_CHUNK (off by default). Default behaviour is unchanged; the layer-major staging path is opt-in.


🔄 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/5468 **Author:** [@bahooo22](https://github.com/bahooo22) **Created:** 11/7/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr-super-chunk` --- ### 📝 Commits (4) - [`652e4df`](https://github.com/Niko1221/Strata/commit/652e4dff13df916d685d5244935117dc19d3d1c5) super-chunk: слой-мажорный обход промпта, эксперты слоя стейджатся один раз - [`b019e83`](https://github.com/Niko1221/Strata/commit/b019e833191be852edec29b51fb395d884ee0d52) super-chunk: фиксы ревизии — stream_base только при активном потоке, cap N и лог - [`d721ed3`](https://github.com/Niko1221/Strata/commit/d721ed30e999e4605cc5c02be1dc3567a9574be4) q36: super-chunk — residual x переносится в xsuper вместе с h (критический фикс) - [`f4324e0`](https://github.com/Niko1221/Strata/commit/f4324e03e5b45672c83629ecbcf3decc738b1caa) docs: add the super-chunk prefill notes to the PR ### 📊 Changes **3 files changed** (+342 additions, -3 deletions) <details> <summary>View changed files</summary> ➕ `docs/research/super-chunk.md` (+117 -0) ➕ `docs/research/super-chunk.ru.md` (+112 -0) 📝 `src/qwen35/q36_engine.cu` (+113 -3) </details> ### 📄 Description ## Problem and result On a hybrid placement the prompt is read chunk by chunk; every chunk walks all layers and reloads each layer's experts over PCIe. On a 96k prompt, N=1 spent 8.7 s in expert H2D copies and 14.6 s in MMQ out of 103.2 s. After the change the prefill is layer-major: a layer runs over N sub-chunks (2048 tokens each) while its experts are staged once. At 96k, KAT IQ4_XS, q4_0 KV, super N=4 against N=1: 1024.0 tok/s against 800.9 (+27.9 %), TTFT -23.5 s, slots 19 -> 17; MoE 49.5 -> 23.3 s. 64k +25 %, 128k +21 %, HauhauCS IQ4_XS +22 %. STRATA_Q36_SUPER_CHUNK=4 enables it; N=1 is the old path and is bit-identical. ## Related discussion Design, measurements and limits: docs/research/super-chunk.md (EN/RU), included in this PR. The review findings (stream_base only with an active stream, cap N <= 8, MTP accounting, the residual-x fix) are part of this PR. Related: #3976 is the layer-major walk of the src/prefill engine; the q36 native path this PR changes does not run Prefill and has no layer-major mode. Scope agreement requested (feature). ## Approach - forward_super: a layer runs over the super-chunk; per-chunk buffers keep their tmax size, xsuper/hsuper hold T*N rows. - The critical fix: forward_super wrote embeddings into xsuper but did not fill the residual x; layer() does x += mixer(h) in place, so the first sub-chunk mixed another sub-chunk's residual (garbage on any text longer than 2048, needle 0/6). Two copies around the layer (x <- xsuper[off], xsuper[off] <- x) plus the hmain update fix it; at N=1 the path is bit-identical. - The expert stream starts only when active (main_hybrid && use_mmq && lhy(l)); cap N <= 8 (32 MiB per 2048-token chunk); the price is logged at start. ## Validation **Passed** (revision f4324e03, Windows 11, CUDA 13.3, sm_86, RTX 3060 Ti 8 GiB): - N=1 against base: bit-identical (SHA and decode); 4k state dump of S/conv of all 30 GDN layers, hlast and KV: same SHA, cos 1.000000. - 96k: N=1 800.9 pp / 16.7 tg, N=4 1024.0 / 17.2 (+27.9 %), TTFT 108.9 -> 85.4 s; 64k +25 %, 128k +21 %, HauhauCS +22 %. - Decode step 1 after N=4: two N=4 runs identical (max_abs 0.0); N=1 vs N=4 differs at step 1 by max_abs 0.181-0.231 with the same argmax (different summation order, not a state defect). **Failed:** none observed. **Not run:** HIP, SYCL, Metal; models other than KAT and HauhauCS IQ4_XS; a formal unit test (the bit-exact check is a manual state dump). Draft until backends are covered. ## Limits N is capped at 8; larger N needs more VRAM for xsuper/hsuper and is not measured. A cancelled request stops at a sub-chunk boundary rather than immediately. Scope note: this is an internal prefill optimization behind `STRATA_Q36_SUPER_CHUNK` (off by default). Default behaviour is unchanged; the layer-major staging path is opt-in. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#5440
No description provided.