Skip to content

metal: row projection cutover per chip (M5 Max narrow up to 32 rows; Ultra unchanged) - #4730

Merged
ashhart merged 7 commits into
mainfrom
lead/metal-row-cutover-per-chip
Nov 23, 2026
Merged

ashhart merged 7 commits into
mainfrom
lead/metal-row-cutover-per-chip

Conversation

@ashhart

@ashhart ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Metal row projection: the narrow/wide cutover is keyed per chip (GPU generation plus the Pro/Max/Ultra tier from the device's name), not by generation alone. Refs #3396.

On an M5 Ultra the 8-row wide kernel wins from 8 rows, but measurements from an M5 Max showed the wide kernel never winning at 3-8 bits up to 32 rows (4-bit at 8 rows: 45.4 µs narrow vs 88.7 µs wide), so windows of 8 rows or more ran on the slower kernel there. The M5 Max now gets its own row (narrow up to 32 rows at 3-8 bits; at 2 bits, wide from 32). The M5 Ultra row is unchanged, and any chip the table doesn't list keeps its generation's cutover. Both kernels produce the same bytes, so tokens can't change.

  • The chip is read once when the pipelines are built; each dispatch only looks up its width's cutover.
  • tf-row-cutover prints the device name and the key it used.
  • Host tests: the name parser (base, Pro, Max, Ultra, trailing spaces, unknown names), the per-width table, and the Max table through call and callStrided.
  • macOS: the series builds and its host tests pass on a Mac; one macOS-only test-helper compile error is fixed in the last commit.

Served A/B on an M5 Ultra, Qwen3.8-27B with the DFlash2 drafter, main against this branch, three runs a side, a fresh window-cost table on every server start: every cell level (-1.75% to +1.35%, inside run-to-run spread), and token digests identical in every run.

An M5 Max read is still welcome: tf-row-cutover should print tier max, and served decode at 4 and 8 streams should improve.

… generation (#3396)

The row kernels' cutover from narrow to wide windows was keyed by the GPU
generation alone, so an M5 Max took the wide kernels from 8 rows as an M5
Ultra does. On an M5 Max the wide kernel never wins from 1 to 32 rows at
3 to 8 bits, and at 2 bits only at 32 (the reporter's tf-row-cutover run:
at 4 bits and 8 rows 45.4 us narrow against 88.7 us wide), so its 8-row
windows ran at about twice the time.

What separates the two is the GPU's size, which Metal does not report as a
core count; it does report the device's name, whose last word gives the
tier. The cutover is now keyed on the generation plus that tier, with a
cutover for each code width: a row without a tier holds for its generation
and later (generation 17: 8 at every width, the M5 Ultra and every other
M5 as before), a row with a tier for that tier of its own generation only
(generation 17, Max: 32 at 2 bits, never at 3 to 8). Chips not in the
table, and later generations, keep their generation's cutover. tf-row-cutover
prints the key it uses and the table's cutover at each width.

The narrow and wide kernels give the same bytes (tf-row-cutover and the
Metal wide-row contract check it), so no token changes. The table and key
live in row_cutover.zig without Metal: test-row-cutover-host checks the Max
row, unlisted tiers and generations, names the key reads and the tool's key
line; the dispatch tests run per code width.
…EV75 1)

Pipelines.load now reads the device's name for the cutover's chip key, but
the host builds' recording Metal stubs had no name: test-qwen27-quant-host
(and with it zig build test) failed to compile where its quantized matrices
load the row pipelines. The qwen27, LFM2, Gemma 4 head and Flash Next stubs
now give an empty name, which keys no listed chip, so their row pipelines
keep their generation's cutover, as before the per-chip key.
chipOf took a name's last word as its tier and any other "Apple M..." name
as base: "Apple M5 Extreme", "Apple M5 Max (40-core)" or "Apple Mx" read as
base, and "Apple A19 Pro", "AMD Radeon Pro" or "Foo Max" as a tier. Today
neither changes a cutover (base has no row; no such device is generation
17), but a base row would have taken them silently. It now reads
"Apple M<digits>" as base and "Apple M<digits> Pro|Max|Ultra" as that tier,
words split on spaces (a trailing space is no word), and gives any other
name no tier, so it keys its generation's cutover as an unlisted chip does.
The dispatch tests set every width's cutover to one value, so a lookup
reading the wrong width's slot would have passed them. The lookup is now
row_cutover.takes, on the host: with the M5 Max's table a 2-bit window of 32
rows takes the wide kernels and one of 31 does not, while every other width
stays narrow at 32; the Ultra's table goes wide at 8 rows and not 7 at every
width; a width the kernels do not unpack takes none. The Metal dispatch test
(macOS) also runs the Max's mixed table through call and callStrided.
… (REV75 4)

tf-row-cutover printed the generation and tier it keyed on, not the name
the tier was read from, so a run on a chip whose name the key does not know
(a new tier word, a virtual machine's device) showed "tier unknown" with
nothing to say why. Its key line now begins with the device's name as Metal
gives it.
@ashhart
ashhart force-pushed the lead/metal-row-cutover-per-chip branch from d94e77c to ceff284 Compare November 23, 2026 07:05
@ashhart
ashhart merged commit 61f5826 into main Nov 23, 2026
1 check failed
@ashhart
ashhart deleted the lead/metal-row-cutover-per-chip branch November 23, 2026 07:05
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