[PR #1050] [CLOSED] prefill: STRATA_PREFILL_CPU_SHARE=auto hands a small chunk's least-routed experts to the idle CPU pool (opt-in) #2996

Closed
opened 2026-11-04 02:04:46 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1050
Author: @sergqwer
Created: 10/6/2026
Status: ❌ Closed

Base: main ← Head: pr/prefill-cpu-share


📝 Commits (10+)

  • f4e96d5 tests: gdn_rec_head also compares the PP (variant 4) and two-column (variant 5) recurrence kernels, bitwise
  • 16bc95a prefill: STRATA_HCD_EXACT=1 - the HC down projection by a WMMA kernel with hipBLASLt solution 1176/1177 k order (StaggerU included), bitwise
  • 502fcef #606: the fused SwiGLU q8_1 quantizers keep the block's scale and sum finite too
  • 64d0136 cache: preserve checkpoints when split allocation fails
  • a0d0056 prefill: fused-expert exact wins (table16 via direct selector, float4 moe_combine, LDS alias + occupancy)
  • 5f5452b serve: park_current's try covers the checkpoint split too (#752): a host OOM skips parking
  • 8b19a38 Layer split: --vram-reserve-later-mib, a separate reserve for the later cards
  • ea83d0d Resident RAM mode with a layer split
  • d2d981f setup: the low-RAM mode's resident variant on several GPUs (#642)
  • cd62e5e serve: a split's stage-0 GPU profile line keeps its text (#848); later stages say which stage

📊 Changes

3 files changed (+196 additions, -4 deletions)

View changed files

📝 include/strata/prefill/prefill.hpp (+12 -0)
📝 src/prefill/prefill.cpp (+178 -2)
📝 src/program/generate.cpp (+6 -2)

📄 Description

A chunk below stream_all_min() (1,024 tokens) streams every routed expert outside VRAM over PCIe. An agent's tool result, a test's output and a short follow-up are all such chunks. Meanwhile the decode CPU pool sits idle, and the arena holds the same experts in RAM.

This adds an opt-in, STRATA_PREFILL_CPU_SHARE=auto|x. Unset (the default), no expert moves and the output is byte-identical to v0.1.39.

What it does

  • The CPU's experts. The pool takes the non-resident experts routed by at most MAXT of the chunk's tokens, fewest first. It runs them on a thread while the GPU streams and runs the rest.
  • Their rows. The CPU's unweighted rows go to Dm's tail, as a peer GPU's do (the same mechanism as --peer-device), and the combine weights them as any other row.
  • auto: the share is measured. Each layer times the CPU thread per expert, and the GPU's expert work per streamed expert. The GPU side uses CUDA events around its expert work, read after the next layer's routing sync, because the host reaches the combine long before the GPU does; timing the host instead gave a wrong share. The next layers hand the CPU g / (c + g) of the streamed experts, the point where both sides end together. A small CPU therefore takes a small share and does not make the prompt slower. x fixes a share.
  • Activations. Q2_0 layers take the pool's Q2_0 kernels' activations (ActQ, as decode's), and i-quant layers take the native vec_dot type.
  • Scope. Serve without batch slots, and generate; one GPU.

Measured

RTX 5090 + Ryzen 9 9950X3D, generate, one chunk, ms (off / auto):

model 600 tokens 250 tokens
UD-Q4_K_XL (every expert in RAM) 1,548 / 1,369, 1,528 / 1,296 (share 0.65)
Q2_0 472 / 445, 491 / 448 (0.90)
IQ2_XS 493 / 481, 502 / 460, 527 / 529 (0.83-0.86) 424 / 355, 402 / 382, 379 / 367
IQ2_XS, 2 AVX2 pool workers (emulated) 512 / 487 (0.49)
  • Where it helps most. The gain grows with the experts' size. UD-Q4_K_XL's larger experts make a small chunk PCIe-bound. Q2_0's and IQ2_XS's ~1.2 MB experts mostly do not, so they move less.
  • Accuracy. The CPU's rows are not bit-identical to the GPU's (another activation format), but they are as accurate.
    • IQ2_XS, first-token KL to STRATA_PREFILL_MMQ=0: 0.0053 off, 0.0080 auto.
    • UD-Q4_K_XL, KL between off and auto: 0.006.
    • On a fork with larger NVFP4 experts, layer 0's expert rows were 1.086% from the FP16 path on the CPU against 1.087% for the GPU's MMQ rows.
  • Identity. Off, the logits and the 32 greedy tokens equal v0.1.39 on IQ2_XS at 600 and 2,100 tokens (fixed cache).
  • Not changed. stream_all_min() stays 1,024. On the fork with NVFP4's 2.76 MB experts the routed-only walk paid up to 4,096 tokens, but on Q2_0 it lost against streaming every expert, so it stays out of this PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio


🔄 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/1050 **Author:** [@sergqwer](https://github.com/sergqwer) **Created:** 10/6/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/prefill-cpu-share` --- ### 📝 Commits (10+) - [`f4e96d5`](https://github.com/Niko1221/Strata/commit/f4e96d55b6f13622bae6b3ded2f81ca16cbd78f6) tests: gdn_rec_head also compares the PP (variant 4) and two-column (variant 5) recurrence kernels, bitwise - [`16bc95a`](https://github.com/Niko1221/Strata/commit/16bc95ab3e5293a6dd557ad0ec7e2a5eef23640a) prefill: STRATA_HCD_EXACT=1 - the HC down projection by a WMMA kernel with hipBLASLt solution 1176/1177 k order (StaggerU included), bitwise - [`502fcef`](https://github.com/Niko1221/Strata/commit/502fcef6ff29325427ecfb5409b242ac7bea18e1) #606: the fused SwiGLU q8_1 quantizers keep the block's scale and sum finite too - [`64d0136`](https://github.com/Niko1221/Strata/commit/64d01362bee3aa109fb340d9b4144a62d9192522) cache: preserve checkpoints when split allocation fails - [`a0d0056`](https://github.com/Niko1221/Strata/commit/a0d00560fdb3bd728001cac756e223b12e3a09e9) prefill: fused-expert exact wins (table16 via direct selector, float4 moe_combine, LDS alias + occupancy) - [`5f5452b`](https://github.com/Niko1221/Strata/commit/5f5452bec6fabe7c76b44af2397b29daac95feb4) serve: park_current's try covers the checkpoint split too (#752): a host OOM skips parking - [`8b19a38`](https://github.com/Niko1221/Strata/commit/8b19a38a57a80ee9c2bd03d677d8b55fc961d34b) Layer split: --vram-reserve-later-mib, a separate reserve for the later cards - [`ea83d0d`](https://github.com/Niko1221/Strata/commit/ea83d0dc5ef3fd481c53ee6bd99dd8016e10ce78) Resident RAM mode with a layer split - [`d2d981f`](https://github.com/Niko1221/Strata/commit/d2d981f5b2841cfcefcc88872730785b9d23bd78) setup: the low-RAM mode's resident variant on several GPUs (#642) - [`cd62e5e`](https://github.com/Niko1221/Strata/commit/cd62e5e07f5efa6be42a8ccfbbc82b78f6abfe93) serve: a split's stage-0 GPU profile line keeps its text (#848); later stages say which stage ### 📊 Changes **3 files changed** (+196 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/prefill/prefill.hpp` (+12 -0) 📝 `src/prefill/prefill.cpp` (+178 -2) 📝 `src/program/generate.cpp` (+6 -2) </details> ### 📄 Description A chunk below `stream_all_min()` (1,024 tokens) streams every routed expert outside VRAM over PCIe. An agent's tool result, a test's output and a short follow-up are all such chunks. Meanwhile the decode CPU pool sits idle, and the arena holds the same experts in RAM. This adds an opt-in, `STRATA_PREFILL_CPU_SHARE=auto|x`. Unset (the default), no expert moves and the output is byte-identical to v0.1.39. ### What it does - **The CPU's experts.** The pool takes the non-resident experts routed by at most `MAXT` of the chunk's tokens, fewest first. It runs them on a thread while the GPU streams and runs the rest. - **Their rows.** The CPU's unweighted rows go to `Dm`'s tail, as a peer GPU's do (the same mechanism as `--peer-device`), and the combine weights them as any other row. - **`auto`: the share is measured.** Each layer times the CPU thread per expert, and the GPU's expert work per streamed expert. The GPU side uses CUDA events around its expert work, read after the next layer's routing sync, because the host reaches the combine long before the GPU does; timing the host instead gave a wrong share. The next layers hand the CPU `g / (c + g)` of the streamed experts, the point where both sides end together. A small CPU therefore takes a small share and does not make the prompt slower. `x` fixes a share. - **Activations.** Q2_0 layers take the pool's Q2_0 kernels' activations (`ActQ`, as decode's), and i-quant layers take the native `vec_dot` type. - **Scope.** Serve without batch slots, and generate; one GPU. ### Measured RTX 5090 + Ryzen 9 9950X3D, generate, one chunk, ms (off / auto): | model | 600 tokens | 250 tokens | |---|---|---| | UD-Q4_K_XL (every expert in RAM) | 1,548 / 1,369, 1,528 / 1,296 (share 0.65) | | | Q2_0 | 472 / 445, 491 / 448 (0.90) | | | IQ2_XS | 493 / 481, 502 / 460, 527 / 529 (0.83-0.86) | 424 / 355, 402 / 382, 379 / 367 | | IQ2_XS, 2 AVX2 pool workers (emulated) | 512 / 487 (0.49) | | - **Where it helps most.** The gain grows with the experts' size. UD-Q4_K_XL's larger experts make a small chunk PCIe-bound. Q2_0's and IQ2_XS's ~1.2 MB experts mostly do not, so they move less. - **Accuracy.** The CPU's rows are not bit-identical to the GPU's (another activation format), but they are as accurate. - IQ2_XS, first-token KL to `STRATA_PREFILL_MMQ=0`: 0.0053 off, 0.0080 auto. - UD-Q4_K_XL, KL between off and auto: 0.006. - On a fork with larger NVFP4 experts, layer 0's expert rows were 1.086% from the FP16 path on the CPU against 1.087% for the GPU's MMQ rows. - **Identity.** Off, the logits and the 32 greedy tokens equal v0.1.39 on IQ2_XS at 600 and 2,100 tokens (fixed cache). - **Not changed.** `stream_all_min()` stays 1,024. On the fork with NVFP4's 2.76 MB experts the routed-only walk paid up to 4,096 tokens, but on Q2_0 it lost against streaming every expert, so it stays out of this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:04:46 +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#2996
No description provided.