Skip to content

metal row projection: windows of 4+ rows run 8 at a time, then 4, 2 and 1, each code unpacked once - #3129

Merged
ashhart merged 5 commits into
mainfrom
lead/metal-rows-8
Nov 17, 2026
Merged

ashhart merged 5 commits into
mainfrom
lead/metal-rows-8

Conversation

@ashhart

@ashhart ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Metal row projections ran windows of more than four rows four at a time, unpacking each weight code once a group. Windows of 4 or more rows now run 8 at a time, then 4, 2 and 1 (6 rows run 4+2, 7 run 4+2+1, 15 run 8+4+2+1), so each code is unpacked once for up to eight rows. Each row's sum keeps the same order of terms, so results stay bit-equal to one row alone. The new template parameter defaults off, so GLM, MiniMax, LFM3 and qwen27 keep their current code.

Tests: row_projection.zig 10/10 (the dispatch test fails with main's dispatch); test-kernel-contract 203/203 with the new records test; the shader compiles at metal3.1 and metal4.1 with all 36 new symbols, and its includers compile.

Device check pending, on an M5 and an M1-M4 Mac: tf-row-widths-check against main's shader (widths 1-32 bit-equal to one row alone, width 16 byte-equal to main's kernel); the row projection wide and row projection kernel-contract entries (42 kernels pass, all 36 controls red); a served A/B with token hashes equal to main at T=0 and tok/s no lower (holding 8 rows a thread may cost registers on M1-M4).

@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Device run on an M3 Ultra (pre-M5), main against this head, Qwen3.8-27B: REVIEW. Decode at a 16,384-token context is slower, 28.4 to 27.4 tok/s (-3.5%), with both new runs (27.33, 27.55) below both base runs (28.45, 28.39). It's held out of the landing queue until the pre-M5 path is level, perhaps by keeping the 8-row step to M5, where it was measured.

  • Synthena (Ash's Agent)

… M1-M4 keep main's 4, 2 and 1

On an M3 Ultra, decode at a 16,384-token context was 3.5% slower with the
8-row step (28.4 to 27.4 tok/s, both new runs below both base runs); it was
measured only on an M5 Ultra. Pipelines.load now records device.tensorUnits(),
the chip fact the Qwen3.8-27B Metal code already reads (applegpu_g17 and
later), and call and callStrided take the wide pipelines only when it is set.
Without tensor units every row count keeps main's pipelines, so M1-M4 run
main's kernels and steps exactly. A host test pins that dispatch for every
width, both sums and 1 to 32 rows; the existing dispatch test now covers the
tensor-unit side.
On Linux the Metal Pipeline is an inert stand-in without an id field, so the
two tests that build pipelines by id failed to compile in test-gemma4-owners-host
once that step reached this file. They now skip at comptime off macOS.
@ashhart
ashhart merged commit 7590927 into main Nov 17, 2026
2 of 11 checks passed
@ashhart
ashhart deleted the lead/metal-rows-8 branch November 17, 2026 07:06
ashhart added a commit that referenced this pull request Nov 17, 2026
Seven duplicate entries go (a PR's own line beside its lines-file line), five outside authors are thanked, #1503 gets the line its close note promised, and eleven lines now match their PRs' code and receipts (#3129, #3194, #3258, #2696, #2921, #3365, #3345, #3384, #3679, #3682, #3699, #3393).
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.

1 participant