mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3906] [Engine] qwen35: hybrid mode: expert placement opt-ins, --async-swaps and --lend-staging #4824
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#4824
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/3906
Author: @xyehya
Created: 10/24/2026
Status: 🔄 Open
Base:
main← Head:pr/q36-05-placement-vram📝 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
13 files changed (+4064 additions, -132 deletions)
View changed files
📝
CMakeLists.txt(+29 -0)📝
docs/QWEN36.md(+181 -3)📝
setup.py(+2 -2)📝
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(+1345 -118)➕
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 5 of 9; it builds on #3905.
Branch
pr/q36-05-placement-vram, stacked onpr/q36-04-bit-identical.Problem and result
In the hybrid mode (the experts do not all fit in VRAM) three things leave GPU time or VRAM unused. All are opt-in flags; with none of them the engine runs as before. The three groups are independent of each other (each has its own code path; the only shared edit is that
--lend-stagingadds two trailing arguments with defaults to three grouping kernels), so they can be opened as three PRs if review prefers; they are in one branch of three commits.--expert-profile F,--expert-profile-save F,--decode-swaps N,--hybrid-zero-copy,--expert-prefetch P): start the slots from a profile and save what a run learned; set the swap rate; hand routing and CPU rows over through mapped pinned memory; fill P slots per layer ahead from the next layer's router.--async-swaps/--async-after-prompt: slot swaps off the engine stream. The synchronous swap cost 20.8 ms per 256 decode tokens at 4K (0.08 ms a token) and 40 to 45 ms after every prompt read.--lend-staging: the two prompt-staging buffers (0.97 GiB) hold 13 more expert slots per layer while decoding.Result on an RTX 5080 16 GB (same day,
--max-context 262144, level 04 with its flags against this level; runs in Validation):--expert-profile,--expert-prefetch 2,--hybrid-zero-copy,--decode-swaps 64,--async-swaps,--lend-staging): decode +17.3% at 4K (195.6 -> 229.4 tok/s) and +13.0% at 40K (186.2 -> 210.5); prompt read at 40K +1.1% (5,970 -> 6,033), with 92 experts per layer in VRAM instead of 94. Flags off, this level decodes like level 04 (195.8 / 186.0).--expert-profile+9.2% / +8.7%; profile with--expert-prefetch 2+10.9% / +9.8%;--hybrid-zero-copy+4.6% / +4.7%;--decode-swaps 64+0.6% / +2.9%;--async-swaps-0.2% / -0.2%;--lend-stagingalone -3.7% / -5.0%. Inside the full set--lend-stagingis worth about +3% (the set without it: -3.0% at 4K, -3.1% at 40K). The parts do not add up, so read the flags as a group.--expert-prefetch(with copies),--async-swapsand--lend-stagingare timing-dependent: their output is not reproducible run to run.Related discussion
none yet. The profile flags use the main path's names and file format (
src/core/expert_cache.cpp, unchanged).--expert-prefetchis not reproducible run to run (a copy is used only once it has landed, so the output depends on timing);--async-swapsis the same. The PR text says so per flag.Approach
Each flag has its own code path and a line in the usage text and
docs/QWEN36.md(including the test settingsSTRATA_Q36_PF_CHECK,_PF_GEN_START,_STAGE_TAIL_CHECK,_AFTER_SWAPS_PER_KTOK,_LEND_SETTLE,_LEND_PRIOR,_ASYNC_SWAPS). The lent slots are a third slot class after the cache and prefetch slots, with their own base pointer:k_group_small,k_route_groupandk_group_hytake it as two trailing arguments whose defaults leave every other path as it was. The async path moves a new expert into the host and device tables only when its batch's event is done, checked at the start of the next forward, so no slot is read before its bytes arrived. The exit report getsrebalance:,lent slots:,async swaps:andtable check:lines.Validation
Revision: branch
pr/q36-05-placement-vram(e301d0c), level 04 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:
strataand the parity tools.cmpat 4K / 14K IDENTICAL / IDENTICAL;gate_a.shagainst level 02's binary: IDENTICAL / IDENTICAL.--expert-slots 56, no FIXED_SLOTS,--kv int8 --gqa-attn --mtp 0): logitscmpof level 04's binary against this branch's, flags off, 4K / 14K: IDENTICAL / IDENTICAL; level 04's binary against itself (is a free-running run reproducible): IDENTICAL / IDENTICAL.Timing (same box and day, 2026-10-23; one cold
strataprocess per run under the GPU lock; arms alternated, two runs each, four for the full set; level 04 built from the revision before its last amend, this level from12bd46a, the revision before the last amend of the stack).$PROFILE= an expert profile saved from an agent session (--expert-profile-save; not in the repository). Common arguments:--native $MODEL --max-context 262144 --prefill auto --pool-workers 16 --kv int8 --gqa-attn --fused-prompt-attn --chunked-gdn --side-stream --split-stage-copy, then the arm's flags, then--mtp 0 --tokens-file $P --n 256 --force "$G"(tg) or--n 1(pp):tg = decode tok/s, individual runs, then the mean; the change is against level 04 with the common flags:
--expert-profile--expert-profile --expert-prefetch 2--hybrid-zero-copy--decode-swaps 64--async-swaps--lend-staging--lend-stagingPrompt read at 40,960 tokens (pp tok/s): level 04 5967.8 / 5971.2 = 5969.5; full set 6042.2 / 6029.6 / 6037.8 / 6022.5 = 6033.0 (+1.1%); full set minus
--lend-staging6027.9 / 6014.7 = 6021.3 (+0.9%). GPU share of decode rows: 74.7% (level 04) -> 81.8% (profile alone) -> 90.8% (full set).The timed binaries are the revision before stack-4. Full-logit
cmpof the submitted revisione301d0cagainst the timed one, with the full set of this level's flags on both sides (fixed 56 slots, 4K and 14K): DIFFERENT, and so is the same binary against itself with the same flags (control: mean KL 6.88e-3 / 5.16e-3 at 4K / 14K, top-1 62/65 and 58/65, no step above 0.1; submitted against timed: 5.22e-3 / 5.08e-3, top-1 63/65 and 60/65). The set's output varies from run to run, so the equality of the two revisions was not shown bycmp; nothing in the difference points at the revision. The control with--prefetch-copies 0(deterministic prefetch) could not run: that flag arrives in the next PR.Failed: none observed.
Not run:
--async-after-promptalone,STRATA_Q36_PF_CHECK=1runs; a repeat-run spread of the timing-dependent flags beyond the runs above.cmpof the submitted revision against the timed one with deterministic flags only (see the control above).STRATA_Q36_FIXED_SLOTS=1, which turns off the slot rebalancing this PR restructures; the free-running smoke above is the only check of the rebalancing, and it is a logits compare, not a timing.Limits
--expert-prefetch,--async-swapsand--async-after-promptare timing-dependent (not reproducible run to run); the others are deterministic.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.