mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3907] [Engine] qwen35: CPU expert pool: phase counters and an opt-in warm-up of the predicted experts (--pool-warm) #4826
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#4826
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/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 experts9903b66[Engine] qwen35: a parity case for the Q4_K down experts at FF 512aab82b7[Engine] qwen35: --kv int8 for the qwen35moe engine, and --tokens-file0a2b727[Engine] qwen35: grouped-query decode attention (#3641's kernel), --kv fp16 and k8v473ba60e[Engine] qwen35: int8 decode attention reads the cache through shared memory, one pass per verify windowefb3066[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 cache022982d[Engine] qwen35: --chunked-gdn, the prompt's gated delta rule in pieces of 16 tokensa3c2dc4[Engine] qwen35: k_add_rms_q and k_moe_out in registers with a one-barrier same-order sum9017b2f[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 onpr/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 Pthe engine already predicts the next layer's experts.--pool-warm Kuses 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 0keeps 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
cmpand 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 0added; 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_phaseandrun_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_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).--pool-warmunset or 0; envSTRATA_Q36_POOL_WARM;--prefetch-copies/STRATA_Q36_PREFETCH_COPIESfor the copies, 1 as today). There is no other switch:--pool-warm 0is 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/main5c8dd32. 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 BF16ssm_alpha/ssm_betagraft (the file of #3699).Passed:
Build CUDA sm_120 and "75;120" (commands as in the level-01 PR), targets
strata pool_warm_testand 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
cmpat 4K / 14K IDENTICAL / IDENTICAL;gate_a.shagainst level 02's binary IDENTICAL / IDENTICAL.Free-running slot count unchanged: 90 of 256 (fp32, 65K), 82 (int8, 262144).
--pool-warm 3 --prefetch-copies 0with the full flag set of level 05, submitted revision9c4d5b6against the timed one (the revision before the last amend of the stack), full-logitcmp, 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
strataprocess 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 from12bd46a).$PROFILE= an expert profile saved from an agent session (not in the repository). Command:tg = decode tok/s, individual runs, then the mean; 92 experts per layer in VRAM in all arms:
--pool-warm 3 --prefetch-copies 0GPU 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:
--pool-warmwith the prefetch copies on (the docs say it loses).pool_testandexpert_multi_testskip on this CPU (no AVX-512 VNNI), so the changed pool code ran under the AVX2 paths only; no AVX-512 machine.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/Stratabranchq36-r2: these PRs' flags on, plus a few fork-only defaults), same card and server sweep, withSTRATA_Q8_PACKED=0(that file keeps its attention and DeltaNet matrices in Q8_0, and the packed copy would take 1.9 GiBfrom the expert slots): Unsloth's
Qwen3.6-35B-A3B-UD-Q4_K_XL(fromunsloth/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.