Repository navigation
perf(qwen3_5): DeltaNet state written in place, no commit copy (8-stream decode 89 -> 142 tok/s, bits unchanged; alternative to #528) - #568
Conversation
…7B is served The family had the 2B's shape as comptime constants and as constexpr lines in each kernel. The kernels are now templates whose dimensions the loader prepends as macros when it compiles them; the seven generated projection files were one body with different constants and become one, compiled once per distinct shape of the checkpoint with the row decoder's split-K and tile rules kept as code. config.zig reads the dimensions and matches them against a two-entry table, the pinned 2B and Qwen3.8-27B (hidden 5,120, 64 layers, 48 DeltaNet value heads over 16 key heads, 24 query heads over 4, a separate output head, bf16 A_log). Buffers, strides, grids and thread counts come from that geometry; two were invisible on the 2B, where hidden and both mixers' rows are all 2,048: the query buffer takes the wider of the DeltaNet and attention rows, and the attention partial kernel gets a simdgroup per query head of a group. The 2B is bit-identical to main (tf-qwen35-forward logits on 300- and 777-token fixtures), passes its 49 exactness checks and loads the same pipelines. The 27B passes the same 49 checks; against stock mlx-lm its top-1 agreement matches mlx-lm's own one-row versus chunked agreement at every length (NLL within 0.002); behind the server 120 of 120 concurrent replies equal solo and 72 of 72 solo equal plain, 36 tok/s a stream and 104-108 at eight, 16 GiB RSS. The fidelity tool falls back to the repository's docs for its third corpus now that the Python engine's left the tree. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
… by a copy kernel gdn_chain writes each segment's last-row recurrence straight into the stream's cache (state_final; each thread reads its own slice into registers before the loop, so in place is safe), so Cache.commit no longer copies 151 MB of recurrence on the host after every forward; only the 2.9 MB of conv windows stay host copies. A partial keep copies the kept row's recurrence back on the GPU (forward.keep, qwen35_state_copy, one command buffer for all streams); a whole-window keep copies nothing, since commit already left the cache at the window's last row. The same floats land in the cache, so no bits change. Qwen3.8-27B 4-bit on M5 Max, -Dcpu=apple_m1, builds alternating: bench_concurrent (code prompt, 256 tokens) aggregate tok/s at 1 / 4 / 8 streams 20.9 / 61.1 / 88.9 -> 22.8 / 81.6 / 142.1; bench_openai one stream 20.8-21.6 -> 22.4-23.1. tf-qwen35-exact 49/49 (partial keeps included), bench_concurrent --alone --serial all equal, the 5,031-token probe reply and the load-time wide-lane check unchanged.
|
Thank you, @jkuepker. Writing the DeltaNet state in place instead of copying it is a clean idea, and your eight-stream table (89 to 142 tok/s, every reply equal to its solo run) is the kind of receipt we like to see. We're closing this one because the 27B now has its own engine. 1.0.3 serves Qwen3.8-27B through a separate family (34c4424, https://github.com/ashhart/TensorFold/releases/tag/v1.0.3). A qwen3_5 checkpoint with the 27B's geometry opens that engine (zig/src/native/metal.zig), and its rounds already commit the DeltaNet state on the GPU (zig/src/families/qwen27/decode_round.zig:243-245). On top of #520 this change would give the 27B a second path through the 2B's row decoder. Part of your result is still open on our side. The 27B in 1.0.3 serves one request at a time, and your run shows the lane rounds can carry eight. We've put that on the 27B engine's list with your name on it. If you'd like to try in-place state writes or concurrent streams on the 27B family, a PR against main is welcome, and reopen this if we've misread it. |
Stacked on #520 (its two commits come first; this change is the last one). This is an alternative to #528, and the two conflict in
state.zig.What this changes
#528 found the cost: after every Qwen3.5 forward,
Cache.commitcopies about 151 MB of DeltaNet recurrence on the host (48 layers × 48 × 128 × 128 × 4 B on the 27B). #528 moves that copy onto the GPU. This change removes it:gdn_chainwrites each segment's last-row state straight into the stream's cache (a newstate_finalbuffer). Each thread reads its own slice into registers before the loop, so writing in place is safe.commitnow copies only the 2.9 MB of conv windows, andkeepafter a fully accepted window copies nothing.forward.keep,qwen35_state_copy). That is one command buffer for all streams; before, it was a second 151 MB host copy.The values are the same floats written to a different buffer, so no bits change.
Receipt
Environment: 094cbaa (Qwen3.5 family: the geometry comes from the checkpoint, and Qwen3.8-27B is served #520) + this commit; Zig 0.17.0; macOS 27.0 (26A428), Metal 32023.921; Apple M5 Max (40-core GPU, 128 GB);
TensorFold/Qwen3.8-27B-MLX-4bitrevision22d8d538154e0e5b6f8dcb1fcc74a60a0798104c; all builds-Dcpu=apple_m1 -Doptimize=ReleaseFast.Exactness:
tf-qwen35-exact: 49 forward/cache checks passed, 0 failed (forward and committed caches against one-row execution, partial keeps included).qualify.zig, which now runsforward.keep): passes with no warning.bench_concurrent.py --alone --serialat 1 / 4 / 8 streams, code and chat prompts: every reply equals its request alone (3 / 12 / 24 of each), and the alone runs equal"draft": false. The same holds for 094cbaa and Qwen3.5 family: the committed DeltaNet state is copied on the GPU (+7% one-stream, +25% eight-stream decode on the 27B) #528.Decode speed, one stream (
bench_openai.py, 256 tokens, 3 reps, temperature 0; builds alternating, two rounds; tok/s, fibonacci-raw / gpu-chat-no-think):At one stream this matches Qwen3.5 family: the committed DeltaNet state is copied on the GPU (+7% one-stream, +25% eight-stream decode on the 27B) #528 within about 1%.
Concurrent throughput (
bench_concurrent.py --levels 1,4,8, 256 tokens, server--parallel 8; aggregate tok/s, code / chat):Qwen3.5 family: the committed DeltaNet state is copied on the GPU (+7% one-stream, +25% eight-stream decode on the 27B) #528 adds two copy dispatches per DeltaNet layer per stream at the end of each step's serial encoder: 96 a stream, reading and writing about 154 MB. Here the commit adds no dispatch and no traffic. The gain at 8 streams is larger than that traffic alone accounts for; I haven't profiled the rest.
Prompt speed: not measured. The prompt path runs the same kernels and now skips one 151 MB host copy per prompt chunk.
Quality: HumanEval-40 (temperature 0, drafts on) was 40/40 for both Qwen3.5 family: the committed DeltaNet state is copied on the GPU (+7% one-stream, +25% eight-stream decode on the 27B) #528 and this change in an earlier A/B on top of perf(qwen3_5): prompt chunks on the M5 tensor units (27B 16.7K prefill 206 -> ~620 tok/s, decode bits unchanged) #563's prompt commits, with decode 51.5 vs 53.1 tok/s.
Tests run:
zig build test test-golden -Dcpu=apple_m1: 95/95 steps, 386/388 tests passed, 2 skipped.tools/zig/lean_check.py: no new findings against 094cbaa.Not run, and why: M1–M4 GPUs (no access); the kernel change is plain Metal with no fragment layouts. CUDA is unaffected (Metal-only change).
Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (bench_concurrent.py --alone --serialabove; resumed prompts not run separately, since the change does not touch the prompt cache)tf-qwen35-exactand the load-time check now run the GPU keep.)