Repository navigation
Gemma on M5 Ultra: long prompts decode without speculation - #2622
Draft
jonathan308 wants to merge 7 commits into
Draft
jonathan308 wants to merge 7 commits into
jonathan308 wants to merge 7 commits into
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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>
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.
5 of 8 tasks
jonathan308
marked this pull request as draft
November 24, 2026 10:53
8 of 16 tasks
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-4bitrequest whose prompt holds more than 16,384 tokens no longer drafts. It decodesas 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=0removes the limit.Depends on mlx-swift-lm #533 (
CBv2MTPConfig.maxDraftPromptTokens). This branch is merged onto #2620's heade0c4207a53,which pins
libs/mlx-swift-lmto the combined SDK head20fa3d540d(mlx-swift-lm #534: SDK main4bb2b43ee8+ #530 +#533). Against
e0c4207a53this 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.
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):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:...):(
DARKBLOOM_GEMMA_MTP_TWO_DRAFTS=0) and the offline benchmark override.EngineV2SlotFactorypasses the value toCBv2MTPConfig.maxDraftPromptTokensand logs it once per slot.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):0,off,falseorno: no limit, today's behaviour;Test plan
MTPConfigTests:gemmaQATLongPromptsOnM5UltraDecodeWithoutDrafts: 16,384 on M5 Ultra; the setting moves it or removes it; nil forevery other chip, model, the one-draft policy and the benchmark override, whatever the setting;
gemmaDraftPromptLimitParsesTheEnvironment;gemmaDraftPromptLimitRollbackIsForwarded.drafts and the same tokens; no limit, unchanged.
exactly
gemmaQATLongPromptsOnM5UltraDecodeWithoutDraftsandgemmaDraftPromptLimitRollbackIsForwarded.16,384.
rows decode ×1.000 / ×1.007 and time to first token ×1.000 / ×1.003, aggregate ×0.990 / ×1.009.
tokens with
DARKBLOOM_CBV2_MTP=0;DARKBLOOM_GEMMA_MTP_MAX_PROMPT_TOKENS=0equals the previous build;one, two and four streams;
within 3 %, aggregate ≥ ×0.99, tokens identical per row.
Components touched
Protocol / interface changes
DARKBLOOM_GEMMA_MTP_MAX_PROMPT_TOKENS(documented).Documentation impact
docs/reference/configuration.md,docs/provider/cli-reference.md,docs/architecture/inference.md(Gemma two-draft policy).Changelog
changelog.d/gemma-m5-ultra-long-prompt-plain-decode.mdand ranpython3 scripts/changelog.py check.Notes
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.
keeps drafting, so its output stays the previous build's.
[2, 0]). The gate only changes lone rowswith 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]Refactor Pass
Pending.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.