Skip to content

Gemma on M5 Ultra: long prompts decode without speculation - #2622

Draft
jonathan308 wants to merge 7 commits into
devfrom
perf/gemma-m5-ultra-long-prompt-plain
Draft

jonathan308 wants to merge 7 commits into
devfrom
perf/gemma-m5-ultra-long-prompt-plain

Conversation

@jonathan308

@jonathan308 jonathan308 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Planned for 0.10.19; not part of 0.10.18. On the 0.10.18 release candidate, T = 0 identity (56/56 prompts),
the off switch (56/56) and the long-prompt gain (lone rows over 16,384: decode ×1.075, n 48) passed. The
mixed-concurrency check (one row over the limit decoding beside three short rows) missed its short-row decode bar in
one of three pairs, so the change waits for a per-row gate and a re-measured mixed check.

Summary

On M5 Ultra, a gemma-4-26b-qat-4bit request whose prompt holds more than 16,384 tokens no longer drafts. It decodes
as ordinary chained target decode for its whole lifetime, with the tokens of MTP-off decode. On those prompts a lone
row's two-draft rounds cost more than they gain. Shorter prompts, other chips, other models and the one-draft policy
are unchanged. DARKBLOOM_GEMMA_MTP_MAX_PROMPT_TOKENS=0 removes the limit.

Depends on mlx-swift-lm #533 (CBv2MTPConfig.maxDraftPromptTokens). This branch is merged onto #2620's head e0c4207a53,
which pins libs/mlx-swift-lm to the combined SDK head 20fa3d540d (mlx-swift-lm #534: SDK main 4bb2b43ee8 + #530 +
#533). Against e0c4207a53 this PR changes only provider files and does not move the gitlink. Land it after #2620.

Linked issue

Closes #

Evidence for the limit

Production request profiles (0.10.17, M5 Ultra, rows decoding alone, two drafts at fixed depth). For each prompt
bin: tokens per round on drafted rows × the plain step of plain rows in the same bin ÷ the round time.

Prompt tokens < 2K 2–3K 3–4K 4–12K 16–24K 24–64K
two drafts ÷ plain ×1.04–1.09 ×0.94–0.96 ×0.99 ×0.95 ×0.82 ×0.73–0.63

Quiet M5 Ultra A/B on the same requests (lone rows, Gemma card sampling, 384 max tokens; four content kinds: report
questions, code, CSV records to JSON, multi-turn chat; ABBA; previous build with two drafts vs an earlier head of this
policy whose limit was 4,096 (316c4179b6), so every request over 4,096 decoded plain):

Prompt tokens n two drafts tok/s plain tok/s plain ÷ two drafts
0-4096 12 159.4 160.4 ×1.002
4096-8192 16 166.9 145.3 ×0.871
8192-12288 10 150.4 142.1 ×0.946
12288-16384 6 147.0 137.6 ×0.934
16384-20480 4 132.1 134.5 ×1.017
20480-28672 11 117.0 131.6 ×1.132
28672-65536 5 106.2 121.2 ×1.135

Two drafts still win up to 16K on three of the four kinds; only the low-acceptance kind (report questions) loses from
about 4K. Past 16,384 plain decode wins (×1.10 overall, n 20), and production shows its largest losses there. Both
agree only above 16K, so the limit is 16,384. M5 Max (production control): ×1.00–1.18 up to 16K, so no other chip gets
a limit.

Evidence: sizing on an M5 Ultra Mac; production bins from 0.10.17
request profiles.

Change

  • MTPAutomaticVerificationPolicy.maxDraftPromptTokens(modelID:chipName:...):
    • returns 16,384 for the catalog Gemma 4 26B QAT on M5 Ultra while the two-draft policy is on;
    • returns nil everywhere else: other chips (M5 Max and M3 Ultra included), other models, the one-draft policy
      (DARKBLOOM_GEMMA_MTP_TWO_DRAFTS=0) and the offline benchmark override.
  • EngineV2SlotFactory passes the value to CBv2MTPConfig.maxDraftPromptTokens and logs it once per slot.
  • The SDK makes a request over the limit target-only for its whole lifetime, as it already does for a request with a
    reasoning budget: no drafts, no assistant history, ordinary chained decode. The gate depends only on the prompt
    length, so a given request either always drafts or never does.
  • DARKBLOOM_GEMMA_MTP_MAX_PROMPT_TOKENS (read once per process; the provider's launchd job forwards it):
    • unset, empty or not a positive integer: 16,384;
    • 0, off, false or no: no limit, today's behaviour;
    • a positive integer: that limit (M5 Ultra only).

Test plan

  • MTPConfigTests:
    • gemmaQATLongPromptsOnM5UltraDecodeWithoutDrafts: 16,384 on M5 Ultra; the setting moves it or removes it; nil for
      every other chip, model, the one-draft policy and the benchmark override, whatever the setting;
    • gemmaDraftPromptLimitParsesTheEnvironment;
    • gemmaDraftPromptLimitRollbackIsForwarded.
  • SDK engine tests in mlx-swift-lm release(provider): v0.7.6 — enable paged KV for GPT-OSS #533: over the limit, no round and the MTP-off engine's tokens; at the limit,
    drafts and the same tokens; no limit, unchanged.
  • Red control: Red control for #2622: tests without the change (do not merge) #2621, the same tests with a test-only adapter that gives no chip a limit. Its CI should fail
    exactly gemmaQATLongPromptsOnM5UltraDecodeWithoutDrafts and gemmaDraftPromptLimitRollbackIsForwarded.
  • Quiet M5 Ultra limit sizing (ABBA, lone rows, same requests): the table above. It moved the limit from 4,096 to
    16,384.
  • Quiet M5 Ultra mixed concurrency at the earlier 4,096 head (1 long + 3 short, and 1 + 1; long rows 8.8–14K): short
    rows decode ×1.000 / ×1.007 and time to first token ×1.000 / ×1.003, aggregate ×0.990 / ×1.009.
  • On the release candidate build, against the previous build (ABBA), at 16,384:
    • T = 0: prompts at or under the limit equal the previous build's tokens; prompts over it equal the previous build's
      tokens with DARKBLOOM_CBV2_MTP=0; DARKBLOOM_GEMMA_MTP_MAX_PROMPT_TOKENS=0 equals the previous build;
    • speed: lone rows over 16,384 gain decode; under the limit, time to first token ≤ ×1.03 and decode ≥ ×0.97 at
      one, two and four streams;
    • mixed concurrency with long rows over 20K tokens (1 long + 3 short, and 1 + 1, three pairs each): short rows
      within 3 %, aggregate ≥ ×0.99, tokens identical per row.

Components touched

  • provider-swift (Swift CLI)
  • native runtime / MLX (SDK pin)
  • landing (Next.js)
  • enclave (Swift)
  • CI / provider release
  • docs

Protocol / interface changes

  • No protocol/interface changes. New environment key DARKBLOOM_GEMMA_MTP_MAX_PROMPT_TOKENS (documented).
  • Yes — described above and matching side updated

Documentation impact

  • Canonical documentation updated: docs/reference/configuration.md, docs/provider/cli-reference.md,
    docs/architecture/inference.md (Gemma two-draft policy).
  • No documentation needed — reason:

Changelog

  • Added changelog.d/gemma-m5-ultra-long-prompt-plain-decode.md and ran python3 scripts/changelog.py check.
  • No user-visible change, or an explicitly authorized release/history change.

Notes

  • Gemma's T = 0 tokens are not bit-identical between a two-draft round and a plain step: verify widths round
    differently, and near-ties can split. So a gated request matches MTP-off decode, not the previous MTP-on output. That
    is why the identity check above has two references.
  • The limit is on prompt length, not on the current context. A row that grows past 16,384 tokens while generating
    keeps drafting, so its output stays the previous build's.
  • On M5 Ultra two or more decode rows already run plain chained decode ([2, 0]). The gate only changes lone rows
    with long prompts. Prefill is untouched.

Before And After

flowchart LR
  R[Gemma QAT request on M5 Ultra] --> P{prompt > 16,384?}
  P -- no --> D[lone row: two drafts per round, as before]
  P -- yes --> T[target-only for its lifetime: ordinary chained decode]
Loading

Refactor Pass

Pending.


Get evidence
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

jonathan308 and others added 3 commits November 23, 2026 22:14
Pin mlx-swift-lm 9db9dfc15c (Layr-Labs/mlx-swift-lm#530). A complete
prefix checkpoint stored with the balanced profile is restored by decoding
its coded rows; the SDK now decodes them on several cores straight into the
staged pages, and stages those pages on zero-fill-on-demand memory when the
serving pool does. The restored bytes are unchanged. Every Gemma 4 cache hit
paid about 141 ms for this at 1,024 cached tokens on an M5 Ultra.

Docs: the restore paragraph of the inference architecture, the parallel
stage row of the SSD reference, and the DARKBLOOM_PREFIX_CACHE_PARALLEL_STAGE
rows of the configuration and CLI references. Changelog fragment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds CBv2MTPConfig.maxDraftPromptTokens on top of the current pin b98bcd3343 (same tree as SDK main 4bb2b43ee8). The next commit sets it for Gemma on M5 Ultra.
Under the two-draft policy on M5 Ultra, a gemma-4-26b-qat-4bit request whose prompt holds more than 4,096 tokens no longer drafts (CBv2MTPConfig.maxDraftPromptTokens): it decodes as ordinary chained target rows for its whole lifetime, with the MTP-off engine's tokens. A lone row's two-draft rounds cost more than they gain there. DARKBLOOM_GEMMA_MTP_MAX_PROMPT_TOKENS=0 removes the limit, a positive integer moves it; the LaunchAgent forwards it. Other chips, models and the one-draft policy are unchanged.
@vercel

vercel Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference-landing Ready Ready Preview Nov 24, 2026 8:12am UTC
darkbloom-status Ready Ready Preview Nov 24, 2026 8:12am UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 24, 2026 8:12am UTC

Request Review

@jonathan308 jonathan308 added run-ci Trigger one-shot PR CI run (auto-removed when run starts) run-release-ci One-shot: run SDK 27 release and qualification on this PR (removed when the run starts) labels Nov 24, 2026
@github-actions github-actions Bot removed run-release-ci One-shot: run SDK 27 release and qualification on this PR (removed when the run starts) run-ci Trigger one-shot PR CI run (auto-removed when run starts) labels Nov 24, 2026
jonathan308 and others added 3 commits November 23, 2026 22:26
Pin mlx-swift-lm f335812335 (Layr-Labs/mlx-swift-lm#530): 9db9dfc15c plus
a test-only commit that passes a destination to writeNative in an existing
SDK test. No library change against 9db9dfc15c.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pin mlx-swift-lm 20fa3d540d (candidate/0.10.18-c6-sdk, landing PR
Layr-Labs/mlx-swift-lm#534): main 4bb2b43ee8 with a merge of #530
(f335812335, the concurrent checkpoint row decode) and a merge of #533
(175069698c, a prompt-length limit for MTP drafting). Against f335812335 it
adds only #533's change; #533's provider side and docs are their own PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tra long-prompt branch

libs/mlx-swift-lm takes #2620's pin 20fa3d540d (SDK main M4 + #530' + #533), replacing this branch's temporary pin to #533 alone. Against e0c4207 the branch now changes only provider files.
@jonathan308 jonathan308 added run-ci Trigger one-shot PR CI run (auto-removed when run starts) run-release-ci One-shot: run SDK 27 release and qualification on this PR (removed when the run starts) labels Nov 24, 2026
@github-actions github-actions Bot removed run-release-ci One-shot: run SDK 27 release and qualification on this PR (removed when the run starts) run-ci Trigger one-shot PR CI run (auto-removed when run starts) labels Nov 24, 2026
The quiet M5 Ultra A/B by prompt band (lone rows, MTP on vs off) puts the break-even at 16,384 prompt tokens, not 4,096.
@jonathan308 jonathan308 added run-ci Trigger one-shot PR CI run (auto-removed when run starts) run-release-ci One-shot: run SDK 27 release and qualification on this PR (removed when the run starts) labels Nov 24, 2026
@github-actions github-actions Bot removed run-ci Trigger one-shot PR CI run (auto-removed when run starts) run-release-ci One-shot: run SDK 27 release and qualification on this PR (removed when the run starts) labels Nov 24, 2026
@jonathan308 jonathan308 mentioned this pull request Nov 24, 2026
5 of 8 tasks

This branch was successfully deployed

3 active deployments
Preview – d-inference-landing — b579536d Deployed Nov 24, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — b579536d Deployed Nov 24, 2026 by vercel[bot]
Preview – darkbloom-status — b579536d Deployed Nov 24, 2026 by vercel[bot]
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