Skip to content

backends: measured kernel choices and 512-row prompt passes for the M5 Ultra - #97

Open
AviKndr wants to merge 1 commit into
lithos-ai:mainfrom
AviKndr:pr/m5-ultra-64c-kernel-choices
Open

AviKndr wants to merge 1 commit into
lithos-ai:mainfrom
AviKndr:pr/m5-ultra-64c-kernel-choices

Conversation

@AviKndr

@AviKndr AviKndr commented Oct 22, 2026

Copy link
Copy Markdown

Refs #13. Stacked on #96 (the m5_ultra_64c backend): this branch is cut from pr/m5-ultra-64c, so review the last commit, backends: measured kernel choices and 512-row prompt passes for the M5 Ultra.

This is the first measured step of #13's item 2: whole-model numbers on the real target, nvidia/Qwen3.8-27B-NVFP4 (482ca0f) with LithosAI/Qwen3.8-27B-DSpark-NVFP4 (b169bc4). It adds the measured kernel choices, decides the lane order on the whole model, and sets serve's prompt chunk.

What changes

  • m5_ultra_64c/kernel-choices.json (54 entries), referenced from config.json (kernel_choices):
    • the autotuner's cache entries for 27B decode on the interleaved16 pack, plain and with DSpark;
    • the prompt pass's 32-row tiles, measured in the 512-row prompt program, the same way db53f2f did for the M3 Ultra.
  • m5_ultra_64c/backend.py: serving_prefill_chunk returns 512 (exact passes, as on the M3 Ultra and the 40-core M5 Max).
  • The whole-model lane-order A/B is added to the writer.decisions.lane_order note. interleaved16 stays, so the profile and its cost tables are unchanged and profile_writer is not re-run.
  • Contract tests: the shipped-choices geometry test covers apple-m5-ultra-64c, and the M5 Ultra test checks the 512-row hook. The backends README row is updated.

Method

Same machine (Mac Studio M5 Ultra, 64-core GPU, 96 GB, macOS 27.0.1), same day (2026-10-21), nothing else on the GPU.

Decode harness:

  • Each arm builds its session the way serve does: serving.setup.prepare and Backend.select_session's load_session options, so the DSpark arms verify 7 proposals plus the anchor, with the fixed rule.
  • Greedy, EOS off, 256 new tokens, on four prompts from tools/bench/spec_bench.py (code0, math0, chat0, text0).
  • One process per arm run, alternating A B / B A over 3 pairs, 3 reps per prompt per run.
  • tok/s is GPU decode time over committed tokens, with the best rep per prompt per run. The ranges below run across runs. Wall tok/s tracks GPU tok/s within 1 % (host idle).
  • The plain arms use --max-context 32774, so plain and DSpark share one target pack (capacity 32768 + 6). Each lane order gets its own pack.

Prompt-tile sweep:

  • Every TM32 shape the prompt program asks for, at each geometry (crew, crew2, ksplit2/4/8, with and without the scale cache), compiled into serve's prompt program and timed at 2048 tokens of context.
  • ms per shape is the per-dispatch counters summed over the pass's ops of that shape. Min-of-6 over two rounds in alternating geometry order.
  • A geometry replaces crew only past the tuner's 3 % margin.
  • The lm_head's tile does no work on an intermediate pass (0.004 ms), so it isn't measured and keeps the default.

1. Baseline: default geometry (--no-autotune equivalent), interleaved16

This is the "before" arm of tables 2 and 3. It matches PR #96's serve exactly.

mode set tok/s (per run) code0 math0 chat0 text0 ms per step tokens per step (code/math/chat/text)
plain 39.63–39.80 39.67–39.81 39.60–39.79 39.65–39.80 39.62–39.81 25.12–25.47 1
DSpark 85.39–85.54 131.58–131.90 118.93–119.12 74.05–74.18 57.39–57.49 41.23–41.89 5.46 / 4.92 / 3.06 / 2.37

2. Lane order on the whole model: interleaved16 stays

Each A/B is 3 paired alternating runs, with a pack per layout.

Default geometry:

mode lane order set tok/s code0 math0 chat0 text0 ms per step
plain interleaved16 39.52–39.95 39.44–40.02 39.53–40.00 39.49–39.86 39.60–39.92 24.99–25.47
plain contiguous 27.61–27.83 27.65–27.84 27.57–27.80 27.53–27.82 27.54–27.86 35.90–36.59
DSpark interleaved16 85.37–85.52 131.52–131.77 118.83–119.02 74.07–74.18 57.38–57.50 41.22–41.71
DSpark contiguous 85.12–85.42 131.13–131.50 118.54–119.02 73.79–74.05 57.23–57.45 41.26–41.68

Autotuned: each layout on its own live-tuner cache, which is what serve would ship for it.

mode lane order set tok/s code0 math0 chat0 text0 ms per step
plain interleaved16 46.00–46.33 45.92–46.26 45.93–46.40 46.01–46.39 45.94–46.36 21.55–21.96
plain contiguous 36.60–36.88 36.65–36.98 36.58–36.94 36.59–36.90 36.55–36.86 27.04–28.25
DSpark interleaved16 123.42–123.99 189.64–191.74 172.13–173.19 107.42–107.84 83.03–83.18 28.83–30.67
DSpark contiguous 105.35–105.66 164.94–165.75 148.87–149.54 89.09–89.42 71.11–71.51 33.33–34.20

Verdict: interleaved16 is faster wherever the ranges separate.

  • Plain: 1.42–1.45× on the default geometry, 1.25–1.27× tuned.
  • DSpark tuned: 1.17–1.18×, and 13–15 % less time per verify step.
  • DSpark on the default geometry is a tie, including per step.

Contiguous is not a clear win anywhere, so the pin from #96 stands and profile_writer is not re-run. [H] The whole model weighs shapes the kernel-level tie in #96 did not cover at their program geometry (all the FP8 projections, the drafter, the lm_head). Plain tokens are identical across layouts on the default geometry.

3. Kernel choices: serve decode, before vs after

  • Before: PR backends: the 64-core M5 Ultra #96's serve: default geometry, 128-row chunk.
  • After: this PR: KernelChoices from the shipped file, 512-row chunk. The prompts are ≤ 29 tokens, so the chunk does not enter decode.
mode arm set tok/s (per run) code0 math0 chat0 text0 ms per step tokens per step (code/math/chat/text)
plain before 39.63–39.80 39.67–39.81 39.60–39.79 39.65–39.80 39.62–39.81 25.12–25.47 1
plain after 46.28–46.64 46.07–46.66 46.06–46.65 46.41–46.63 46.43–46.64 21.43–21.76 1
DSpark before 85.39–85.54 131.58–131.90 118.93–119.12 74.05–74.18 57.39–57.49 41.23–41.89 5.46 / 4.92 / 3.06 / 2.37
DSpark after 122.16–124.23 190.18–193.81 167.39–169.87 106.65–108.57 81.86–83.18 28.50–29.67 5.57 / 4.87 / 3.10 / 2.37

Results:

  • Plain: +16–18 %.
  • DSpark: +43–45 %, mostly the round: 41.2–41.9 → 28.5–29.7 ms per step, with acceptance within ±2 %.
  • The shipped file reproduces the live tuner's numbers (table 2: 46.0–46.3 plain and 123.4–124.0 DSpark).
  • As with the autotuner, greedy outputs can differ from the default geometry's at near ties: plain text0, and DSpark code0, math0 and chat0.

4. The prompt pass's 32-row tiles

Measured in the 512-row prompt program at 2048 tokens of context. ms is summed over the pass's ops of each shape.

shape (TM32) chosen ms crew (default) ms
bf16 96×5120 (compact partials) ksplit8 3.28 6.96
fp8 14336×5120 ksplit4 18.94 24.99
fp8 16384×5120 ksplit4 64.89 76.94
fp8 5120×6144 residual ksplit4 35.07 47.11
nvfp4 34816×5120 silu·mul ksplit2 174.76 195.04
nvfp4 5120×17408 residual ksplit4 104.59 143.62
nvfp4 5120×25600 ksplit4 2.52 2.93
nvfp4 2048×5120 ksplit2 0.87 2.19
nvfp4 248320×5120 (lm_head) not measured, default — —

Whole pass, 5 paired alternating runs, min-of-3 each:

rows default ms chosen ms
512 618.0–622.3 516.7–519.9
128 (separate sweep, its own choices) 334.2–338.1 153.9–154.4

Three shapes choose the same geometry at 128 and 512 rows. Of the other five, two differ only in the scale cache (ties), and three are near ties or under 3 ms of the 512-row pass. The shipped set is the 512-row one, since serve now runs 512-row passes.

5. serve's prompt chunk (serving_prefill_chunk)

Prompt GPU time in ms. Chat prompts of exactly N tokens, exact passes, 3 reps per run.

A/B prompt A B
128 rows (128-row tiles) vs 512 (512-row tiles), 3 pairs 2846 3314–3351 2766–2786
8192 10862–11095 9236–9299
512 vs 1024 (shipped choices), 2 pairs 2846 2773–2784 2712–2728
8192 9262–9319 9001–9056
512 vs 1024 (shipped choices), 2 pairs, again 700 654–656 654–679
1500 1407–1421 1370–1420
2846 2759–2786 2679–2787
serve before → after (default geometry, 128 rows → shipped choices, 512 rows), 2 pairs 2846 7373–7450 2743–2776
8192 22462–22685 9198–9278
  • Every arm generates the same tokens per prompt, except "before" at 8192, which differs from "after" at a near tie.
  • 512 rows beats 128 everywhere.
  • 1024 is 2–3 % faster in one A/B and within 512's range in the other, so it's not a clear gain. 512 it is, like the M3 Ultra and the 40-core M5 Max.

Context only: the published 40-core M5 Max figures (not a matched A/B)

These come from another machine, other prompts, other recipes and another day.

  • README's 168 tok/s at 128-token context. This is a target-compute projection: 6 × 1000 / (an eight-row target forward summed from isolated layer minima), assuming six accepted tokens per pass. It excludes drafting, the output head and acceptance.
    • Here, a complete DSpark round (draft, eight-row verify with the output head, accept) takes 28.5–29.7 ms. That is about 200–210 tok/s at six tokens per round.
    • The measured rate is lower because acceptance on these prompts is 2.4–5.6 tokens per round, not six.
  • Measured M5 Max round (m5max-27b-dspark-refinement.md): 42.6 ms at 128 tokens with its tuned NVFP4 draft recipes, and 12.47 GPU ms per delivered token on its four prompts (about 80 tok/s).
  • Plain decode here: 46.3–46.6 tok/s reads ~17.6 GB per token, about 820 GB/s, 67 % of nominal. That is in line with the writer's single-token kernel rates on this chip (700–825 GB/s).

Tests

  • pytest tests/contract tests/kernels tests/runtime: 2739 passed, 40 skipped, 3 failed. The 3 failures are the existing test_streaming_moe_oracle.py ones under transformers 5.20 (Qwen3_5MoeTextRotaryEmbedding.__init__() got an unexpected keyword argument 'device'), unrelated to this change.
  • tools/ci/hygiene.py: ok.

Not in this PR

  • Fusion and draft recipes (gdn_mixer_fusion, megakernels, DSpark draft recipes) for the M5 Ultra: the measured M5 Max recipes don't carry over.
  • The lm_head's prompt-pass tile.
  • The A/B harness and the tile sweep are local scripts, not committed. They're available if a tools/bench version is wanted.

🤖 Generated with Claude Code

Register Apple M5 Ultra / Apple10 / 64 cores as its own backend: the two 32-core M5 Max dies it joins are a
different device for the crew geometry and the bus, and the 80-core part is another. With 96 GB (a 77.76 GB GPU
working set) the target and its drafter fit at the full context. The profile is tools/profile_writer.py's on the
device (Mac Studio, macOS 27.0.1): block scales, one threadgroup per core, the matrix tile from 2 rows for NVFP4
and INT4 and from 4 for FP8 and BF16, and v3 attention, faster than v1 and v2 at every measured point;
sibling_order is alu_first from p12 (88 % of the ALU sibling hidden encoded first, 13 % encoded second).

The writer decides the lane order from one T = 1 point, which fell on either side of the 3 % margin run to run
on this chip (contiguous +9.5 %, then +2.3 %). Two paired alternating A/B runs across the target's shapes are a
tie on the target (the NVFP4 MLP faster contiguous, FP8 and BF16 faster interleaved16), so the writer's tie rule
and the Apple10 default stand: profile_writer takes --lane-order to pin it, and the cost tables are measured on
that layout. The probe results are committed.

Refs lithos-ai#13

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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