Skip to content

Gemma on M5 Ultra: no drafts for a step whose rows all have prompts over 16,384 tokens - #2699

Merged
jonathan308 merged 3 commits into
devfrom
perf/gemma-m5-ultra-prompt-limit-0119
Nov 24, 2026
Merged

jonathan308 merged 3 commits into
devfrom
perf/gemma-m5-ultra-prompt-limit-0119

Conversation

@jonathan308

@jonathan308 jonathan308 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Gemma 4 26B QAT on M5 Ultra, under the two-draft policy, gets a prompt limit of 16,384 tokens. A decode step whose
drafting-eligible rows all have prompts over the limit runs without drafts, as ordinary chained decode. A row at or
under the limit keeps the chip's table, so a long-prompt row never stops another row from drafting. On M5 Ultra two or
more decode rows already run without drafts, so this changes only a long-prompt row decoding alone. There, two-draft
rounds cost more than they gain.

The engine side is mlx-swift-lm #546, the plan-time cohort check behind CBv2MTPConfig.maxDraftPromptTokens. With the
limit unset, #546 runs the current engine path. This branch is stacked on #2689 (SDK pin e7918994a7, which already
has the config field), so it builds as is. The behaviour follows once the pin includes #546.

DARKBLOOM_GEMMA_MTP_MAX_PROMPT_TOKENS=0 turns it off: the provider then passes no limit, and the engine runs exactly as
before.

Linked issue

Closes #

Evidence for the limit

Production request profiles (0.10.17, M5 Ultra, rows decoding alone): two drafts ÷ plain by prompt bin, ×1.04–1.09
under 2K, ×0.95 at 4–12K, ×0.82 at 16–24K, ×0.73–0.63 at 24–64K.

Quiet M5 Ultra A/B on the same requests (lone rows, Gemma card sampling; report questions, code, CSV records to JSON,
multi-turn chat; ABBA):

Prompt tokens n two drafts tok/s plain tok/s plain ÷ two drafts
0–4K 12 159.4 160.4 ×1.002
4–8K 16 166.9 145.3 ×0.871
8–12K 10 150.4 142.1 ×0.946
12–16K 6 147.0 137.6 ×0.934
16–20K 4 132.1 134.5 ×1.017
20–28K 11 117.0 131.6 ×1.132
28–64K 5 106.2 121.2 ×1.135

On an earlier release-candidate build (the whole-request form of this limit) lone rows over 16,384 decoded ×1.075
(n 48). T = 0 output matched the previous build at or under the limit and matched MTP-off decode over it (56/56).

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 on other chips (M5 Max and M3 Ultra included), for other models, under the one-draft policy and with
      the offline benchmark override.
  • gemmaPromptLimitOnByDefault (true) is the build default. Turning it false in one line leaves an unset setting with
    no limit.
  • EngineV2SlotFactory passes the value to CBv2MTPConfig.maxDraftPromptTokens and logs it once per slot.
  • DARKBLOOM_GEMMA_MTP_MAX_PROMPT_TOKENS (read once per process; the provider's launchd job forwards it):
    • unset, empty or not a positive integer: the build default (16,384);
    • 0, off, false or no: no limit;
    • 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;
    • gemmaPromptLimitDefaultCanBeSwitchedOff: with the build default off, an unset setting gives no limit; a positive
      setting still applies, and 0 stays off;
    • gemmaDraftPromptLimitParsesTheEnvironment;
    • gemmaDraftPromptLimitRollbackIsForwarded.
  • Engine tests in mlx-swift-lm fix(cache): harden routing and cache lifecycle #546: a lone row over the limit runs no round and has the MTP-off engine's tokens;
    rows at the limit draft; a row over the limit beside a row under it keeps the table's depth; no limit, unchanged.
  • Red control: Red control for #2699: tests without the change (do not merge) #2698, the same tests with a test-only adapter that gives no chip a limit. Its CI should fail
    exactly gemmaQATLongPromptsOnM5UltraDecodeWithoutDrafts, gemmaPromptLimitDefaultCanBeSwitchedOff and
    gemmaDraftPromptLimitRollbackIsForwarded.
  • On the release candidate build, quiet M5 Ultra, the limit on vs DARKBLOOM_GEMMA_MTP_MAX_PROMPT_TOKENS=0 (same
    app, ABBA, pre-declared bar): mixed concurrency (one long row with three short, and one with one), lone rows over
    and under the limit, and T = 0 identity.

Components touched

  • provider-swift (Swift CLI)
  • native runtime / MLX
  • 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 long-prompt row decoding alone matches MTP-off decode, not the previous
    MTP-on output.
  • The limit is on prompt length, not on the current context.
  • This replaces the earlier draft Gemma on M5 Ultra: long prompts decode without speculation #2622, whose whole-request form could keep other rows from drafting on chips whose
    tables draft at two or more rows.

Before And After

flowchart LR
  S[Gemma QAT decode step on M5 Ultra] --> P{every drafting-eligible row's prompt > 16,384?}
  P -- no --> D[the chip's table, as before]
  P -- yes --> T[depth 0: ordinary chained decode]
Loading

Refactor Pass

Refactor pass: no change justified.


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

…ver 16,384 tokens

Under the two-draft policy on M5 Ultra, MTPAutomaticVerificationPolicy.maxDraftPromptTokens gives gemma-4-26b-qat-4bit a prompt limit of 16,384 tokens, passed to CBv2MTPConfig.maxDraftPromptTokens. A plan whose speculation-eligible decode rows all have prompts over the limit runs at depth 0 as ordinary chained decode; a row under the limit keeps the chip's table, so a long-prompt row never stops another row from drafting. On M5 Ultra two or more decode rows already run without drafts, so this changes only a long-prompt row decoding alone. DARKBLOOM_GEMMA_MTP_MAX_PROMPT_TOKENS=0 removes the limit and a positive integer moves it; the provider's launchd job forwards it. Other chips, models and the one-draft policy are unchanged.
MTPAutomaticVerificationPolicy.gemmaPromptLimitOnByDefault (true) decides whether an unset DARKBLOOM_GEMMA_MTP_MAX_PROMPT_TOKENS applies M5 Ultra's 16,384 limit. With it false, an unset setting passes no limit, the engine behaviour from before the limit; an explicit positive value still applies it and 0 stays off. Tests cover both defaults.
The policy tests pass onByDefault explicitly, and the process-value check compares against gemmaPromptLimitOnByDefault, so turning the default off changes only gemmaPromptLimitDefaultCanBeSwitchedOff's first expectation.
@jonathan308 jonathan308 added the run-ci Trigger one-shot PR CI run (auto-removed when run starts) label Nov 24, 2026
@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 4:39pm UTC
darkbloom-status Ready Ready Preview Nov 24, 2026 4:39pm UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 24, 2026 4:39pm UTC

Request Review

@github-actions github-actions Bot removed the run-ci Trigger one-shot PR CI run (auto-removed when run starts) label Nov 24, 2026
@jonathan308
jonathan308 changed the base branch from perf/sdk-pin-m9 to dev November 24, 2026 18:52
@jonathan308
jonathan308 merged commit 87abb41 into dev Nov 24, 2026
27 checks passed

This branch was successfully deployed

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