Repository navigation
qwen27 metal: drafted window rows share the decode tail attention in pairs, before M5 - #3661
Merged
Merged
Conversation
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
5 of 8 tasks
ashhart
force-pushed
the
lead/oe1-metal
branch
from
November 17, 2026 12:56
6aedede to
9f1ec75
Compare
…ntion in pairs (Q27_JOIN) Before the M5 the 27B's decode attention runs q27_attn_tail, a threadgroup a (KV head, chunk, row), and with six query heads a KV head only lines 0-5 of its 16-line tile carry the row: lines 8-15, with their own softmax state, are padding. A drafted window's rows all read the stream's keys below the window, and streams resumed from one stored prompt on shared KV pages read the same keys too, yet each row loaded and multiplied every chunk alone. Plan.pair pairs rows over the chunks wholly below the keys they hold alike, at one chunk width: a stream's rows below its window, and streams of one share group below the group's keys. The lead's threadgroup carries the rider's six heads in lines 8-13 (q27_attn_pack_b), runs the joint chunks once for both (q27_attn_tail, the rider's own threadgroup returning there), and the merges read the rider's joint partials from the lead's slot. Each line's arithmetic is the one it runs alone: line 8 + i mirrors line i's key columns, shuffles and sum order. The join is a Q27_JOIN build of the same sources (simd_attention.joined); main's pipelines compile from unchanged text and run every plan without a pair. The runner builds the join before the M5 with a group of 8 heads or fewer (attention_join.build) and pairs each round's rows; TF_QWEN27_JOIN=0 keeps main's pipelines. Share groups across streams wait for shared prompt pages on Metal; until then only a window's own rows pair. Tests: tf-qwen27-attention-share checks pairs against every stream alone through main's kernels and against main's unpaired plan, bit for bit, with a planted page a false share must show, and times them; tf-qwen27-attention-pages still matches contiguous caches bit for bit; a host test covers Plan.pair's rules. Measured on an M3 Ultra (80-core), attention pass at 34,817 keys, main -> pairs: 4 streams x 8-row drafted windows 11.2 -> 6.0 ms (-46%); with streams on one prefix's pages, 8 x 1 row 3.31 -> 2.16 ms and 4 x 1 1.94 -> 1.43. Served, the 27B on its default contiguous caches, main -> the join, per-stream tokens a second while all decode, 264 replies identical to main's (drafts off and one stream too): drafted at a 32K prompt +29% at 8 streams and +24% at one, at 8K +3.5% and +2.6%; plain decode (one row a stream, no pairs, main's pipelines) level, and an 8K x 8 repeat of nine runs each puts the join at +0.06% and TF_QWEN27_JOIN=0 at +0.33% against main.
# Conflicts: # CHANGELOG.md
ashhart
force-pushed
the
lead/oe1-metal
branch
from
November 17, 2026 16:08
9f1ec75 to
eeb30e7
Compare
ashhart
added a commit
to jschmied/TensorFold
that referenced
this pull request
Nov 17, 2026
# Conflicts: # CHANGELOG.md
ashhart
added a commit
to jayleaton/TensorFold
that referenced
this pull request
Nov 17, 2026
# Conflicts: # CHANGELOG.md
ashhart
added a commit
to gilby/TensorFold
that referenced
this pull request
Nov 17, 2026
# Conflicts: # CHANGELOG.md
ashhart
added a commit
to garvrao80/TensorFold
that referenced
this pull request
Nov 17, 2026
# Conflicts: # CHANGELOG.md
ashhart
added a commit
to akol1/TensorFold
that referenced
this pull request
Nov 17, 2026
# Conflicts: # CHANGELOG.md
ashhart
added a commit
to laudney/TensorFold
that referenced
this pull request
Nov 17, 2026
# Conflicts: # CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Qwen3.8-27B on Metal before M5: a drafted window's rows run the decode attention in pairs over the keys below the window, so each pair shares one threadgroup, one K/V load and one matrix multiply.
The change. The second row of a pair uses the first row's spare tile lines (8 to 13), and every line's arithmetic is the one it runs alone. The paired kernels are a
Q27_JOINbuild of the same sources. Main's pipelines compile from unchanged text and run every plan that has no pair.TF_QWEN27_JOIN=0turns it off; the setting is registered, documented and tested. Pairs across streams on shared pages are already inPlan.pairand wait for the store's page sharing, a separate change. Macs with tensor units (M5) run the prefix-kernel plan and are untouched; a join there would be a follow-up.Exact.
tf-qwen27-attention-sharechecks paired rows against every stream alone and against main's unpaired plan, bit for bit, with a planted control that fails.tf-qwen27-attention-pagesstill passes. On macOSzig build testpasses, including a newPlan.pairhost test. pr_check reports 0 errors, and lean is 221 before and after.Served, M3 Ultra, Qwen3.8-27B with contiguous caches, main against this. Every one of 264 replies is identical to main's.
Kernel, M3 Ultra, 35K keys. Four 8-row drafted windows: 11.2 to 6.0 ms. Eight streams on shared pages: 3.31 to 2.16 ms.