[PR #3907] [Engine] qwen35: CPU expert pool: phase counters and an opt-in warm-up of the predicted experts (--pool-warm) #4826

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3907
Author: @xyehya
Created: 10/24/2026
Status: 🔄 Open

Base: main ← Head: pr/q36-06-pool-warm


📝 Commits (10+)

  • 1883224 [Engine] qwen35: accept Q4_K down-projection experts
  • 9903b66 [Engine] qwen35: a parity case for the Q4_K down experts at FF 512
  • aab82b7 [Engine] qwen35: --kv int8 for the qwen35moe engine, and --tokens-file
  • 0a2b727 [Engine] qwen35: grouped-query decode attention (#3641's kernel), --kv fp16 and k8v4
  • 73ba60e [Engine] qwen35: int8 decode attention reads the cache through shared memory, one pass per verify window
  • efb3066 [Engine] qwen35: --attn-mma, decode attention on tensor cores for the int8 cache (not bit-identical)
  • 6e21c89 [Engine] qwen35: --fused-prompt-attn, the prompt attention in one tensor-core kernel from the int8 cache
  • 022982d [Engine] qwen35: --chunked-gdn, the prompt's gated delta rule in pieces of 16 tokens
  • a3c2dc4 [Engine] qwen35: k_add_rms_q and k_moe_out in registers with a one-barrier same-order sum
  • 9017b2f [Engine] qwen35: --side-stream: z, alpha / beta (and the attention k, v) on a stream beside the first matrix

📊 Changes

16 files changed (+4460 additions, -171 deletions)

View changed files

📝 CMakeLists.txt (+33 -0)
📝 docs/QWEN36.md (+196 -3)
📝 include/strata/kernels/cpu/pool.hpp (+40 -1)
📝 setup.py (+2 -2)
📝 src/kernels/cpu/pool.cpp (+170 -37)
➕ src/kernels/cpu/pool_warm_test.cpp (+88 -0)
📝 src/kernels/cuda/iq_kernels.cu (+3 -3)
📝 src/kernels/native_expert_parity.cpp (+7 -2)
➕ src/qwen35/q36_attn.cuh (+890 -0)
📝 src/qwen35/q36_engine.cu (+1424 -119)
➕ src/qwen35/q36_gdn.cuh (+258 -0)
📝 src/qwen35/q36_kernels.cuh (+113 -4)
➕ src/qwen35/q36_pattn.cuh (+297 -0)
➕ tools/qwen35/q36_attn_parity.cu (+500 -0)
➕ tools/qwen35/q36_gdn_parity.cu (+199 -0)
➕ tools/qwen35/q36_pattn_parity.cu (+240 -0)

📄 Description

Series (each stacked on the one before; review in order): #3699 → #3903 → #3904 → #3905 → #3906 → #3907 → #3908 → #3909 → #3910. Scope discussion: #3700. This is 6 of 9; it builds on #3906.

Branch pr/q36-06-pool-warm, stacked on pr/q36-05-placement-vram.

Problem and result

In the hybrid mode the CPU pool computes the experts that have no VRAM slot, and its parked workers are idle between layers. With --expert-prefetch P the engine already predicts the next layer's experts. --pool-warm K uses the idle time: the K best predicted experts that have no slot and no copy are posted to the pool, its parked workers load their row slice into their own caches, and when the layer's call comes a warmed expert's rows go to the worker that loaded them. A warm call of one expert takes about 9 us instead of 24. --prefetch-copies 0 keeps the lookahead and drops the PCIe copies, which compete with the warm-up for the same RAM; it is meant to be used together (--expert-prefetch 2 --prefetch-copies 0 --pool-warm 3).
The dots are the same single-token dots whoever computes them, so the logits are bitwise the same. The PR also adds phase counters to the hybrid exit report (a second pool: line); logging only.

Draft until a Flash-Next default-path cmp and timing exist (see below).

Result on an RTX 5080 16 GB (same day, --max-context 262144, level 05 with its full flag set against this level with --pool-warm 3 --prefetch-copies 0 added; runs in Validation): decode +6.4% at 4K (229.2 -> 244.0 tok/s) and +4.6% at 40K (210.5 -> 220.1). GPU share of the decode rows falls (90.8% -> 86.2% at 4K) and CPU entries rise (7.5k -> 11.3k), so the gain does not come from more GPU work. The two flags were not measured separately. Flags off, this level decodes like level 05 (229.4 / 209.7). 16K was not measured.

none yet. This PR touches code Flash-Next also runs (src/kernels/cpu/pool.cpp, include/strata/kernels/cpu/pool.hpp): the pool's worker loop, drain, run_phase and run_split_multi_native. With the flags off the paths are the old ones, plus four clock reads per phase, accumulated into counters, and a flag test in the park loop; the row code was moved into one function (native_rows) without change. I have no Flash-Next measurement yet; this stays a draft until I have one.

Approach

  • Warm set: a seqlock (warm_seq_ odd while the host writes it); a worker that sees the sequence change loads its slice in 8 KB chunks and stops when a batch is published or a newer set arrives. A set counts as static only when every worker finished loading that set. Needs pinned workers and no NUMA split (else off, with a message).
  • Off by default (--pool-warm unset or 0; env STRATA_Q36_POOL_WARM; --prefetch-copies / STRATA_Q36_PREFETCH_COPIES for the copies, 1 as today). There is no other switch: --pool-warm 0 is off.
  • pool_warm_test: 400 random calls with warm sets that are subsets, disjoint, complete, posted without waiting and posted with none, at six worker counts including ones that do not divide the row counts; compared bitwise against the same calls without a warm set. It returns 77 when the pool cannot warm on the machine (unpinned, NUMA split, one worker).

Validation

Revision: branch pr/q36-06-pool-warm (9c4d5b6), level 05 below it, origin/main 5c8dd32. Environment: Fedora 44 (Linux 7.2.11), CUDA 13.4.92 with g++-15 as host compiler, RTX 5080 16 GB (driver 615.78.08), Core Ultra 9 285K, 61 GB DDR5 (6400 MT/s configured), Sage-A1.5 Q4_K_M with the BF16 ssm_alpha/ssm_beta graft (the file of #3699).

Passed:

  • Build CUDA sm_120 and "75;120" (commands as in the level-01 PR), targets strata pool_warm_test and the parity tools.

  • pool_warm_test: 400 runs, 0 mismatches; the other CPU/GPU test binaries of the lower levels pass.

  • Default path against level 01's binary, flags off, fixed 56 slots: logits cmp at 4K / 14K IDENTICAL / IDENTICAL; gate_a.sh against level 02's binary IDENTICAL / IDENTICAL.

  • Free-running slot count unchanged: 90 of 256 (fp32, 65K), 82 (int8, 262144).

  • --pool-warm 3 --prefetch-copies 0 with the full flag set of level 05, submitted revision 9c4d5b6 against the timed one (the revision before the last amend of the stack), full-logit cmp, fixed 56 slots, 4K and 14K, the flags on both sides: IDENTICAL / IDENTICAL (64,563,200 bytes each). The same flags are deterministic here because the prefetch copies are off.

Timing (same box and day, 2026-10-23; one cold strata process per run under the GPU lock, arms alternated, two runs each; both binaries built from the revisions before the last amend of the stack, level 05 from 12bd46a). $PROFILE = an expert profile saved from an agent session (not in the repository). Command:

strata --native $MODEL --max-context 262144 --prefill auto --pool-workers 16 --kv int8 --gqa-attn --fused-prompt-attn --chunked-gdn --side-stream --split-stage-copy --expert-profile $PROFILE --expert-prefetch 2 --hybrid-zero-copy --decode-swaps 64 --async-swaps --lend-staging [--pool-warm 3 --prefetch-copies 0] --mtp 0 --tokens-file $P --n 256 --force "$G"

tg = decode tok/s, individual runs, then the mean; 92 experts per layer in VRAM in all arms:

arm tg 4,096 tg 40,960
level 05, full set 229.1 / 229.4 = 229.2 210.4 / 210.6 = 210.5
this level, same flags (warm-up off) 229.4 / 229.4 = 229.4 (+0.1%) 210.6 / 208.8 = 209.7 (-0.4%)
this level, plus --pool-warm 3 --prefetch-copies 0 243.6 / 244.4 = 244.0 (+6.4%) 220.2 / 220.1 = 220.1 (+4.6%)

GPU share of decode rows / CPU entries: level 05 90.8% / 7,547 (4K), 92.3% / 6,338 (40K); with the warm-up 86.2% / 11,293 (4K), 88.9% / 9,111 (40K).

Failed: none observed.

Not run:

  • Decode at 16K; the two flags one at a time; --pool-warm with the prefetch copies on (the docs say it loses).
  • Flash-Next: any run with the changed pool (default path, and with the main path's expert pool): not run.
  • pool_test and expert_multi_test skip on this CPU (no AVX-512 VNNI), so the changed pool code ran under the AVX2 paths only; no AVX-512 machine.
  • Windows and macOS builds of the pool; HIP and SYCL builds.
  • ThreadSanitizer on the seqlock.

Limits

The warm-up pays only with the PCIe copies off, and copies off without it is a loss (the docs give the numbers); K above 3 was slower on this machine. Measured on one CPU and one memory configuration (DDR5 at 6400 MT/s configured, 2 channels); the effect depends on how close the pool is to the RAM bandwidth.

Not specific to Sage-A1.5

Sage-A1.5 is a fine-tune of Qwen3.6-35B-A3B with the same architecture and tensor layout, so this path runs the base model
unchanged. The before/after numbers above are Sage-A1.5's. The base model was measured once, on my fork's build of the whole series
(xyehya/Strata branch q36-r2: these PRs' flags on, plus a few fork-only defaults), same card and server sweep, with
STRATA_Q8_PACKED=0 (that file keeps its attention and DeltaNet matrices in Q8_0, and the packed copy would take 1.9 GiB
from the expert slots): Unsloth's Qwen3.6-35B-A3B-UD-Q4_K_XL (from unsloth/Qwen3.6-35B-A3B-MTP-GGUF),
262K int8 cache, decode 221 / 208 / 199 / 187 / 164 / 159 tok/s and prompt read 6,473 / 7,010 / 6,277 / 4,656 / 3,411 /
2,506 tok/s at 4K / 16K / 40K / 90K / 160K / 240K (Sage-A1.5 on the same build: decode 231 / 210 / 213 / 187 / 179 / 162).
Not measured: this PR's own before/after on the base model.

🤖 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/3907 **Author:** [@xyehya](https://github.com/xyehya) **Created:** 10/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/q36-06-pool-warm` --- ### 📝 Commits (10+) - [`1883224`](https://github.com/Niko1221/Strata/commit/1883224f75d2f2fc29aa303e750c2918385f0af4) [Engine] qwen35: accept Q4_K down-projection experts - [`9903b66`](https://github.com/Niko1221/Strata/commit/9903b6609a29b699c088f78f29810d16458d45f8) [Engine] qwen35: a parity case for the Q4_K down experts at FF 512 - [`aab82b7`](https://github.com/Niko1221/Strata/commit/aab82b73b4a3c0be261c5432dc65d455ac216155) [Engine] qwen35: --kv int8 for the qwen35moe engine, and --tokens-file - [`0a2b727`](https://github.com/Niko1221/Strata/commit/0a2b72720c69800b811f8baea30fdfb4bb164ef3) [Engine] qwen35: grouped-query decode attention (#3641's kernel), --kv fp16 and k8v4 - [`73ba60e`](https://github.com/Niko1221/Strata/commit/73ba60e899f38d6698e9d857d04b7e08a3a4b54c) [Engine] qwen35: int8 decode attention reads the cache through shared memory, one pass per verify window - [`efb3066`](https://github.com/Niko1221/Strata/commit/efb3066fc0908c060cbccf749741d848381f2124) [Engine] qwen35: --attn-mma, decode attention on tensor cores for the int8 cache (not bit-identical) - [`6e21c89`](https://github.com/Niko1221/Strata/commit/6e21c895f215690eae1ae196b428e1090fcc1db9) [Engine] qwen35: --fused-prompt-attn, the prompt attention in one tensor-core kernel from the int8 cache - [`022982d`](https://github.com/Niko1221/Strata/commit/022982df36843763f7f43978bf3259d95a3948d0) [Engine] qwen35: --chunked-gdn, the prompt's gated delta rule in pieces of 16 tokens - [`a3c2dc4`](https://github.com/Niko1221/Strata/commit/a3c2dc4c8a7f9aaec120cd0594efe9893d4b95db) [Engine] qwen35: k_add_rms_q and k_moe_out in registers with a one-barrier same-order sum - [`9017b2f`](https://github.com/Niko1221/Strata/commit/9017b2fd45cea7a63e871a21c523d1065fe455eb) [Engine] qwen35: --side-stream: z, alpha / beta (and the attention k, v) on a stream beside the first matrix ### 📊 Changes **16 files changed** (+4460 additions, -171 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+33 -0) 📝 `docs/QWEN36.md` (+196 -3) 📝 `include/strata/kernels/cpu/pool.hpp` (+40 -1) 📝 `setup.py` (+2 -2) 📝 `src/kernels/cpu/pool.cpp` (+170 -37) ➕ `src/kernels/cpu/pool_warm_test.cpp` (+88 -0) 📝 `src/kernels/cuda/iq_kernels.cu` (+3 -3) 📝 `src/kernels/native_expert_parity.cpp` (+7 -2) ➕ `src/qwen35/q36_attn.cuh` (+890 -0) 📝 `src/qwen35/q36_engine.cu` (+1424 -119) ➕ `src/qwen35/q36_gdn.cuh` (+258 -0) 📝 `src/qwen35/q36_kernels.cuh` (+113 -4) ➕ `src/qwen35/q36_pattn.cuh` (+297 -0) ➕ `tools/qwen35/q36_attn_parity.cu` (+500 -0) ➕ `tools/qwen35/q36_gdn_parity.cu` (+199 -0) ➕ `tools/qwen35/q36_pattn_parity.cu` (+240 -0) </details> ### 📄 Description Series (each stacked on the one before; review in order): #3699 → #3903 → #3904 → #3905 → #3906 → #3907 → #3908 → #3909 → #3910. Scope discussion: #3700. This is 6 of 9; it builds on #3906. Branch `pr/q36-06-pool-warm`, stacked on `pr/q36-05-placement-vram`. ## Problem and result In the hybrid mode the CPU pool computes the experts that have no VRAM slot, and its parked workers are idle between layers. With `--expert-prefetch P` the engine already predicts the next layer's experts. `--pool-warm K` uses the idle time: the K best predicted experts that have no slot and no copy are posted to the pool, its parked workers load their row slice into their own caches, and when the layer's call comes a warmed expert's rows go to the worker that loaded them. A warm call of one expert takes about 9 us instead of 24. `--prefetch-copies 0` keeps the lookahead and drops the PCIe copies, which compete with the warm-up for the same RAM; it is meant to be used together (`--expert-prefetch 2 --prefetch-copies 0 --pool-warm 3`). The dots are the same single-token dots whoever computes them, so the logits are bitwise the same. The PR also adds phase counters to the hybrid exit report (a second `pool:` line); logging only. **Draft until a Flash-Next default-path `cmp` and timing exist** (see below). Result on an RTX 5080 16 GB (same day, `--max-context 262144`, level 05 with its full flag set against this level with `--pool-warm 3 --prefetch-copies 0` added; runs in Validation): decode +6.4% at 4K (229.2 -> 244.0 tok/s) and +4.6% at 40K (210.5 -> 220.1). GPU share of the decode rows falls (90.8% -> 86.2% at 4K) and CPU entries rise (7.5k -> 11.3k), so the gain does not come from more GPU work. The two flags were not measured separately. Flags off, this level decodes like level 05 (229.4 / 209.7). 16K was not measured. ## Related discussion none yet. **This PR touches code Flash-Next also runs** (`src/kernels/cpu/pool.cpp`, `include/strata/kernels/cpu/pool.hpp`): the pool's worker loop, `drain`, `run_phase` and `run_split_multi_native`. With the flags off the paths are the old ones, plus four clock reads per phase, accumulated into counters, and a flag test in the park loop; the row code was moved into one function (`native_rows`) without change. I have no Flash-Next measurement yet; this stays a draft until I have one. ## Approach - Warm set: a seqlock (`warm_seq_` odd while the host writes it); a worker that sees the sequence change loads its slice in 8 KB chunks and stops when a batch is published or a newer set arrives. A set counts as static only when every worker finished loading that set. Needs pinned workers and no NUMA split (else off, with a message). - Off by default (`--pool-warm` unset or 0; env `STRATA_Q36_POOL_WARM`; `--prefetch-copies` / `STRATA_Q36_PREFETCH_COPIES` for the copies, 1 as today). There is no other switch: `--pool-warm 0` is off. - `pool_warm_test`: 400 random calls with warm sets that are subsets, disjoint, complete, posted without waiting and posted with none, at six worker counts including ones that do not divide the row counts; compared bitwise against the same calls without a warm set. It returns 77 when the pool cannot warm on the machine (unpinned, NUMA split, one worker). ## Validation Revision: branch `pr/q36-06-pool-warm` (9c4d5b6), level 05 below it, `origin/main` 5c8dd32. Environment: Fedora 44 (Linux 7.2.11), CUDA 13.4.92 with g++-15 as host compiler, RTX 5080 16 GB (driver 615.78.08), Core Ultra 9 285K, 61 GB DDR5 (6400 MT/s configured), Sage-A1.5 Q4_K_M with the BF16 `ssm_alpha`/`ssm_beta` graft (the file of #3699). **Passed:** - Build CUDA sm_120 and "75;120" (commands as in the level-01 PR), targets `strata pool_warm_test` and the parity tools. - `pool_warm_test`: 400 runs, 0 mismatches; the other CPU/GPU test binaries of the lower levels pass. - Default path against level 01's binary, flags off, fixed 56 slots: logits `cmp` at 4K / 14K IDENTICAL / IDENTICAL; `gate_a.sh` against level 02's binary IDENTICAL / IDENTICAL. - Free-running slot count unchanged: 90 of 256 (fp32, 65K), 82 (int8, 262144). - `--pool-warm 3 --prefetch-copies 0` with the full flag set of level 05, submitted revision `9c4d5b6` against the timed one (the revision before the last amend of the stack), full-logit `cmp`, fixed 56 slots, 4K and 14K, the flags on both sides: IDENTICAL / IDENTICAL (64,563,200 bytes each). The same flags are deterministic here because the prefetch copies are off. **Timing** (same box and day, 2026-10-23; one cold `strata` process per run under the GPU lock, arms alternated, two runs each; both binaries built from the revisions before the last amend of the stack, level 05 from `12bd46a`). `$PROFILE` = an expert profile saved from an agent session (not in the repository). Command: ``` strata --native $MODEL --max-context 262144 --prefill auto --pool-workers 16 --kv int8 --gqa-attn --fused-prompt-attn --chunked-gdn --side-stream --split-stage-copy --expert-profile $PROFILE --expert-prefetch 2 --hybrid-zero-copy --decode-swaps 64 --async-swaps --lend-staging [--pool-warm 3 --prefetch-copies 0] --mtp 0 --tokens-file $P --n 256 --force "$G" ``` tg = decode tok/s, individual runs, then the mean; 92 experts per layer in VRAM in all arms: | arm | tg 4,096 | tg 40,960 | |---|---|---| | level 05, full set | 229.1 / 229.4 = 229.2 | 210.4 / 210.6 = 210.5 | | this level, same flags (warm-up off) | 229.4 / 229.4 = 229.4 (+0.1%) | 210.6 / 208.8 = 209.7 (-0.4%) | | this level, plus `--pool-warm 3 --prefetch-copies 0` | 243.6 / 244.4 = 244.0 (+6.4%) | 220.2 / 220.1 = 220.1 (+4.6%) | GPU share of decode rows / CPU entries: level 05 90.8% / 7,547 (4K), 92.3% / 6,338 (40K); with the warm-up 86.2% / 11,293 (4K), 88.9% / 9,111 (40K). **Failed:** none observed. **Not run:** - Decode at 16K; the two flags one at a time; `--pool-warm` with the prefetch copies on (the docs say it loses). - Flash-Next: any run with the changed pool (default path, and with the main path's expert pool): not run. - `pool_test` and `expert_multi_test` skip on this CPU (no AVX-512 VNNI), so the changed pool code ran under the AVX2 paths only; no AVX-512 machine. - Windows and macOS builds of the pool; HIP and SYCL builds. - ThreadSanitizer on the seqlock. ## Limits The warm-up pays only with the PCIe copies off, and copies off without it is a loss (the docs give the numbers); K above 3 was slower on this machine. Measured on one CPU and one memory configuration (DDR5 at 6400 MT/s configured, 2 channels); the effect depends on how close the pool is to the RAM bandwidth. ## Not specific to Sage-A1.5 Sage-A1.5 is a fine-tune of Qwen3.6-35B-A3B with the same architecture and tensor layout, so this path runs the base model unchanged. The before/after numbers above are Sage-A1.5's. The base model was measured once, on my fork's build of the whole series (`xyehya/Strata` branch `q36-r2`: these PRs' flags on, plus a few fork-only defaults), same card and server sweep, with `STRATA_Q8_PACKED=0` (that file keeps its attention and DeltaNet matrices in Q8_0, and the packed copy would take 1.9 GiB from the expert slots): Unsloth's `Qwen3.6-35B-A3B-UD-Q4_K_XL` (from `unsloth/Qwen3.6-35B-A3B-MTP-GGUF`), 262K int8 cache, decode 221 / 208 / 199 / 187 / 164 / 159 tok/s and prompt read 6,473 / 7,010 / 6,277 / 4,656 / 3,411 / 2,506 tok/s at 4K / 16K / 40K / 90K / 160K / 240K (Sage-A1.5 on the same build: decode 231 / 210 / 213 / 187 / 179 / 162). Not measured: this PR's own before/after on the base model. 🤖 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>
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#4826
No description provided.