Repository navigation
Conversation
On M5, a 64-wide tile split into 8 K slices keeps 28 KB of partial sums in threadgroup memory, so only one threadgroup fits a core. Up to 32 rows the 32-wide kernel computes the same bits faster: down_proj 144 -> 113 us a call, out_proj 63 -> 51 us, o_proj 74 -> 61 us on M5 Max. The Qwen3.8-27B forward drops 36.7 -> 33.4 ms at 1 row and 39.4 -> 36.5 ms at 16 rows, with bit-identical logits. At 64-128 rows the 64-wide kernel's forward is 8-11% faster, so narrow tiles apply only when a round cannot pass 32 rows: --parallel 1. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Receipt from an M5 Ultra (Mac Studio, 256 GB, macOS 27.0.1, AC power). Setup
Token equality: all six #196-shaped runs gave identical The +11% one-stream gain on the Ultra is larger than the +7.5–8% the PR measured on the M5 Max. I didn't measure the crossover row count. |
|
Thank you, @jkuepker. Tracing the slowdown to 28 KB of partial sums in threadgroup memory, which leaves room for one threadgroup a core, is a sharp find, and gating the narrow tiles on row count kept the 64- and 128-row rounds from paying for it. The Python engine is frozen (#286), so this won't merge there, and Qwen3.8-27B isn't on the Zig engine yet. The Zig families avoid that buffer another way. During decode, Nemotron's two eight-slice projections run each K slice as its own threadgroup, with the partial sums in device memory, added in slice order. When the 27B comes over, its three eight-slice projections get your A/B, 32 wide against 64 wide up to 32 rows, next to that split path. If 32 wide wins, it lands with your credit. |
On M5, a 4-bit projection split into 8 K slices and tiled 64 columns wide (
_COOP) keeps 7 × 16 × 64 fp32 partial sums (28 KB) in threadgroup memory, so only one threadgroup fits per GPU core. On Qwen3.8-27B this applies to down_proj (5120×17408), out_proj and o_proj (5120×6144). Up to 32 rows, the 32-wide_MAIN_TILEDkernel at the same split computes the same bits faster. At 64–128 rows the 64-wide kernel is still faster, so this PR switches tile width only on servers whose rounds cannot go past 32 rows.Change
lane_qmm.install(..., narrow_rows=True)tiles 4-bit weights whosesplit_kis aboveNARROW_MAX_SK(4) 32 wide instead of 64. Other weights are tiled as before.qwen3_5.load(parallel=...)setsnarrow_rowswhenparallel × (lone-stream window, including TF_COPY_ROWS) ≤ 32rows. In practice that means--parallel 1with the default window. The default--parallel auto(8) is unchanged.test_install_narrow_rows_keeps_many_slice_weights_32_wide_with_the_same_bitstest_one_stream_servers_ask_for_narrow_tiles(coversparallelandTF_COPY_ROWS)Measurements (M5 Max 128 GB, MLX 0.32.3, Vontra/Qwen3.8-27B-MLX-4bit)
Per call, in a dependent chain over all layers. Both widths use the same split, and outputs are
array_equal:Full target forward pass, with logits bit-identical at 1, 9 and 16 rows: 36.7 → 33.4 ms at 1 row, 39.4 → 36.5 ms at 16 rows. In an interleaved A/B, rows 17/32 were 3.6%/1.9% faster, and rows 64/128 were 10.8%/7.7% slower, which is why the switch is gated on row count.
End to end with
--no-drafts, localeval run in A/B/A/B order with tight spreads:--parallel 2, 64 wide)--parallel 1, 32 wide)Prefill is unchanged. For drafted (DFlash2) decode I expect about +5%, because the drafter's time per round doesn't change. That's below my harness's noise, so it is not demonstrated end to end.
Tests
Full suite on M5 Max: 3789 passed, 486 skipped, 1 failed. The failure is
test_glm5_prompt_kernels.py::test_fused_index_scores_are_the_three_ops, which fails the same way onmainwithout this change.I only measured on an M5 Max. On M5 parts with more cores per die, the one-threadgroup-per-core limit is the same, but I haven't measured the crossover row count there.
🤖 Generated with Claude Code