[PR #3788] [CLOSED] [Engine] q36: offload whole expert layers to helper GPUs (peer prefill, row split, and the slot-layout + context-fit fixes) #4781

Closed
opened 2026-11-07 15:39:00 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3788
Author: @maoyufeng1985
Created: 10/23/2026
Status: ❌ Closed

Base: main ← Head: rebase-foundation


📝 Commits (10+)

  • 02d522a qwen36: whole layers' experts run on helper GPUs (--expert-cache-device1..3)
  • d404c3a qwen36: opt-in int8 KV cache (--kv fp32|int8|k8v8|k8v32|k32v8)
  • 6f205cd qwen36: int8 KV cache extends to the MTP block (--kv now applies to every state index)
  • b53ccea qwen36: per-entry helper split (the helper takes the entries it holds, not whole layers)
  • 4d1d904 plans: the post-rebase measurements (four-config parity, the warmup fix, MTP)
  • 16c9b55 plans: the warmup OOB independent review and the real bottleneck (22.6 ms/token of host wait, 56 tok/s ceiling)
  • 3287425 qwen36: STRATA_Q36_HELPER_ASYNC - the helper's wait overlaps the layer's own work
  • b9f74c0 plans: the helper-async A/B (+7%, 26.6 vs 25.1 tok/s) and the presence-based-flag pitfall
  • aed169f plans: cross-layer queue design - zero-copy off is the real win (+48%), ring design held in reserve
  • c9daa20 qwen36: one stderr line naming STRATA_REMOTE_ZEROCOPY when helpers are opened

📊 Changes

29 files changed (+7887 additions, -369 deletions)

View changed files

📝 CMakeLists.txt (+6 -2)
📝 include/strata/core/expert_cache.hpp (+16 -0)
📝 include/strata/core/remote_expert_opt.hpp (+6 -1)
📝 include/strata/core/remote_experts.hpp (+101 -25)
📝 include/strata/kernels/cpu/expert_layout.hpp (+11 -0)
📝 include/strata/kernels/iq_kernels.hpp (+7 -0)
➕ plans/2026-10-15-ornith-build-bench.md (+30 -0)
➕ plans/2026-10-15-port-multigpu-qwen35.md (+122 -0)
➕ plans/2026-10-15-pull-upstream-local-patches.md (+74 -0)
➕ plans/2026-10-17-q36-three-card-runbook.md (+993 -0)
➕ plans/2026-10-19-q36-23ms-breakthrough.md (+137 -0)
➕ plans/2026-10-19-q36-beyond-100tok-roadmap.md (+114 -0)
➕ plans/2026-10-19-q36-rendezvous-off-moe-end.md (+228 -0)
➕ plans/2026-10-20-q36-1p3h-optimal.md (+350 -0)
➕ plans/2026-10-20-q36-prefill-helper-vram.md (+442 -0)
➕ plans/2026-10-21-q36-peer-ima-root-cause.md (+519 -0)
➕ plans/2026-10-21-q36-stager-benefit-negative.md (+190 -0)
📝 src/core/expert_cache.cpp (+9 -3)
📝 src/core/remote_expert_opt.cu (+83 -32)
📝 src/core/remote_experts.cpp (+413 -146)

...and 9 more files

📄 Description

Problem

On a one-GPU-plus-host-RAM box, the q36 (Qwen3.6-35B-A3B) prompt phase was the wall:
a P100 as the primary and three P104s idle. This workstream moves whole layers' experts
onto the helper GPUs and prefill-parallelizes them, and fixes the two correctness bugs
that made the offload produce NaN instead of answers.

Result (192.168.1.98, P100 + 3×P104, no P2P): prompt prefill goes from ~156 tok/s
(peers off) to ~246–254 tok/s (row split + peers on + the host route), and decode is
unchanged (tg128 52.1–53.0). Everything is opt-in; the default path (no helper flags,
no --kv, default context) is byte-identical to the last release.

What is here (one coherent stack, 27 commits)

  • Whole layers' experts on helper GPUs (--expert-cache-device1..3), in two geometries:
    layer stripes, and the row split (STRATA_Q36_HELPER_PARALLEL=1, each helper takes
    expert % n == k of every layer and the helpers run one layer at the same time).
  • The peer prompt path: helpers prefill the layers they own while the primary runs its
    own, results back through pinned host rows (STRATA_Q36_PREFILL_PEERS=1
    • STRATA_Q36_PREFILL_PEERS_HOST=1).
  • Correctness fix 1 — the helper cache's slot layout. The MMQ prompt path addresses
    a layer's experts as w + z * expert_bytes, which only works when two consecutive
    experts of a layer sit exactly the engine's stride apart. Two separate layouts broke
    that: 256-byte alignment (a Q6_K layer's stride 2041200 becomes 2041344) and the
    row split's expert-outer ranked order (a layer's two experts end up ~40 slots apart,
    gap 76722000 instead of 2041200). The fix lays slots out with the engine's step and
    layer-major, and checks the property at startup and per layer — a cache whose slot
    geometry is not the engine's is a startup failure naming the layer, not NaN rows in
    the first answer.
  • Correctness fix 2 — context-fit. The prompt chunk is read from free VRAM and never
    looked at the context, so --max-context 512 on a big card got a 2048-token chunk and
    wrote past the KV (an illegal-memory-access instead of a refusal). The chunk is now
    clamped to the context, and a prompt that cannot fit (prompt + MTP drafts + 1 > ctx)
    refuses with a clear message, RC=2.
  • int8 KV cache extended to the MTP block; the MTP mapped chain and --mtp-calibrate N.

Validation

All measured on 192.168.1.98, model Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf.

Passed:

  • The crash command (--bench-pp 160 --bench-tg 8, row split + peers on + host route)
    runs RC=0 with no IMA and no NaN; all 40 layers finite. A six-configuration matrix
    (wide pp512 window, one helper, stripe mode, peers-off parity gen: 220) is green.
  • The MTP regression on the final binary: --mtp 2 with three helpers, tg128 51.5–52.8
    against the 52.1–53.0 measured before the slot renumber - the draft chain did not
    regress.
  • The faulting --max-context 512 command now refuses with RC=2; a prompt that fits
    the 512-cell context still runs at 79.4 tok/s; the default-context answer is unchanged.
  • The flag-off default path is byte-identical (three runs of --tokens 32 --n 1).

Not run:

  • HIP and SYCL builds - this box is CUDA-only. The change is opt-in and the default
    path is untouched, but the other backends were not compiled here.
  • The mapped-chain number under --kv int8: the engine reports the flag INERT in that
    shape (the MTP block's layer is hybrid), so it is not a measurement.

Failed: none.

Limits

Everything is opt-in behind its flag or option; a default run is unchanged. Validation
is CUDA-only. The full evidence trail, with every number and how it was measured, is in
plans/2026-10-21-q36-peer-ima-root-cause.md.

🤖 Generated with Claude Code


🔄 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/3788 **Author:** [@maoyufeng1985](https://github.com/maoyufeng1985) **Created:** 10/23/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `rebase-foundation` --- ### 📝 Commits (10+) - [`02d522a`](https://github.com/Niko1221/Strata/commit/02d522a1b572f156e0be496a53fcdc2f6161c415) qwen36: whole layers' experts run on helper GPUs (--expert-cache-device1..3) - [`d404c3a`](https://github.com/Niko1221/Strata/commit/d404c3afd70c5c51da7eccd4b3a63c3bd83bf1b1) qwen36: opt-in int8 KV cache (--kv fp32|int8|k8v8|k8v32|k32v8) - [`6f205cd`](https://github.com/Niko1221/Strata/commit/6f205cdd609551f8c665ed73c985d156576b46d4) qwen36: int8 KV cache extends to the MTP block (--kv now applies to every state index) - [`b53ccea`](https://github.com/Niko1221/Strata/commit/b53ccea59b9c677c663c14e1b75ea26421c19d5e) qwen36: per-entry helper split (the helper takes the entries it holds, not whole layers) - [`4d1d904`](https://github.com/Niko1221/Strata/commit/4d1d9040b28b7f7da9e06d05b04a3725e84a6fdc) plans: the post-rebase measurements (four-config parity, the warmup fix, MTP) - [`16c9b55`](https://github.com/Niko1221/Strata/commit/16c9b5544ac00c1c78974f8f78bc22ba95de0680) plans: the warmup OOB independent review and the real bottleneck (22.6 ms/token of host wait, 56 tok/s ceiling) - [`3287425`](https://github.com/Niko1221/Strata/commit/3287425b0ecf1128986be617b8b36143758956d2) qwen36: STRATA_Q36_HELPER_ASYNC - the helper's wait overlaps the layer's own work - [`b9f74c0`](https://github.com/Niko1221/Strata/commit/b9f74c09857ecd4d02569fa3eba65337c4bdb077) plans: the helper-async A/B (+7%, 26.6 vs 25.1 tok/s) and the presence-based-flag pitfall - [`aed169f`](https://github.com/Niko1221/Strata/commit/aed169f9afbf4c891eeb2a516a8fdd0baf04c7b5) plans: cross-layer queue design - zero-copy off is the real win (+48%), ring design held in reserve - [`c9daa20`](https://github.com/Niko1221/Strata/commit/c9daa2011b12842d0eb2a16697f153911bb67ba0) qwen36: one stderr line naming STRATA_REMOTE_ZEROCOPY when helpers are opened ### 📊 Changes **29 files changed** (+7887 additions, -369 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+6 -2) 📝 `include/strata/core/expert_cache.hpp` (+16 -0) 📝 `include/strata/core/remote_expert_opt.hpp` (+6 -1) 📝 `include/strata/core/remote_experts.hpp` (+101 -25) 📝 `include/strata/kernels/cpu/expert_layout.hpp` (+11 -0) 📝 `include/strata/kernels/iq_kernels.hpp` (+7 -0) ➕ `plans/2026-10-15-ornith-build-bench.md` (+30 -0) ➕ `plans/2026-10-15-port-multigpu-qwen35.md` (+122 -0) ➕ `plans/2026-10-15-pull-upstream-local-patches.md` (+74 -0) ➕ `plans/2026-10-17-q36-three-card-runbook.md` (+993 -0) ➕ `plans/2026-10-19-q36-23ms-breakthrough.md` (+137 -0) ➕ `plans/2026-10-19-q36-beyond-100tok-roadmap.md` (+114 -0) ➕ `plans/2026-10-19-q36-rendezvous-off-moe-end.md` (+228 -0) ➕ `plans/2026-10-20-q36-1p3h-optimal.md` (+350 -0) ➕ `plans/2026-10-20-q36-prefill-helper-vram.md` (+442 -0) ➕ `plans/2026-10-21-q36-peer-ima-root-cause.md` (+519 -0) ➕ `plans/2026-10-21-q36-stager-benefit-negative.md` (+190 -0) 📝 `src/core/expert_cache.cpp` (+9 -3) 📝 `src/core/remote_expert_opt.cu` (+83 -32) 📝 `src/core/remote_experts.cpp` (+413 -146) _...and 9 more files_ </details> ### 📄 Description ## Problem On a one-GPU-plus-host-RAM box, the q36 (Qwen3.6-35B-A3B) prompt phase was the wall: a P100 as the primary and three P104s idle. This workstream moves whole layers' experts onto the helper GPUs and prefill-parallelizes them, and fixes the two correctness bugs that made the offload produce NaN instead of answers. Result (192.168.1.98, P100 + 3×P104, no P2P): prompt prefill goes from ~156 tok/s (peers off) to ~246–254 tok/s (row split + peers on + the host route), and decode is unchanged (tg128 52.1–53.0). Everything is opt-in; the default path (no helper flags, no `--kv`, default context) is byte-identical to the last release. ## What is here (one coherent stack, 27 commits) - Whole layers' experts on helper GPUs (`--expert-cache-device1..3`), in two geometries: layer stripes, and the row split (`STRATA_Q36_HELPER_PARALLEL=1`, each helper takes `expert % n == k` of every layer and the helpers run one layer at the same time). - The peer prompt path: helpers prefill the layers they own while the primary runs its own, results back through pinned host rows (`STRATA_Q36_PREFILL_PEERS=1` + `STRATA_Q36_PREFILL_PEERS_HOST=1`). - **Correctness fix 1 — the helper cache's slot layout.** The MMQ prompt path addresses a layer's experts as `w + z * expert_bytes`, which only works when two consecutive experts of a layer sit exactly the engine's `stride` apart. Two separate layouts broke that: 256-byte alignment (a Q6_K layer's stride 2041200 becomes 2041344) and the row split's expert-outer ranked order (a layer's two experts end up ~40 slots apart, gap 76722000 instead of 2041200). The fix lays slots out with the engine's step and layer-major, and checks the property at startup and per layer — a cache whose slot geometry is not the engine's is a startup failure naming the layer, not NaN rows in the first answer. - **Correctness fix 2 — context-fit.** The prompt chunk is read from free VRAM and never looked at the context, so `--max-context 512` on a big card got a 2048-token chunk and wrote past the KV (an illegal-memory-access instead of a refusal). The chunk is now clamped to the context, and a prompt that cannot fit (prompt + MTP drafts + 1 > ctx) refuses with a clear message, RC=2. - int8 KV cache extended to the MTP block; the MTP mapped chain and `--mtp-calibrate N`. ## Validation All measured on 192.168.1.98, model `Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf`. **Passed:** - The crash command (`--bench-pp 160 --bench-tg 8`, row split + peers on + host route) runs RC=0 with no IMA and no NaN; all 40 layers finite. A six-configuration matrix (wide pp512 window, one helper, stripe mode, peers-off parity `gen: 220`) is green. - The MTP regression on the final binary: `--mtp 2` with three helpers, tg128 51.5–52.8 against the 52.1–53.0 measured before the slot renumber - the draft chain did not regress. - The faulting `--max-context 512` command now refuses with RC=2; a prompt that fits the 512-cell context still runs at 79.4 tok/s; the default-context answer is unchanged. - The flag-off default path is byte-identical (three runs of `--tokens 32 --n 1`). **Not run:** - HIP and SYCL builds - this box is CUDA-only. The change is opt-in and the default path is untouched, but the other backends were not compiled here. - The mapped-chain number under `--kv int8`: the engine reports the flag INERT in that shape (the MTP block's layer is hybrid), so it is not a measurement. **Failed:** none. ## Limits Everything is opt-in behind its flag or option; a default run is unchanged. Validation is CUDA-only. The full evidence trail, with every number and how it was measured, is in `plans/2026-10-21-q36-peer-ima-root-cause.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:39:00 +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#4781
No description provided.