Skip to content

Metal: the 27B verifies 32 rows a pass on pre-M5 Macs - #1841

Closed
ashhart wants to merge 3 commits into
mainfrom
lead/qwen27-32rows
Closed

ashhart wants to merge 3 commits into
mainfrom
lead/qwen27-32rows

Conversation

@ashhart

@ashhart ashhart commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Item 1 of #1621: on pre-M5 Macs one stream of Qwen3.8-27B verified at most 16 rows a pass.

  • Contiguous and strided 4-bit projections select four 8-row tiles within 32 KiB of threadgroup storage; shader bodies, K partitions, FP32 sums and the native window/draft policy are unchanged.
  • Registered under the kernel contract: frozen-main 16-row byte contracts, two GPU row-coupling controls and twelve adaptive launch records.
  • Host: three fault controls red, focused and Metal-entry compiles pass.

The M3 Ultra run (the kernel contract, 16 against 32 rows byte for byte, and one-stream drafted code and chat against main) comes before this lands.

Part of #1621.

@akol1

akol1 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Ran this head (eb912b0cf) on the other pre-M5 Mac here, so there is a data point before the M3 Ultra run lands. It is not that run: the contract half reproduces on an M4 Max; the one-stream comparison I can also run here if you point me at the harness (the 27B checkpoints and the DFlash2 drafter are local).

Host: Mac16,5, Apple M4 Max (40-core GPU, applegpu_g16, no tensor units), 128 GB, macOS 27.2 (26B123), Zig 0.17.0 with -Dcpu=apple_m1.

  • zig build kernel-contract: 43/43 steps.
  • zig build test-kernel-contract: 24/24 steps, 137/137 tests.
  • tf-kernel-contract on this GPU: PASS limits: 492 registered Metal launches against M1-M5, 0 problems.
  • --only '32-row': SUMMARY 2 kernels: 2 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed; 0 limit problems.
    • The byte check this PR is about: PASS shapes metal simd_qmm 32-row q4 g64: 19 shapes bit-equal to the kernel it replaces (worst 0.000 of the bound), 0 edges refused by the kernel, and the same line for simd_qmm_bits 32-row q4 g64.
    • PASS sums metal simd_qmm 32-row q4 g64: exact sums at k 512, where fp16 sums would miss by 317x and bf16 by 2483x (535x and 2866x for _bits); PASS repeat ...: five runs byte-identical (1632 bytes), inputs and guards untouched, no overlap; PASS nonfinite ...: 192 non-finite and 192 finite outputs match the float64 classes.
    • Both row-coupling controls are red as planted, at 17x48x256 ... its bytes differ from frozen main's 16-row simd_qmm passes's from byte 1536, so the equality above is a real check on this device, not a vacuous one.
  • --only simd: SUMMARY 6 kernels: 6 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed; 0 limit problems.

What this does not say: whether the served 27B selects 32 rows a pass here, and whether a drafted one-stream reply matches main. The contract proves the 32-row tiles write the same bits as the 16-row tiles for those 19 shapes and that the coupling control fires; the end-to-end comparison is still the item I would need your harness for.

The head is now conflicting (eb912b0cf, 120 commits behind main), so this evidence is against the current PR head only. I can re-run on a rebased head, and run the served comparison on the M4 Max, whenever you want them.

@akol1

akol1 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

The one-stream comparison I offered in my last note is below. Not the M3 Ultra run: the other pre-M5 Mac here, Mac16,5, Apple M4 Max (40-core GPU, applegpu_g16, tensor units false), 128 GB, macOS 27.2 (26B123), Zig 0.17.0 -Dcpu=apple_m1.

Setup: Qwen3.8-27B 4-bit + DFlash2 drafter, one stream, greedy, TF_QWEN27_SLOT_RESUME=0 so each request pays its own prefill, prompts of 42 / 61 / 390 / 739 tokens and 8–206 generated tokens, TF_Q27_PASS_PROFILE=1, TF_QWEN27_WINDOW 16 and 32, three rotated rounds plus two rounds with TF_QWEN27_COPIES=1; load average 3.9–7.9 logged per arm. Heads: this PR's eb912b0cf against main at the PR base 933b969fa.

Tokens are identical everywhere: all four greedy continuations hash the same in every arm, both binaries, both windows, copies on and off, every request cached=0.

The tiles are fine; the served round loop does not ask for 32 rows here. Offers stay at 16 rows or fewer on both binaries, e.g. steady state q27_offer width=32 rows=8 tree_nodes=7 copy_rows=0, widest rows=16 tree_nodes=15 copy_rows=0; tree_nodes never exceeded 15 in any arm. With TF_QWEN27_COPIES=1 the copies are counted but only in the first round of a reply (rows=16 tree_nodes=7 copy_rows=8 once per arm, copy_rows=0 after that) — consistent with copyRows() starting at @min(cap, 16) and growing only while copies land whole (zig/src/native/qwen27_slots.zig). So the 32-row path is selected by the prompt GEMMs, which run 128-row chunks (rowTiles(128) = 4), and by the startup cost sweep — not by a drafted decode round.

That costs prompt throughput. Prefill, seconds, four arms per column, rounds 2–3, i.e. every window/copies combination this head supports:

prompt main eb912b0cf ratio
739 tok 3.48 / 3.57 / 3.89 / 4.03 16.37 / 16.48 / 16.76 / 18.82 4.1–5.4×
390 tok 1.81 / 1.81 / 1.83 / 2.44 8.38 / 8.50 / 8.57 / 10.30 3.4–5.7×
61 tok 0.31 / 0.31 / 0.33 / 0.42 1.40 / 1.43 / 1.44 / 1.78 3.4–5.8×
42 tok 0.29 / 0.29 / 0.30 / 0.32 1.38 / 1.43 / 1.44 / 1.65 4.3–5.7×

Same window and same round, the ratio is 4.2–4.8× on every prompt. Time to first token follows prefill: 3.9 s → 16.8 s on the 739-token prompt.

Decode is a wash and the window does not move it. 75.5–91.1 tok/s on main against 78.4–94.4 on this head for the 206-token continuation; 36.8–48.7 against 36.9–48.0 for the 24-token reply; 40.5–52.9 against 41.6–51.4 for the 200-token one. Verify rounds are 34–36 against 31–34 (739-token prompt), 8 against 8, 62–64 against 62–65: no halving, because the pass width is still the 15-node tree, so the wide tile's main customer is prompt processing.

I have no M5 view; on M5 copies defaults on and the window can actually fill, so the trade can go the other way there. On this pre-M5 default (tensor units false, copies=off) the change measures as a ~4.5× prompt-processing regression with no decode gain. If the goal is only to make a 32-row verify legal and fast, I would gate the four-tile dispatch on the pass being a window-32 verify (or on the verify width) rather than on rows > 16, which catches every prompt chunk.

The contract side still holds on this head and is not in question: contract build 43/43, test-kernel-contract 24/24 … 137/137, --only '32-row' 2 kernels / 2 controls red as planted, --only simd 6 / 2; native build 57/57.

Happy to re-run on a rebased or gated head with the same prompts and measure. The window half of this is item (2) on #1621, where I have posted it.

@ashhart

ashhart commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Thanks @akol1 for the M4 Max run: a second pre-M5 chip is what this needed, and it says something we didn't expect. Tokens are identical, decode is a wash, offers stay at 16 rows or fewer, and prefill on eb912b0cf is 4.2 to 4.8 times slower than main at the same window and round. A speedup that costs that isn't one. The head has been rebased since. Our M3 Ultra run on it is still owed, and it has to show a gain over main's explicit TF_QWEN27_WINDOW=32 with prefill level. If it doesn't, this PR closes, with your numbers as the reason. A rerun on the rebased head with your same prompts would be welcome, since you have the checkpoint and the chip.

@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Closing this one. On @akol1's M4 Max run, prefill on this design was 4.2 to 4.8 times slower than main at the same window, with identical tokens and decode a wash. The rebased head's kernel and row-selection files are the same as the head that run measured, so the M3 Ultra run would be measuring the same code, and a 32-row verify can't pay that prefill back. Thanks again @akol1 for the run that settled it. If the 32-row pass comes back, it will be with a prefill path that stays level.

@ashhart ashhart closed this Nov 9, 2026
@ashhart
ashhart deleted the lead/qwen27-32rows branch November 10, 2026 16:34
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.

2 participants