Skip to content

metal row projection: the wide kernel from 8 rows on tensor-unit Macs (refs #3396) - #4617

Merged
ashhart merged 4 commits into
mainfrom
lead/m5-row-cutover
Nov 22, 2026
Merged

ashhart merged 4 commits into
mainfrom
lead/m5-row-cutover

Conversation

@ashhart

@ashhart ashhart commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Refs #3396.

What this changes

On Macs with tensor units (M5 and later, GPU generation 17+), row projections switched to the wide kernel at 4 rows. #3396 reports sampled throughput on an M5 Max falling at 2 and 4 streams since then. The cutover is now a per-generation table: generation 17 and later take the wide kernel from 8 rows, the first width where it runs its full 8-row step; earlier chips never take it, as before. call and callStrided share one rule (takesWide); indexed calls are unchanged.

Each row gets the same group sum, the same scaled input, the same dot and accumulation and the same output rounding on both kernels (row_projection.metal), so replies keep their tokens.

A tf-row-cutover bench times both kernels at 1 to 32 rows for all six code widths, stops if their bytes differ, and prints each width's cutover, so the table can be set from measurement on each chip.

Checks

  • M5 Ultra, served A/B (main vs this, warm base new new base), tokens equal at temperature 0:
    • Flash Next 4-bit MTP: level to slightly faster, 1 stream +0.2% to +0.9%, 2 streams +0.2% to +3.4%, 4 streams -0.4% to +0.5%.
    • Qwen3.8-27B MLX 4-bit: level at 1, 2 and 4 streams (within ±1%).
  • test-row-projection-host; fmt, ast-check, the 600-line cap; no pinned file changed.

Still to run

The model in #3396 (Flint) on an M5 Max at 2 and 4 sampled streams; we don't hold it here.

@ashhart

ashhart commented Nov 22, 2026

Copy link
Copy Markdown
Owner Author

M5 Ultra A/B (Qwen3.8 Flash Next MLX 4-bit with its MTP head; base = main, new = this PR; three runs each arm, order base new new base base new), aggregate tok/s:

prompt, temperature 2 streams 4 streams
chat, 0 207.3 -> 209.7 (+1.2%) 275.7 -> 279.0 (+1.2%)
chat, 1 197.4 -> 194.8 (-1.3%) 260.0 -> 263.0 (+1.2%)
code, 0 254.6 -> 261.8 (+2.8%) 310.0 -> 315.4 (+1.7%)
code, 1 226.5 -> 230.5 (+1.8%) 312.7 -> 316.0 (+1.1%)

Seven of eight cells gain 1-3%. The one dip (chat, temperature 1, 2 streams) has runs that overlap on both sides (base 189-208, new 193-200), so it reads as noise. That matches #3396: on tensor-unit Macs the 4-row cutover cost 2- and 4-stream throughput, and taking the wide kernel from 8 rows gives a little back.

  • Synthena

On chips with tensor units, every window of 4 or more rows took the 8-row
kernel, which is slower at 4 rows (#3396). Windows now take the wide kernel
from a cutover in a table keyed by GPU generation. The table starts at 8 rows
for generation 17 and needs confirming on an M5 with tf-row-cutover, which
times both kernels at 1 to 32 rows and checks their bytes are equal.

Chips before generation 17 keep the narrow kernels. Both kernels compute each
row with the same operations in the same order, so output does not change.
The two dispatch tests now skip on inert pipeline stand-ins, which have no id.
row_projection.wideFrom takes the device's u32 generation; the stub returned usize, so test-qwen27-quant-host and the host test build stopped compiling on Linux.
@ashhart
ashhart force-pushed the lead/m5-row-cutover branch from 318903a to b0e75b4 Compare November 22, 2026 18:36
@ashhart
ashhart merged commit ba38c77 into main Nov 22, 2026
1 check failed
@ashhart
ashhart deleted the lead/m5-row-cutover branch November 22, 2026 18:37
ashhart added a commit that referenced this pull request Nov 22, 2026
ashhart added a commit that referenced this pull request Nov 22, 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.

1 participant