mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3910] [Engine] qwen35: hybrid mode sizes the CPU half by the rows that reach it and keeps 256 MiB free (default change) #4828
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#4828
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/3910
Author: @xyehya
Created: 10/24/2026
Status: 🔄 Open
Base:
main← Head:pr/q36-09-hybrid-sizing-default📝 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
27 files changed (+6856 additions, -262 deletions)
View changed files
📝
CMakeLists.txt(+39 -0)📝
apps/host/server/run-config-check.mjs(+1 -1)📝
apps/host/tests/run-config-check.test.mjs(+5 -0)📝
docs/DETAILS.md(+7 -0)📝
docs/QWEN36.md(+269 -3)📝
include/strata/kernels/cpu/pool.hpp(+40 -1)📝
serve/server.py(+44 -5)➕
serve/test_turn_splice.py(+171 -0)➕
serve/turn_splice.py(+177 -0)📝
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(+2122 -204)➕
src/qwen35/q36_gdn.cuh(+258 -0)📝
src/qwen35/q36_kernels.cuh(+113 -4)➕
src/qwen35/q36_pattn.cuh(+297 -0)➕
src/qwen35/q36_sampling.hpp(+320 -0)...and 7 more files
📄 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 9 of 9; it builds on #3909.
Branch
pr/q36-09-hybrid-sizing-default, stacked onpr/q36-08-agent-turns.Problem and result
In the hybrid mode the placement reserves 768 MiB of free VRAM and sizes the CPU half's device buffers for a whole prompt chunk (
tmaxrows), although only--hybrid-rows(128 by default) rows can reach the CPU. Both leave room that the expert cache could use. Two changes, both default (no flag):--prefill 2048, given back to the expert slots.place_expertsitself allocates after reading the free VRAM) instead of 768 MiB.--expert-vram,--expert-slotsand the all-in-VRAM decision are not changed: an explicit--expert-vrambudget keeps exactly its old slot pool (the CPU half's buffers are counted in the slot budget only for the reserve-derived budget, where the old reserve paid for them). The branch is two commits, one per change; the first is arithmetic on the buffers' sizes, the second needs data from more than one setup.Measured on the RTX 5080 16 GB with Sage-A1.5 Q4_K_M, free-running (no
--expert-slots),--prefill 2048 --pool-workers 16 --mtp 0: hybrid experts per layer in VRAM, level 08 -> this PR: 90 -> 95 (--max-context 65536, fp32 cache) and 82 -> 87 (--max-context 262144 --kv int8 --gqa-attn). With all of level 08's flags (--max-context 262144): 92 -> 97. From the docs, measured on the tree these commits came from and not re-run on this branch: with--snapshots 2 --expert-prefetch 2, 78 -> 80 cache slots for change 1; with the opt-ins of the docs' measurement (prefetch, snapshots, lend-staging), 93 -> 97 slots for change 2, the lowest free VRAM 0.579 -> 0.297 GiB (the low-water check,STRATA_Q36_VRAM_WATCH=1, was not run on this branch).Decode speed, forced text, same day, two runs per arm, level 08 -> this PR: +1.1% at 4K (243.8 -> 246.5 tok/s) and +1.2% at 40K (219.1 -> 221.7) with all of level 08's flags; +0.5% / -0.7% with only
--kv int8 --gqa-attn; +0.9% / -0.3% with no flag at all (fp32 cache, 65K). Free-running greedy--mtp 2: +3.6% at 4K, +5.8% at 40K, but the acceptance also moves (83% -> 89%, 78.5% -> 81%), so that pair is not the same text. These are two runs on one card and a gain of about 1% in decode: they do not justify a default by themselves. The case for the change is the 5 extra resident experts per layer and the larger free-VRAM margin it uses; the question for the maintainers is below.Related discussion
No scope issue yet: this draft asks the question here (related scope discussion: #3700). The scope question for the maintainers: is a 256 MiB headroom acceptable as the default? The number comes from one card, one desktop session and the runs listed below.
Approach
STRATA_Q36_VRAM_WATCH=1(a test setting) polls the device's free VRAM every 5 ms and reports each new low-water mark and the lowest at exit; the headroom was sized from it: over a 245K prompt read plus MTP 2 decode, a 198K read with two follow-ups, lend-staging's evict and refill around 4K / 16K / 40K prompts and the first request, the low-water mark was 21 MiB under the free VRAM after placement, all of it in the warm-up. The log gets a lineVRAM left after the experts' buffers: X GiB (CPU half: N rows).STRATA_Q36_PLACE_DEBUG=1prints the placement numbers (documented indocs/QWEN36.md).Anything else that allocates VRAM after the placement (another program, the desktop, a driver) now has 256 MiB, not 768 MiB. A failure there would be a
cudaMallocerror at a later request.Validation
Revision: branch
pr/q36-09-hybrid-sizing-default(f8997ef), level 08 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), target
strataand the test tools.Slot counts above (
slots.sh:strata --native $MODEL --max-context N --prefill 2048 --pool-workers 16 --mtp 0 --tokens 1,2,3,4,5,6,7,8 --n 2 [--kv int8 --gqa-attn], the linehybrid experts: N of 256 per layer in VRAM).Fixed-slot gates (
--expert-slots 56,STRATA_Q36_FIXED_SLOTS=1) against level 01's binary andgate_a.shagainst level 02's: IDENTICAL / IDENTICAL at 4K and 14K. They are identical because the fixed slot count hides the change; the free-running slot count is the evidence.The submitted revision
f8997efagainst the timed one (the revision before the last amend of the stack), full-logitcmpwith the flags of level 09 on both sides (all of level 08's flags, fixed 56 slots, 4K and 14K): IDENTICAL / IDENTICAL (64,563,200 bytes each). The fixed slot count hides this PR's change, so this shows only that the amend of the stack did not alter the output; the slot counts are the evidence for the PR itself.--expert-vram 6 --max-context 65536gives 68 of 256 experts per layer on level 08 and on this branch (slots.sh): an explicit budget keeps its old pool (cpu_dev_bis 0 for an explicit budget).Timing (same box and day, 2026-10-23; one cold
strataprocess per run under the GPU lock; arms alternated, two runs each; the binaries are the revisions before the last amend of the stack).<08 flags>=--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-sampled q --sample-gpu --snapshots 2 --snapshot-host($PROFILEis an expert profile saved from an agent session, not in the repository). Commands,$P/$G= prompt ids and forced text of the depth:Decode tok/s (forced text), individual runs, then the mean; slots = experts per layer in VRAM, level 08 -> this PR:
--kv int8 --gqa-attnFree-running greedy
--mtp 2, all flags, tok/s and draft acceptance:Where the extra slots do not change what the CPU pool does (40K, int8 + gqa only) the decode is level, within about 1%. GPU share of the decode rows with all flags: 86.2% -> 87.4% at 4K, 88.9% -> 89.8% at 40K.
Failed: none observed.
Not run:
STRATA_Q36_VRAM_WATCH=1on this branch, and the slot counts "with the opt-ins of the docs' measurement" above on this branch.cudaMemGetInfoand a polling thread; never compiled for HIP).Limits
One card, one desktop (GNOME on Fedora). A machine with a heavier desktop or another GPU program may fail where 768 MiB did not;
STRATA_Q36_HEADROOM_MIB=768gives the old reserve back (documented indocs/QWEN36.md), and--expert-vram/--expert-slotsbypass the reserve.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.