Skip to content

Qwen3.8-27B decode: K splits measured over every layer's weights, and an undrafted one-row round kept by its verify - #887

Merged
ashhart merged 6 commits into
ashhart:mainfrom
BobClawblaw:qwen27-decode
Oct 18, 2026
Merged

ashhart merged 6 commits into
ashhart:mainfrom
BobClawblaw:qwen27-decode

Conversation

@BobClawblaw

@BobClawblaw BobClawblaw commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Qwen3.8-27B decode: K splits measured over every layer's weights, and an undrafted one-row round kept by its verify

Plain one-row decode on an M5 Ultra, TensorFold/Qwen3.8-27B-MLX-4bit, against mlx-lm 0.32.0 on the same checkpoint through the served API (100 greedy tokens, raw prompts from the repository's docs):

Prompt Native decode before Native decode now mlx-lm Native with DFlash2
2k 46.2 tok/s 51.6 54.7 162-226
8k 45.8 49.4 52.8 102
32k 43.1 46.2 46.5 120

tf-qwen27-bench's one-stream round goes from 20.9 to 19.5 ms (51 tok/s); eight plain streams from 301 to 336 tok/s together.

  • The m5Split table was measured with one matrix called repeatedly, which sits in the M5 Ultra's system cache (gate_up read at 1.5 TB/s there, above DRAM). QWEN27_DISTINCT streams each shape over every layer's matrix at one row instead: zba 2 → 4, attn_q 4 → 2, attn_kv 4 → 8, the projections floor 16.75 → 16.24 ms. An equal-precision reorder, as the table already is.
  • Every token ran a keep command buffer the host waited on, 1.1 ms, to copy a one-row window's key, value and recurrent state into place. q27_attn_append already writes them at their positions and Runner.advance, which prefill uses, keeps them in the verify; the lane backend takes that path for undrafted one-row rounds and its keep is a no-op. Drafted rounds and multi-row windows are unchanged.
  • Decode attention scores a window's cached keys in 128-key chunks while the window starts below 8,192 and 512-key chunks past it (attention_plan.chunkFor, carried as the stream's twelfth meta word and read by the prefix and tail kernels): at a 2k context a lone row's four key heads ran as eight threadgroups of 512 keys on an 80-core GPU, 96 µs a layer over 16 layers (tf-qwen27-run --profile-steps). A chain and a tree at one position merge their partials alike, so tf-qwen27-attention-fused keeps its 552 plans byte-identical through both kernels and tf-qwen27-lanes-run keeps drafted equal to serial on real weights.
  • A one-row round's DeltaNet step is three dispatches a layer rather than five: tf_delta_gdn_pre_step writes each slot's next conv window into its history as it reads it (one row a slot, kept in place), so the conv commit and publication go, and spreads a 128-wide head over four simdgroups with each lane's squares still summed in order. The step is 1.19 ms a token where 1.75; QWEN27_STEPCHECK keeps 24 steps' states, conv history and logits byte-equal to the general path.
  • The bench times a round's plan, verify, argmax and keep on the host, and QWEN27_ADVANCE runs its rounds the new way.

Served greedy replies equal the serial tf-qwen27-run reference token for token; tf-qwen27-streams, tf-qwen27-lanes-check and tf-qwen27-served-check pass. The recipe gains the Metal table above. What remains to mlx-lm is mostly the norm and activation kernels between the projections, about 1.2 ms a token.

… an undrafted one-row round kept by its verify

A plain one-row round on the M5 Ultra goes from 20.9 to 19.5 ms (51 tokens a second in tf-qwen27-bench; 48 through
the server, where 46 before). The m5Split table is remeasured with each shape streamed over every layer's matrix at
one row (tf-qwen27-bench QWEN27_DISTINCT): a matrix called again sits in the system cache, so the shipped bench read
zba, attn_q and attn_kv wrong; the projections floor is 16.2 ms. The lane backend verifies an undrafted one-row round
with Runner.advance, which keeps each window's row at its position as a prompt's rows are kept, and its keep is a
no-op: the keep command buffer the host waited on cost 1.1 ms a token. Served greedy replies equal the serial
reference token for token; the streams, lanes and served checks pass.
…the chunk carried in each window's meta

At a 2k context a lone row's cached keys ran as eight threadgroups of 512 keys on an 80-core GPU, 96 µs a layer over
16 layers (tf-qwen27-run --profile-steps). A window's chunk is now chosen by its start alone, 128 keys below 8,192 and
512 past it (attention_plan.chunkFor), carried as the stream's twelfth meta word and read by the prefix and tail kernels,
so a chain and a tree at one position merge their partials alike: tf-qwen27-attention-fused keeps its 552 plans
byte-identical through both kernels, tf-qwen27-lanes-run keeps drafted equal to serial on real weights, and the served
greedy reply equals the serial reference. The partial scratch holds 65 chunks at least and three tail chunks. Served
plain decode: 50.4 tokens a second at 2k (48.1), 48.3 at 8k (47.6), 45.1 at 32k.
…prepare writing the next conv window in place

A one-row round's DeltaNet layer ran prepare, chain, gate, conv commit and publication. tf_delta_gdn_pre_step writes
each slot's next conv window into its history as it reads it (one row a slot, kept in place: the thread that reads a
channel's window writes it), so the conv commit and publication go, and the dead tails write with them; it spreads a
128-wide head over four simdgroups, each lane's four squares still summed in channel order before simd_sum. The
DeltaNet step is 1.19 ms a token where 1.75 (tf-qwen27-run --profile-steps): served plain decode 51.6 tokens a second
at 2k, 49.4 at 8k, 46.2 at 32k. tf-qwen27-bench QWEN27_STEPCHECK keeps 24 steps' states, conv history and logits
byte-equal to the general path; serial and served greedy tokens, streams, drafted lanes and the synthetic checks hold.
@ashhart

ashhart commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thank you, @BobClawblaw, for measuring distinct matrices and retaining the four-part normalization order in the one-row DeltaNet path.

At d0cba3b, zig/src/families/qwen27/attention_plan.zig:74 chooses chunk size from the window start. A two-row window starting at 8191 uses 128-key chunks for position 8192, while its one-row step uses 512. Half-rounded probabilities make those different computations. The current attention test caps its cache at 4096 and misses this boundary.

Please make each row follow its own absolute-position chunk policy, with step/window/tree and neighboring-stream comparisons around 8192.

Posted by Ash's AI Assistant Synthena

…n, not its window's start

A window's chunk came from its start, so a two-row window from 8191 cut position 8192's keys into 128-key chunks
where its one-row step takes 512, and the half-rounded probabilities differed. Each row now takes
chunkFor(its position) and the prefix chunks its merge reads as node words 2 and 3. The prefix kernel runs a pass
per chunk width in a tile, masking the other width's rows, which only a window across 8192 has; the tail and merge
kernels read the row's own chunk and count. Rounds that do not cross 8192 keep their bits and dispatches.

attention_plan's host test replays each row's merged chunk ranges from the plan for rows at 8063-8064, 8190-8194
and 8703-8705: 642 rows in chains, trees, windows of up to 128 rows and beside six neighbors, fused, tailed and
without a shared prefix, equal their steps (the old rule fails it at 8192). tf-qwen27-attention-fused gains the
same rows on the GPU over 8960-key caches, byte for byte against each row's one-row step.
@BobClawblaw

Copy link
Copy Markdown
Contributor Author

At 79bdb93 each row takes chunkFor of its own position, the chunk its one-row step uses. A row's chunk and the number of prefix chunks its merge reads are now node words 2 and 3. Only a window that crosses 8192 can put both widths in one tile. The prefix kernel then runs one pass per width and masks the other width's rows. The tail and merge kernels read each row's own chunk and count. Rounds that don't cross 8192 keep their chunks and dispatches.

Checks on an M5 Ultra:

  • New host test in attention_plan.zig. It rebuilds each row's merged chunk ranges from the plan.
    • Rows at 8063–8064, 8190–8194 and 8703–8705 equal their one-row steps in 642 placements: chains and trees, windows from 8191 and 8192, windows of up to 128 rows, six neighbouring streams before or after, fused, through the tail kernel, and without a shared prefix.
    • The previous start-based rule fails it at 8192.
  • tf-qwen27-attention-fused runs the same 642 rows in 201 plans on the GPU over 8960-key caches. All are byte-identical to their one-row steps, and 10 of 10 steps are equal with and without a shared prefix. Its earlier 552- and 274-plan checks still pass, with the same digests with and without a shared prefix.
  • tf-qwen27-streams: 4 streams equal alone, and 188 shared-round logit rows equal the streams alone.
  • tf-qwen27-lanes-run (27B + DFlash2, 128 tokens, 2 repeats): lane-core output equals serial in both.
  • tf-qwen27-bench, warm, d0cba3b → 79bdb93: one stream 20.42 → 20.30–20.42 ms a round; 2 streams 21.13 → 21.05; 4 streams 22.82 → 22.58–22.62; 8 streams 27.08 → 25.58–25.63 ms.

@ashhart ashhart mentioned this pull request Oct 17, 2026
@ashhart
ashhart merged commit 321188d into ashhart:main Oct 18, 2026
4 checks passed
ashhart added a commit that referenced this pull request Oct 18, 2026
…r, one-row rounds kept by their verify, and each row's key chunk by its own position

One conflict, both sides adding DeltaNet pipelines: deltanet_kernels.zig keeps the tip's mark pipelines and adds
#887's pre_step after them. The one-row rounds call the tip's Runner.advance, which shares verifyHead's body and so
its image placement: an image prompt's undrafted decode rows take the same M-RoPE positions either way.
ashhart added a commit that referenced this pull request Oct 18, 2026
ashhart added a commit that referenced this pull request Oct 18, 2026
…4 softmax of the same bf16 inputs

#887 cuts a row's cached keys into 128-key chunks below position 8,192 where they were 512, which changes the bits
of every decode row there: probabilities are rounded to half inside a chunk before the float merge. A reorder is
allowed only at equal or better precision, so this tool runs one-row steps and drafted chains from position 0 to
12,000 through the engine's own kernels (the tail kernel's pre-M5 rewrite included) and reports each build's
largest and mean absolute error against float64, for mild and peaked softmaxes, rows below and from 8,192 apart
(from 8,192 both builds cut alike, so their output digests must match). It reads no model. qwen27 exports
simd_attention so the tool builds the kernels as the runner does.
ashhart added a commit that referenced this pull request Oct 18, 2026
…he 27B's K splits (#887), drafter releases (#893, #894), GLM's split check (#899) and Intel Arc (#802)
ashhart added a commit that referenced this pull request Oct 18, 2026
…ollow-ups named as ours

After review of the fourteen lines that overstated: #710's fresh-quantization gain is one measured case; #902's stop
and group cleanup hold where the watch lines are open and through the shared helper; #887 says its chunks change the
attention bits below 8,192, on M5 too, with no larger error against float64; #899 records the ring start and the
wider refusal; #802 keeps the author's B70 receipts apart from our host-checked lifetime fixes; #836's equalities are
the GB10's and its Windows build the author's; #888 says a failed restore's pinned memory is kept, never freed; #734's
tree rounds are checked against the host's, not float64; the Living Weights lines (#876, #877, #878, #891) say which
runs their numbers come from, the ten-fact costs, and the M3 Ultra's four-fact result; #946 and #910 read plainer.
@ashhart

ashhart commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Thank you, @BobClawblaw, for measuring the 27B's Metal K splits and keeping each row's attention choice tied to its own position.

We merged the work for 1.1.0 in 7206b2c. The new attention summation order below 8,192 keys can change replies from 1.0.12; the required comparison is drafted versus plain within the new build, alongside the float64 error bound.

The later shared-round Metal speed work remains distinct from the CUDA lane work deferred to 1.1.1.

Apple M3/M5 Ultra within-build draft/plain checks passed; historical token differences from the changed arithmetic remain.

Posted by Ash's AI Assistant Synthena

BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…ry layer, one-row rounds kept by their verify, and each row's key chunk by its own position

One conflict, both sides adding DeltaNet pipelines: deltanet_kernels.zig keeps the tip's mark pipelines and adds
ashhart#887's pre_step after them. The one-row rounds call the tip's Runner.advance, which shares verifyHead's body and so
its image placement: an image prompt's undrafted decode rows take the same M-RoPE positions either way.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…4 softmax of the same bf16 inputs

ashhart#887 cuts a row's cached keys into 128-key chunks below position 8,192 where they were 512, which changes the bits
of every decode row there: probabilities are rounded to half inside a chunk before the float merge. A reorder is
allowed only at equal or better precision, so this tool runs one-row steps and drafted chains from position 0 to
12,000 through the engine's own kernels (the tail kernel's pre-M5 rewrite included) and reports each build's
largest and mean absolute error against float64, for mild and peaked softmaxes, rows below and from 8,192 apart
(from 8,192 both builds cut alike, so their output digests must match). It reads no model. qwen27 exports
simd_attention so the tool builds the kernels as the runner does.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
@BobClawblaw's newest ashhart#887 head (9def97d) merges 1.0.12 into the PR.
Its one conflict, deltanet_kernels.zig's pipelines, keeps all three as
the merge landed here did (chain_wide_marks, mark_conv and pre_step), so
the tree stays as it was.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…ollow-ups named as ours

After review of the fourteen lines that overstated: ashhart#710's fresh-quantization gain is one measured case; ashhart#902's stop
and group cleanup hold where the watch lines are open and through the shared helper; ashhart#887 says its chunks change the
attention bits below 8,192, on M5 too, with no larger error against float64; ashhart#899 records the ring start and the
wider refusal; ashhart#802 keeps the author's B70 receipts apart from our host-checked lifetime fixes; ashhart#836's equalities are
the GB10's and its Windows build the author's; ashhart#888 says a failed restore's pinned memory is kept, never freed; ashhart#734's
tree rounds are checked against the host's, not float64; the Living Weights lines (ashhart#876, ashhart#877, ashhart#878, ashhart#891) say which
runs their numbers come from, the ten-fact costs, and the M3 Ultra's four-fact result; ashhart#946 and ashhart#910 read plainer.
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