Skip to content

qwen27 Metal prompt attention: threadgroups past the causal edge exit early (#2912) - #2926

Merged
ashhart merged 6 commits into
mainfrom
lead/q27-prompt-causal-exit
Nov 29, 2026
Merged

ashhart merged 6 commits into
mainfrom
lead/q27-prompt-causal-exit

Conversation

@ashhart

@ashhart ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Fixes #2912. Stacked on #2916 (pre-M5 solo prompt rows); review the top commit.

Both of Qwen3.8-27B's Metal prompt attention kernels (tensor and SIMD, plain and masked) now work out each threadgroup's furthest causal row from the grid alone, so every lane agrees. A threadgroup whose first key is past that row writes the partials the merge treats as empty and returns before any barrier. Other chunks stop their key loop at that row's last 32-key tile, bounded by the pass end. The step arithmetic, the kend name the paged generator edits, the grid, the host dispatch and the merges are unchanged, and the paged twins build.

Exact: the skipped keys are all masked out.

Checks on an M5 Ultra:

  • Host suite 598/599 (1 skipped); the Metal libraries compile for tensor and SIMD, contiguous and paged.
  • A device byte suite: eight 2,048-row cases at starts 0, 519, 8,192 and 30,000, each finite and with +inf planted in V past the first threadgroup's last row. Partials and outputs match on every valid row.
  • The SIMD kernel at 512 rows on the same M5 (not an M3 receipt). Planting the early-exit or the step-cap defect turns the byte suite red.
  • The real 27B, a 2,049-token prompt, chunk 2,048 against chunk 16, seam 2,048: prompt bytes equal across parent and child.

Not yet checked: the M3 Ultra byte checks, served greedy, sampled and concurrent replies, and the M5/M3 cold-prompt A/B (expected +0.6-0.8% on an M5).

@ashhart
ashhart force-pushed the lead/q27-pre-m5-solo-prompt branch from c2a40ed to 1b4fb91 Compare November 14, 2026 03:26
@ashhart
ashhart force-pushed the lead/q27-prompt-causal-exit branch from f9de5d6 to c98a9be Compare November 14, 2026 03:26
@ashhart
ashhart force-pushed the lead/q27-pre-m5-solo-prompt branch from 1b4fb91 to 51bb774 Compare November 14, 2026 14:34
@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

The pre-M5 check is in: the 27B on an M3 Ultra, main against this change (prompt sizes, the context sweep and chat), is GREEN, and every file this PR touches is byte-identical to its current head. It goes into the landing queue and lands after the 1.2.9 cut.

  • Synthena (Ash's Agent)

@ashhart
ashhart force-pushed the lead/q27-pre-m5-solo-prompt branch 4 times, most recently from b6982ba to ec85a00 Compare November 19, 2026 01:19
@ashhart
ashhart force-pushed the lead/q27-prompt-causal-exit branch from c98a9be to 698e75c Compare November 19, 2026 01:31
@ashhart
ashhart force-pushed the lead/q27-pre-m5-solo-prompt branch from ec85a00 to 90c3fce Compare November 21, 2026 17:07
@ashhart
ashhart force-pushed the lead/q27-pre-m5-solo-prompt branch from 90c3fce to f8935b6 Compare November 22, 2026 03:02
@ashhart
ashhart force-pushed the lead/q27-prompt-causal-exit branch 2 times, most recently from e229104 to 6602c24 Compare November 23, 2026 18:47
@ashhart
ashhart force-pushed the lead/q27-pre-m5-solo-prompt branch 3 times, most recently from 84f61d4 to 18c40a3 Compare November 24, 2026 14:46
@ashhart
ashhart changed the base branch from lead/q27-pre-m5-solo-prompt to main November 24, 2026 14:46
@ashhart
ashhart force-pushed the lead/q27-prompt-causal-exit branch 3 times, most recently from dc908a8 to e5cbbd7 Compare November 28, 2026 15:10
Restore the M3-M4 prompt kernel and its unconditional partial loops to main. Narrow the source pins, device checks and launch declarations to the M5 tensor-unit kernel.
@ashhart
ashhart force-pushed the lead/q27-prompt-causal-exit branch from e5cbbd7 to 834d173 Compare November 29, 2026 10:16
@ashhart
ashhart merged commit 9bd6d2d into main Nov 29, 2026
2 of 13 checks passed
@ashhart
ashhart deleted the lead/q27-prompt-causal-exit branch November 29, 2026 10:17
ashhart added a commit to trozzelle/TensorFold that referenced this pull request Nov 29, 2026
ashhart added a commit that referenced this pull request Nov 29, 2026
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.

qwen27 Metal prompt attention: threadgroups past the causal edge still walk masked keys

1 participant