mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3909] [Engine] qwen35: agent turns continue from cached state (--snapshots, --snapshot-host, splice_turns) #4827
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#4827
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/3909
Author: @xyehya
Created: 10/24/2026
Status: 🔄 Open
Base:
main← Head:pr/q36-08-agent-turns📝 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 (+6772 additions, -257 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(+252 -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(+2055 -199)➕
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 8 of 9; it builds on #3908.
Branch
pr/q36-08-agent-turns, stacked onpr/q36-07-mtp-sampled.Problem and result
The engine continues a conversation only when the new prompt starts with every token it holds (the DeltaNet state cannot step back). An agent's reply comes back as text and is encoded again; about once in 8,000 sampled tokens the model wrote a piece of text in other tokens than the tokenizer's own split, and the whole conversation is read again: 80-105K tokens, 30-45 s in the hybrid mode on an RTX 5080 with DDR5-6400 dual channel (two long agent sessions, a Qwen3.6-35B-A3B fine-tune). Three opt-ins. The server half (
splice_turns, Python) and the engine half (--snapshots,--snapshot-host, C++) are independent: they share the problem, not code, so they can be opened as two PRs; the branch has them as two commits (snapshots + splicing, then--snapshot-host):"splice_turns": true | "parsed"instrata-<model>.json(orSTRATA_SPLICE_TURNS=1): a reply that comes back as the same text (parsed: the same reasoning, answer and calls) is sent as the ids the model wrote. A reply that holds a control token the model wrote is never spliced.--snapshots K(--snapshot-min N): K copies of a session's recurrent state, taken after long prompt reads; a prompt that parts from the held tokens after one restores it and reads only the rest.--snapshot-host: the snapshots in pinned host memory (62.8 MiB each leave VRAM, which the expert slots get).Result on an RTX 5080 16 GB (same day,
--max-context 262144, serve protocol, level 07 and level 08 with the flags off against level 08 with--snapshots 2 --snapshot-host; runs in Validation): the re-read after a re-encoded reply goes from a full re-read to a restore: an 88K-token conversation 19.2 s (all 88,064 tokens read) -> 0.28 s (87,700 reused, 364 read); a 40K one 6.71 s -> 0.26 s (40,000 reused, 364 read). Fresh reads (19.15 to 19.22 s at 87,700 tokens) and decode (243.9 against 243.0 tok/s at 4K, 220.2 against 220.2 at 40K) are unchanged.splice_turnsis Python and was not exercised in the timing pass.Related discussion
none yet. Not related to a filed issue that I found.
Approach
Everything is off by default.
serve/turn_splice.pykeeps, per recent conversation, the prompt the server sent and the ids generated after it, and splices only after an engine run of one pass (a wrap-up, tool-call opening or recovery pass reads another prompt).encode_promptis split in two so the rendered text is available; with the option off the same code runs.STRATA_REUSE_DIAG=1makes the engine and the server say where a prompt parts from the held tokens; it logs conversation content (a few tokens and the text there), so it is off by default and documented as such.docs/QWEN36.mdanddocs/DETAILS.mddescribe the options.Validation
Revision: branch
pr/q36-08-agent-turns(44ae57c), level 07 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 earlier test tools.python3 -m unittest serve.test_turn_splice: 8 tests OK (run on the level-09 tree, which has the same Python files).splice_turnsis a known key of the app's run-config check (apps/host/server/run-config-check.mjs, with a case inapps/host/tests/run-config-check.test.mjs); checked by loading the module and callingcheckRunConfig; the node test file itself was not run (itsesbuilddependency is not installed here).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
44ae57cagainst the timed one (the revision before the last amend of the stack), full-logitcmpwith the flags of level 08 on both sides (--snapshots 2 --snapshot-hoston top of level 07's, fixed 56 slots, 4K and 14K): IDENTICAL / IDENTICAL (64,563,200 bytes each), so the timings hold for the submitted revision.Timing (same box and day, 2026-10-23; one cold engine per run under the GPU lock; the binaries are the revisions before the last amend of the stack;
$PROFILEis an expert profile saved from an agent session, not in the repository).<07 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. The CLI cannot send a second prompt, so the re-read goes through--serve:BASE is 40,000 (prompt of 40,960 ids) or 87,700 (prompt of 90,112 ids). The number kept is the engine's own line
prompt N tokens = R reused + W read in MS ms. Per run: reused + read tokens, engine read ms:--snapshots 2 --snapshot-hostDecode (CLI, forced 256 tokens,
--mtp 0, same flags as above, with--tokens-file $P --n 256 --force "$G"), tok/s, individual runs, then the mean. Experts per layer in VRAM: 92 for all but the--snapshots 2row, which holds the two 62.8 MiB snapshots in VRAM and has 90:--snapshots 2 --snapshot-host--snapshots 2(snapshots in VRAM, 90 slots)The last row against the one above it is two runs against four, inside the noise. A host snapshot takes 1.6 ms to the host and 1.2 ms back (Limits).
Failed: none observed.
Not run:
STRATA_Q36_SNAPSHOT_TEST(a restore is bit-exact against the same split read) andtools/qwen35/q36_snapshot_check.pyon this branch.serve/test_server.pyand the rest of the Python suite (onlyserve.test_turn_spliceran).tools/reuse_replay.pyon a recorded session;splice_turnsin the timing pass.FU8_ORDER=control-first): the third request above is a second restore, not a plain reuse.splice_turnsagainst a real agent client on this branch;--batchslots with snapshots; pictures (splicing is skipped for requests with images).cudaMemcpyDefaultis used for the host snapshots; never compiled for HIP).Limits
STRATA_REUSE_DIAG=1logs conversation content; it is off by default and the docs say so where it is described.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.