Skip to content

perf(lanes): one-stream servers tile 8-slice projections 32 wide (+8% serial decode on M5 Max, same bits) - #196

Closed
jkuepker wants to merge 1 commit into
ashhart:mainfrom
jkuepker:mac-perf
Closed

jkuepker wants to merge 1 commit into
ashhart:mainfrom
jkuepker:mac-perf

Conversation

@jkuepker

@jkuepker jkuepker commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

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_TILED kernel 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 whose split_k is above NARROW_MAX_SK (4) 32 wide instead of 64. Other weights are tiled as before.
  • qwen3_5.load(parallel=...) sets narrow_rows when parallel × (lone-stream window, including TF_COPY_ROWS) ≤ 32 rows. In practice that means --parallel 1 with the default window. The default --parallel auto (8) is unchanged.
  • Tests:
    • test_install_narrow_rows_keeps_many_slice_weights_32_wide_with_the_same_bits
    • test_one_stream_servers_ask_for_narrow_tiles (covers parallel and TF_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:

projection 64 wide 32 wide
down_proj ×64 144 µs 113 µs
out_proj ×48 63 µs 51 µs
o_proj ×16 74 µs 61 µs

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:

prompt before (--parallel 2, 64 wide) after (--parallel 1, 32 wide)
1k 26.4 / 26.6 tok/s 28.5 / 28.4 tok/s (+7.5%)
16k 25.0 / 25.1 tok/s 27.0 / 27.1 tok/s (+8%)

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 on main without 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

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]>
@freemanconsulting

Copy link
Copy Markdown

Receipt from an M5 Ultra (Mac Studio, 256 GB, macOS 27.0.1, AC power).

Setup

--parallel 1 --no-drafts (the PR's shape): bench_openai medians, tok/s

Cell main (run 5 / 7) #196 (run 6 / 8) Change
code greedy 41.52 / 41.50 46.13 / 46.05 +11.0%
code sampled 41.17 / 41.16 45.72 / 45.63 +10.9%
chat greedy 41.12 / 41.09 45.65 / 45.58 +11.0%
chat sampled 40.79 / 40.77 45.28 / 45.20 +10.9%
  • bench_concurrent (1 stream): 40.1–40.4 → 44.2–44.9 tok/s.
  • Decode at 16k depth: 36.6 → 40.2 tok/s.

--parallel 1 with DFlash2 (one run each): code greedy 141.65 → 143.16 tok/s (+1.1%). The other cells range from −0.2% to +0.6%. That is within noise, and below the ~+5% the PR anticipated for drafted decode.

Token equality: all six #196-shaped runs gave identical bench_openai replies. Every bench_concurrent --alone --serial check was equal.

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.

@ashhart

ashhart commented Oct 6, 2026

Copy link
Copy Markdown
Owner

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.

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.

3 participants