Skip to content

Qwen3.5 family: the committed DeltaNet state is copied on the GPU (+7% one-stream, +25% eight-stream decode on the 27B) - #528

Closed
BobClawblaw wants to merge 3 commits into
ashhart:mainfrom
BobClawblaw:qwen3_5-gpu-commit
Closed

BobClawblaw wants to merge 3 commits into
ashhart:mainfrom
BobClawblaw:qwen3_5-gpu-commit

Conversation

@BobClawblaw

Copy link
Copy Markdown
Contributor

Stacked on #520: the first two commits are that PR, the last one is this change. Review 2c53ed3 alone. Follows #527, where the tile-width A/B from the receipt on #520 led somewhere else.

What was found

tf-qwen35-bench (new, below) splits a one-row 27B step on an M5 Ultra: 25 ms on the GPU, of which 22.9 ms is the projection kernels at about 660 GB/s and 1.8 ms the other kernels, 0.2 ms of CPU encode, and about 2.3 ms of CPU work after the command buffer completes. That last part was Cache.commit: a host memcpy of every DeltaNet layer's recurrent state and conv window from the scratch snapshot into the stream's cache, 3 MiB a layer and 151 MB a stream on the 27B (18 MB on the 2B). At eight streams it ran eight times.

The tile width and split count, the lead from the receipt, are not it on this die: once the GPU clock is up, the shipped choices are within a few percent of the best cell on every one of the 27B's shapes, and the first-pass numbers that said otherwise were clock ramp after CPU-side compiles. Details on #527.

What changes

  • zig/kernels/metal/qwen3_5/layout.metal, kernels.zig: a qwen35_copy kernel, 16 bytes a thread, in the fixed layout library (23 pipelines for the 27B now, 22 before).
  • forward.zig: Encoder.commitStates dispatches it at the end of the step's encoder for each segment's last row, the same rows and offsets commit used, so the cache is written by the GPU before the command buffer completes. It stays inside the serial compute encoder: the buffers are untracked, so a blit encoder would have needed fences.
  • state.zig: Cache.commit keeps the length and the keep window only. keep (partial keeps after a tree window) still copies on the host from the snapshot, unchanged.
  • zig/tests/qwen35_bench.zig, tf-qwen35-bench: every distinct projection shape of a checkpoint at 1, 8, 16 and 32 rows under the shipped tile width and split count and their alternatives, in bursts long enough for the GPU clock, each alternative marked = or ! against the shipped kernel's bytes; then the projections-only step and the whole one-row step.
  • docs/recipes/qwen3.8-27b.md: the pipeline count, the new measurements, and where a step goes.

Checks (M5 Ultra, 256 GB, macOS 27.0.1, Zig 0.17.0, Metal Toolchain 27A266a, 27B at 22d8d538)

  • tf-qwen35-forward logits from Qwen3.5 family: the geometry comes from the checkpoint, and Qwen3.8-27B is served #520's binary (094cbaa) and this one are byte-identical on the 2B and the 27B, 300- and 777-token fixtures.
  • tf-qwen35-exact on the 27B: 49 of 49 forward and cache checks.
  • tf-qwen35-check: loads, 23 pipelines, separate head.
  • zig build test: 386 of 388, 2 skipped.
  • Server, tools/bench_concurrent.py --alone --serial, 128 tokens, sampled and greedy, old binary and new: 180 of 180 concurrent replies equal their solo runs and every solo run equals "draft": false, on both.
aggregate tok/s 1 stream 2 4 8 8 steady
#520 head 35.9-36.1 53-54 79-81 106-110 112-114
this 38.5-38.7 60-61 94-96 131-138 141-144
  • Decode, tools/bench_openai.py --tokens 64 --reps 5 --temperatures 1.0,0, A/B/A/B, two rounds each: old 35.8-36.3 tok/s, new 38.5-38.9, spreads within 0.2.
  • tf-qwen35-bench one-row step: 27.5 ms to 25.6 ms, GPU time unchanged.

What is left for the receipt's gap

On this die the projection kernels with 5,120 inputs (gate, up, the DeltaNet and attention input projections, the head) run at about 730 GB/s where mx.quantized_matmul on the same shapes reaches 900-1,030 GB/s; the long down projection is the other way round, 65 µs native against 101 µs. Those shapes carry about 60% of the step's weight bytes, so that is the next lever, and it is kernel structure (loads in flight per simdgroup), not tile width. Noted on #527.

🤖 Generated with Claude Code

BobClawblaw and others added 3 commits October 8, 2026 07:31
…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]>
…d a projection bench

Cache.commit copied each DeltaNet layer's recurrent state and conv window from
the scratch snapshot into the stream's cache with a host memcpy after the step's
command buffer completed: 3 MiB a layer, 151 MB a stream on the 27B, 2 ms of a
27.5 ms one-row step and eight times that at eight streams. The forward now
dispatches a copy kernel for the same rows at the end of its encoder, so the
cache is written by the GPU before the command buffer completes; commit keeps
the length and the keep window.

tf-qwen35-bench times every distinct projection shape of a checkpoint at 1, 8,
16 and 32 rows under the shipped tile width and split count and their
alternatives, marks which alternatives produce the same bytes, and times the
projections-only step and the whole one-row step. On an M5 Ultra the shipped
choices are within a few percent of the best cell for the 27B's shapes once the
GPU clock is up; the tile width is not the lever there (ashhart#527).

Measured on the M5 Ultra, 27B: one-row decode 36.0-36.3 to 38.5-38.9 tok/s;
eight streams 106-110 to 131-138 aggregate. The 2B and 27B forward logits are
byte-identical to the previous binary on 300- and 777-token fixtures, and
tf-qwen35-exact passes its 49 checks.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you, @BobClawblaw. Finding the 151 MB host copy behind every step, and moving it into the step's encoder with the logits byte-identical, was careful work, and tf-qwen35-bench is a good tool.

We're closing this one because the 27B now runs on its own engine in 1.0.3 (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 commit the DeltaNet state on the GPU (zig/src/families/qwen27/decode_round.zig:243-245). On top of #520 this would give the 27B a second path through the 2B's row decoder, and @jkuepker's #568 is closing for the same reason.

The part we keep is your eight-stream result. 1.0.3's 27B serves one request at a time, and your runs show the lane rounds can carry it. That's on our list for the 27B engine, credited to you. If you'd like to bring the bench or concurrent streams to that family, we'd welcome it, and reopen this if we've missed something.

@ashhart ashhart closed this Oct 10, 2026
BobClawblaw added a commit to BobClawblaw/TensorFold that referenced this pull request Oct 10, 2026
…tions floor, and shared rounds by stream count

ashhart#528's tf-qwen35-bench for the 27B engine. Each projection shape of the checkpoint is timed at 1, 8,
16 and 32 rows on the shipped split and every other split the lane kernel takes, with '=' where
the bytes equal the shipped split's; then every projection of a one-row step in one command
buffer; then shared decode rounds of 1, 2, 4 and 8 streams, one row each, verified and kept as
the lane core does, with wall and verify-GPU ms a round.
BobClawblaw added a commit to BobClawblaw/TensorFold that referenced this pull request Oct 10, 2026
…tions floor, and shared rounds by stream count

ashhart#528's tf-qwen35-bench for the 27B engine. Each projection shape of the checkpoint is timed at 1, 8,
16 and 32 rows on the shipped split and every other split the lane kernel takes, with '=' where
the bytes equal the shipped split's; then every projection of a one-row step in one command
buffer; then shared decode rounds of 1, 2, 4 and 8 streams, one row each, verified and kept as
the lane core does, with wall and verify-GPU ms a round.
BobClawblaw added a commit to BobClawblaw/TensorFold that referenced this pull request Oct 11, 2026
…tions floor, and shared rounds by stream count

ashhart#528's tf-qwen35-bench for the 27B engine. Each projection shape of the checkpoint is timed at 1, 8,
16 and 32 rows on the shipped split and every other split the lane kernel takes, with '=' where
the bytes equal the shipped split's; then every projection of a one-row step in one command
buffer; then shared decode rounds of 1, 2, 4 and 8 streams, one row each, verified and kept as
the lane core does, with wall and verify-GPU ms a round.
@BobClawblaw
BobClawblaw deleted the qwen3_5-gpu-commit branch October 15, 2026 15:21
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…tions floor, and shared rounds by stream count

ashhart#528's tf-qwen35-bench for the 27B engine. Each projection shape of the checkpoint is timed at 1, 8,
16 and 32 rows on the shipped split and every other split the lane kernel takes, with '=' where
the bytes equal the shipped split's; then every projection of a one-row step in one command
buffer; then shared decode rounds of 1, 2, 4 and 8 streams, one row each, verified and kept as
the lane core does, with wall and verify-GPU ms a round.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…tions floor, and shared rounds by stream count

ashhart#528's tf-qwen35-bench for the 27B engine. Each projection shape of the checkpoint is timed at 1, 8,
16 and 32 rows on the shipped split and every other split the lane kernel takes, with '=' where
the bytes equal the shipped split's; then every projection of a one-row step in one command
buffer; then shared decode rounds of 1, 2, 4 and 8 streams, one row each, verified and kept as
the lane core does, with wall and verify-GPU ms a round.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants