mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3908] [Engine] qwen35: MTP drafting for sampled requests (--mtp-sampled, --spec-min-p, --sample-gpu) #4825
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#4825
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/3908
Author: @xyehya
Created: 10/24/2026
Status: 🔄 Open
Base:
main← Head:pr/q36-07-mtp-sampled📝 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
19 files changed (+5869 additions, -240 deletions)
View changed files
📝
CMakeLists.txt(+39 -0)📝
docs/QWEN36.md(+225 -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(+1822 -188)➕
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)➕
src/qwen35/q36_sampling_test.cpp(+473 -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)➕
tools/qwen35/q36_spec_sampled.py(+183 -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 7 of 9; it builds on #3907.
Branch
pr/q36-07-mtp-sampled, stacked onpr/q36-06-pool-warm.Problem and result
On the Qwen3.6 engine path only a strictly greedy request drafts with the MTP block. A request with a temperature above 0 or a repeat / frequency / presence penalty decodes one token at a time even with
--mtp 2. That includes every request that names no sampling, because the server fills in the model card's sampling (#3354:drafts accepted 0 of 0, 73-88 tok/s where the same machine reaches about 150 with drafts).--mtp-sampled match | q: sampled requests draft too.matchdrafts the block's greedy pick and keeps each window row's token exactly as a plain decode step would sample it (same seed, same text as without drafts, up to a near tie in the last bits).qsamples the drafts from the block's own distribution and keeps them by the speculative-sampling rule; the text is a sample of the same distribution, not the same text.--spec-min-p P(the main path's name): end a step's drafts at the first one the block is less sure of than P.--sample-gpu: a sampled row comes to the host as a shortlist of the K highest logits (K = top_k + the ids the penalties touch, at most 160) instead of 1 MB of logits.Result on an RTX 5080 16 GB (same day,
--max-context 262144, level 06 with its flags against this level; runs in Validation). Sampled requests (temperature 0.7, top-p 0.95, top-k 20, seeds 1 to 4, 256 tokens each, through--serve), tok/s:--sample-gpualone: 232.1 -> 244.1 (+5.2%) at a 4K prompt, 210.1 -> 218.2 (+3.8%) at 40K.--mtp 2 --spec-min-p 0.5 --mtp-sampled q --sample-gpu: 282.6 (+21.8%) at 4K and 240.6 (+14.5%) at 40K, 67 to 75% of drafts accepted at 4K and 68 to 69% at 40K. The two 4K runs of this arm are 276.2 and 289.1, so it is noisier than the others (the seed changes the text and so the acceptance).--mtp 2: level 06 already drafts greedy requests (294.6 tok/s at 4K, 243.9 at 40K); this level with--spec-min-p 0.5gives 298.3 and 249.7 (+1.3% / +2.4% over level 06). Against--mtp 0that is +23% / +13%.--mtp-sampled matchwas not measured.Related discussion
matchidea behindSTRATA_Q36_MTP_SAMPLED=1, stacked on #3678). If #3773 lands first,--mtp-sampled matchshould keep its environment variable as an alias; I will rebase either way.STRATA_SPEC_PROB,--coupled-draft,DETAILS.md"Sampled drafting"): different engine; the rule here reusescore/spec_prob.hpp, andSTRATA_SPEC_MIN_TEMPis that path's variable.--draft-vocabrow) is the separate fix 07a.Approach
Flags off, the engine drafts for greedy requests only, as before. The sampler moves from
q36_engine.cutosrc/qwen35/q36_sampling.hpp(header-only) so a CPU test can check the rules without a GPU. The default sampled path is unchanged: the host's top-k keeps the comparator it had (lg[a] > lg[b]) unless--mtp-sampledor--sample-gpuis given; only then equal logits are ordered by the lower id (the shortlist kernel needs a total order, andmatchneeds the plain steps and the window rows to sort alike). The one fix that does touch the default path, a penalty for a history id outside a--draft-vocabrow that wrote past the row, is its own first commit and its own PR (07a, below). Greedy requests are untouched.q36_sampling_test(CPU):sample()against a copy of the old function on 8,000 random rows (tie rule off and on; same token, same rng state);matchgives the plain sampler's text seed for seed;matchandqgive the exact joint of four tokens against the chain (chi-square), also with--spec-min-pand over a--draft-vocabrow; three deliberately wrong rules fail as controls; the shortlist gives the whole row's chain, token and rng state (27,291 cases, ties and penalties).tools/qwen35/q36_spec_sampled.pymeasures the rules on the real model.Validation
Revision: branch
pr/q36-07-mtp-sampled(66da263), level 06 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 q36_sampling_testand the earlier test tools.q36_sampling_test: passed (GPU build tree; also built by hand withg++ -std=c++17 -Iinclude src/qwen35/q36_sampling_test.cppand run: passed).Greedy 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).
The submitted revision
66da263against the timed one (the revision before the last amend of the stack), full-logitcmpwith the flags of level 07 on both sides (--sample-gpuon top of level 06's flags, fixed 56 slots, 4K and 14K): IDENTICAL / IDENTICAL (64,563,200 bytes each). This is a greedy compare; it says the timings hold for the submitted revision, not that sampling is unchanged.Timing (same box and day, 2026-10-23; one cold
strataprocess per run under the GPU lock; CLI runs alternated, two runs each, four for level 06 with--mtp 2, level 07 and the 4K greedy rows; serve runs two each; both binaries from the revisions before the last amend of the stack).<06 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($PROFILEis an expert profile saved from an agent session, not in the repository); 92 experts per layer in VRAM in every arm. Commands:(
strata generatehas no temperature option, so the sampled rows go through--serve.) Greedy, tok/s, individual runs, then the mean; "accepted" is the engine's own draft acceptance:--mtp 0--mtp 2--mtp 2 --spec-min-p 0.5 --mtp-sampled q --sample-gpu(Changes against level 06 with
--mtp 0.) Sampled, serve protocol, tok/s over the 4 seeds of one run, two runs per arm (per-seed values in the raw results):--mtp 0--sample-gpu--mtp 2 --spec-min-p 0.5 --mtp-sampled q --sample-gpuThe first pass of the level-06
--mtp 2arm passed--spec-min-p, which level 06 does not have; it was re-run without it and only the re-run is shown.Failed: none observed.
Not run:
origin/maintext for text on the real model (card sampling, fixed seed, flags off): the logits gate is greedy and does not cover it.q36_sampling_testcoverssample()itself (above).--mtp-sampledand--sample-gpuagainstoff(q36_spec_sampled.py): the timing pass measured speed and acceptance only.--mtp-sampled match,--mtp 3and above, a 16K prompt.--batchslots with--mtp-sampled; vision.k_cand_part/k_cand_mergeare inq36_engine.cu; never compiled for HIP).Limits
qneedstop_k<= 64 and a temperature above 0 and at leastSTRATA_SPEC_MIN_TEMP; other sampled requests usematch.--sample-gpucopies the whole row for a penalty that raises a logit or when K would pass 160. Measured on one model and one card.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.