Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a66d4f1
Raise CBv2 mixed-step prefill geometry for GPT-OSS, dense Qwen and Ge…
Gajesh2007 Oct 22, 2026
51e331a
Document the Gemma 4 block ring bound and tighten geometry comments
Gajesh2007 Oct 22, 2026
585890d
Record why the Gemma benchmark wrapper schema stays at 6
Gajesh2007 Oct 22, 2026
1514eac
Merge master into ttft/mixed-prefill-chunk
Gajesh2007 Oct 22, 2026
c9b9707
docs: untangle the recurrent-bank paragraph after the master merge
Gajesh2007 Oct 22, 2026
7552a7b
Merge master into ttft/mixed-prefill-chunk
Gajesh2007 Oct 22, 2026
2ca5b2d
Re-pin libs/mlx-swift-lm to the merged SDK change (#331)
Gajesh2007 Oct 22, 2026
44b1a3e
Merge master into ttft/mixed-prefill-chunk
Gajesh2007 Oct 22, 2026
e8dba33
Re-pin the SDK to f77b384c and adapt to its tool-call delta type
Gajesh2007 Oct 22, 2026
4402b3a
Fill the schema-5 geometry in the merged prompt-mode receipt test
Gajesh2007 Oct 22, 2026
e541cbd
Carry the schema-5 prompt geometry into gptoss_profile summaries
Gajesh2007 Oct 22, 2026
0f92cac
Keep the wide prompt geometry default for Gemma 4 only
Gajesh2007 Oct 22, 2026
e19f138
Raise undersized Gemma 4 chunk overrides to cover a whole media block
Gajesh2007 Oct 22, 2026
872edea
Record the prompt geometry the built engines actually ran in receipts
Gajesh2007 Oct 22, 2026
f95ff5e
Count only completed tool-call deltas in the Flint test helpers, as #…
Gajesh2007 Oct 22, 2026
af702d9
Raise undersized Gemma 4 step budgets to cover a whole media block
Gajesh2007 Oct 22, 2026
8a9d48a
Name the families whose policy replaces the prompt geometry overrides
Gajesh2007 Oct 22, 2026
ce3a645
Merge master into ttft/mixed-prefill-chunk
Gajesh2007 Oct 22, 2026
7806655
Place prefill-geometry passthrough test apart from sibling PRs' inser…
Gajesh2007 Oct 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog.d/mixed-step-prefill-chunk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Wider mixed-step prefill for Gemma 4

- Gemma 4 prefills prompts in 2,048-token chunks with a 4,096-token step budget, including while other requests are decoding, instead of 512-token chunks beside decode. Busy engines reach the first token sooner and decode each stream faster; solo prefill chunking, KV capacity, paged ring sizes, load quotations and activation floors are unchanged. On contiguous KV (Gemma 4 artifacts other than the catalog's paged `gemma-4-26b-qat-4bit`, or with paging disabled), a solo prompt whose 2,048-token chunk cannot reserve KV now waits or is preempted instead of retrying with 512-token chunks, as the former 2,048-token stripe did.
- Gemma 4 image and video requests keep 512-token chunks, so their attention memory is unchanged.
- A decode token that shares a step with a long prompt now waits for a 2,048-token chunk instead of a 512-token one: typical inter-token gaps shrink, the slowest grow.
- GPT-OSS and dense Qwen3.5/3.8 also reached the first token sooner with the wide geometry, but at eight 32k-token prompts it raised their activation peaks further above their memory floors, so they keep the 512-token chunk and 2,048-token step by default. Nemotron 3.5, Bonsai, MoE Qwen, Qwen3-VL, Qwen4, MiMo and other families keep them too.
- Set `DARKBLOOM_CBV2_PREFILL_CHUNK=512` and `DARKBLOOM_CBV2_STEP_TOKENS=2048` to restore the previous Gemma 4 geometry, or `2048` and `4096` to opt another family in; `darkbloom start` forwards both to the background provider. Either override disqualifies reviewed serving and deadline profiles, like other `DARKBLOOM_CBV2_*` settings.
19 changes: 19 additions & 0 deletions docs/architecture/hardware-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,25 @@ Mode or a non-nominal thermal state the bridge serves and reports the configured
width (`EngineV2Bridge.hasPostureGatedWidth`). Explicit `engine_v2_max_concurrent`
values, including a literal `4` from older configs, are kept.

The [prompt geometry](inference.md#prompt-geometry) likewise changes no KV
grant, windowed-ring size, load quotation or activation floor: the paged pool
is sized from the largest schedulable chunk, `max(prefillChunkSize,
soloPrefillStripeTokens)`, which Gemma 4's 2,048-token plain chunk leaves at
its previous value, and Gemma 4 media keeps its 512-token chunk. It does let a
Gemma mixed step carry up to 4,096 prompt tokens beside decode rows. That
working set rides the unchanged activation reserve: the
[2026-10-21 measurements](../reports/2026-10-21-mixed-step-prefill-geometry.md)
put its KV-subtracted peak at eight concurrent 32k-token prompts at 3.73 GiB,
inside the 5.5 GiB default. GPT-OSS and dense Qwen keep 512 / 2,048 by default
because the same geometry lifted their peaks at that load further above their
floors, GPT-OSS from 3.50 to 3.62 GiB against 3.5 and Qwen3.5-9B from 5.73 to
6.03 GiB against 5.5. The live KV gate grants KV up to the cap minus the
reserve (`UnifiedMemoryCap.liveKVHeadroomBytes`), so a peak above the reserve
lands beyond the cap; even the previous geometry reaches both floors at that
load, so they need a long-context re-measurement coordinated with platform
admission. MoE Qwen's peak rose 2.1 GiB (`EngineV2Factory.usesWidePrefillChunk`,
`provider-swift/Sources/ProviderCore/Inference/Engine/Factory/EngineV2Factory+Configuration.swift`).

### Deadline admission rates

First-token deadline admission is a time check, not a memory grant. Its
Expand Down
85 changes: 83 additions & 2 deletions docs/architecture/inference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1126,8 +1126,10 @@ elapsed nanoseconds. Numerics only — never tokens, text or hashes
| Setting | Value in production | Code |
|---|---|---|
| `maxConcurrentRequests` | `engine_v2_max_concurrent` (default and clamp: [`../provider/cli-reference.md#providertoml-keys-read-by-the-cli`](../provider/cli-reference.md#providertoml-keys-read-by-the-cli); per-model map `engine_v2_max_concurrent_by_model`) | `provider-swift/Sources/ProviderCore/Config/ProviderConfig.swift`, `productionSchedulerConfig` |
| `maxBatchedTokensPerStep` / `prefillChunkSize` / `maxWaiting` | 2048 / 512 / 64 (`CBv2SchedulerConfig` init defaults) | `CBv2Contracts.swift`, `CBv2SchedulerConfig` |
| `soloPrefillStripeTokens` | 2048 (`defaultSoloPrefillStripeTokens`); 4096 for dense Qwen3.5/3.8 (`Qwen35Model`, not `Qwen35MoEModel`); `DARKBLOOM_CBV2_SOLO_PREFILL_STRIPE` | `EngineV2Factory+Configuration.swift` |
| `prefillChunkSize` / `maxBatchedTokensPerStep` | 2048 / 4096 (`widePrefillChunkTokens`; the step defaults to twice the chunk) for Gemma 4 (`usesWidePrefillChunk`); 512 / 2048 (`CBv2SchedulerConfig` init defaults) for every other family; `DARKBLOOM_CBV2_PREFILL_CHUNK`, `DARKBLOOM_CBV2_STEP_TOKENS` | `EngineV2Factory+Configuration.swift` (`prefillGeometry`) |
| `maxWaiting` | 64 (`CBv2SchedulerConfig` init default) | `CBv2Contracts.swift`, `CBv2SchedulerConfig` |
| `soloPrefillStripeTokens` | 4096 for dense Qwen3.5/3.8 (`Qwen35Model`, not `Qwen35MoEModel`); 2048 (`defaultSoloPrefillStripeTokens`) for families on the 512-token chunk; none for Gemma 4, because a stripe arms only above the plain chunk; `DARKBLOOM_CBV2_SOLO_PREFILL_STRIPE` | `EngineV2Factory+Configuration.swift` (`soloPrefillStripeTokens`) |
| `bidirectionalMediaPrefillChunkCeiling` | 512 whenever the plain chunk is wider, otherwise unset | `EngineV2Factory+Configuration.swift` (`prefillGeometry`); `CBv2Contracts.swift` (`plainPrefillChunkSize`) |
| `maxConcurrentPartialPrefills` | 1; `DARKBLOOM_CBV2_MAX_PARTIAL_PREFILLS` | `EngineV2Factory+Configuration.swift`, `maxPartialPrefillsKey` |
| Prompt-chunk attention | 128-query blocks (`DARKBLOOM_CBV2_ATTN_QUERY_BLOCK`; paged blocks other than Qwen4 QSA build an absolute mask), bounding the composed score tensor. A full-attention chunk with no window, softcap, vision span or bidirectional mask, whose head_dim MLX fuses (64/72/80/96/128; 256 on NAX from 1024 queries in bf16/fp16), is one `.causal` call on either KV backend (live packed paged KV keeps its own path); `DARKBLOOM_TTFT_FUSED_CAUSAL_PREFILL=0` restores blocks | `libs/mlx-swift-lm/Libraries/MLXLMCommon/ContinuousBatchingV2/AttentionV1.swift` (`usesFusedCausalPrefill`), `libs/mlx-swift-lm/Libraries/MLXLMCommon/ContinuousBatchingV2/Paged/PagedLayerCache.swift` (`prefillAttend`) |
| `enablePrefixCache` | true when the slot has an effective SSD cache, enabled paged resident cache, or recurrent checkpoint-bank configuration, or complete SSD checkpoint store; engine capability gates still apply | `EngineV2Factory+Production.swift` (`assembleProductionBuild`), `EngineV2.swift` |
Expand All @@ -1139,6 +1141,65 @@ elapsed nanoseconds. Numerics only — never tokens, text or hashes
Environment variables are named here, never defaulted; defaults live in
[`../reference/configuration.md`](../reference/configuration.md).

### Prompt geometry

With one partial prefill (`maxConcurrentPartialPrefills`), the plain chunk is
the prompt work a busy engine runs beside its decode rows: a solo stripe never
arms beside an unpaused decode row (`SchedulerV2.plan`). Gemma 4 takes the
2,048-token plain chunk and a 4,096-token step, so a full chunk and a finishing
row's remainder share one step with the decode rows. The wider chunk amortizes
each step's fixed host and readback cost over more prompt tokens and gives MoE
expert GEMMs more rows per expert; a prompt needs a quarter of the mixed steps,
so decode rows also spend more steps without prompt work. The chunk replaces
Gemma 4's 2,048-token stripe rather than exceeding it, so the paged pool's
`maxPrefillChunk` (`max(prefillChunkSize, soloPrefillStripeTokens)`,
`makeSegmentedPagedBackend`) and every windowed-ring KV charge stay unchanged.
The same holds for the GPT-OSS and dense Qwen opt-in below. The trade is
inter-token latency: a decode token that shares a step with prompt work waits
for the whole chunk, so the p90 gap shrinks while the p99 gap grows two to
three times. The
[2026-10-21 measurements](../reports/2026-10-21-mixed-step-prefill-geometry.md)
record the load, engine and memory evidence; the activation effect is in
[hardware support](hardware-support.md#serving-width-by-chip).

Requests with bidirectional media blocks, Gemma 4 images and video frames,
keep the SDK's 512-token plain chunk (`bidirectionalMediaPrefillChunkCeiling`,
`CBv2SchedulerConfig.plainPrefillChunkSize`). A paged span-bearing chunk
attends in one unblocked call whose score tensor grows with the chunk length
times the history (`PagedLayerCache.prefillAttend`); a chunk that begins at a
block still extends over the whole block. Qwen media is causal, attends in
query blocks like text and takes the plain chunk.

Other families keep 512 / 2048 (`usesWidePrefillChunk`):

| Family | Reason |
|---|---|
| GPT-OSS (`GPTOSSModel`), dense Qwen3.5/3.8 (`Qwen35Model`) | Both reached the first token sooner under 2,048 / 4,096, but at eight 32k-token prompts it lifted their KV-subtracted activation peaks further above their floors: GPT-OSS from 3.50 to 3.62 GiB against 3.5, Qwen3.5-9B from 5.73 to 6.03 against 5.5. Floors are measured constants that move only with platform admission. Setting both keys to `2048` and `4096` opts them in. |
| Nemotron 3.5 Lightning, Ternary Bonsai 2 (`MLXVLM.PrismHadamardQwen35`) | Their qualified demanded short checkpoints split only an armed solo stripe (`demandedCheckpointRange`), and the 2,048-token stripe would not exceed a 2,048-token plain chunk. |
| MoE Qwen (`Qwen35MoEModel`) | Its measured activation peak rises about 2 GiB under 2,048 / 4,096, past the default floor at eight 32k-token prompts, and it has no busy-engine TTFT measurement. |
| Qwen3-VL, Qwen4, MiMo and other families | No busy-engine measurement of the wide geometry. MiMo's grouped-prefill, step-owned attention and bounded MTP envelopes grow with the step budget (`EngineV2.init`). |

An explicit `DARKBLOOM_CBV2_PREFILL_CHUNK` applies to every family, and the
step budget follows it unless `DARKBLOOM_CBV2_STEP_TOKENS` is set, except
where a later family policy replaces the geometry. GLM5Next takes its own
2,048-token chunk and step limits and no stripe (`glm5NextServingScheduler`),
and calibrated Nemotron models cap the chunk at their calibrated prefill limit
and drop the stripe (`calibratedPrefillTokenLimit`), both in
`provider-swift/Sources/ProviderCore/Inference/Engine/Factory/EngineV2Factory+Configuration.swift`.
Nemotron Super local serving takes `DARKBLOOM_NEMOTRON_SUPER_PREFILL_CHUNK`
and a step that holds one chunk plus its decode rows
(`provider-swift/Sources/ProviderCore/Inference/Engine/Factory/NemotronSuperLocalPrefill.swift`,
`NemotronSuperLocalPrefill.Policy.apply`). Scheduler-prefill
benchmark receipts record the geometry the engine was actually built with
(`EngineV2Factory.ProductionBuild.prefillGeometry`). Like every
`DARKBLOOM_CBV2_*` key, either override enters the complete-checkpoint
numerics fingerprint (`PrefixCachePolicy.completeCheckpointIdentity`) and
disqualifies reviewed serving and deadline profiles
(`ServingPerformanceProfiles.runtimeOverridesAreAbsent`,
`DeadlineRuntimeEnvironment.permitsQualification`). A solo chunk on Gemma 4
no longer counts toward `soloStripeChunks`, which still counts chunks wider
than `prefillChunkSize`.

### Deadlines

The coordinator's relative first-content budget is anchored once at frame
Expand Down Expand Up @@ -2141,6 +2202,26 @@ or change consumer/OpenRouter routing.
7. MTP is fail-open to target-only decode: artifact resolution failure or
`DARKBLOOM_CBV2_MTP` off never refuses a load — `EngineV2SlotFactory+MTP.swift`,
`MTPContractsV2.swift` (`envEnabled`).
8. Default prompt geometry never widens the largest schedulable chunk or a
bidirectional media chunk: the wide plain chunk equals Gemma 4's former
stripe, and block-bearing requests keep the SDK chunk — `EngineV2Factory+Configuration.swift`
(`usesWidePrefillChunk`, `prefillGeometry`), `SchedulerV2.swift`
(`prefillChunkCap`).
9. A Gemma 4 block chunk never exceeds the `maxPrefillChunk` its windowed
rings hold, although a chunk that starts at a block covers the whole block
and submit validation bounds blocks only by the step budget:
`Gemma4Processor` gives every image and video frame its own
`boi`/`eoi`-delimited block of `image_seq_length` or
`video_processor.max_soft_tokens` soft tokens (280 and 70 by default; the
vision family's largest image budget is 1,120). The default 2,048-token
chunk covers that, and a chunk override that leaves `max(chunk, stripe)`
below 1,120 tokens is raised to 1,120. A step budget below 1,120 is raised
to 1,120 as well, because submit validation refuses a block longer than the
step budget —
`libs/mlx-swift-lm/Libraries/MLXVLM/Models/Gemma4.swift` (`Gemma4Processor`),
`MultimodalV2.swift` (`CBv2MultimodalPlan.validate`),
`EngineV2Factory+Configuration.swift` (`gemma4MaximumMediaBlockTokens`,
`prefillGeometry`).

## Failure modes

Expand Down
8 changes: 7 additions & 1 deletion docs/provider/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,12 @@ The JSON report records `promptMode` (`"rotating"` or `"fixed"`),
seed length. These optional fields extend schema `4`; absent metadata in older
reports remains unspecified. The flag is rejected outside `--scheduler-prefill`
before runtime loading (`provider-swift/Sources/ProviderBenchmark/SchedulerPrefillBenchmark.swift`,
`run`, `makePrompt`, `SchedulerPrefillBenchmarkReport`).
`run`, `makePrompt`, `SchedulerPrefillBenchmarkReport`). Schema `5` adds
`prefillChunkTokens` and `maxBatchedTokensPerStep`; with
`soloPrefillStripeTokens` they record the scheduler the production build handed
the warm-up engine, after serving, calibration and GLM policy
(`EngineV2Factory.ProductionBuild.prefillGeometry`), and a measured engine built
with different geometry fails the run.

Scheduler prefill installs `MLXMemoryGuard.configureOnce` before loading weights,
matching serving and the throughput sweep. Stderr records the selected allocator
Expand Down Expand Up @@ -1751,6 +1756,7 @@ must support the checkpoint contract described in
| `DARKBLOOM_MLX_CACHE_LIMIT_GB` | `provider-swift/Sources/ProviderCore/Inference/Memory/MLXMemoryGuard.swift` (`defaultCacheLimitGB`) |
| `DARKBLOOM_MLX_MEMORY_RESERVE_GB` | `provider-swift/Sources/ProviderCore/Inference/Memory/MLXMemoryGuard.swift` |
| `DARKBLOOM_CBV2_MAX_PARTIAL_PREFILLS` | `provider-swift/Sources/ProviderCore/Inference/Engine/Factory/EngineV2Factory+Configuration.swift` (`maxPartialPrefillsKey`) |
| `DARKBLOOM_CBV2_PREFILL_CHUNK`, `DARKBLOOM_CBV2_STEP_TOKENS` | `provider-swift/Sources/ProviderCore/Inference/Engine/Factory/EngineV2Factory+Configuration.swift` (`prefillChunkKey`, `stepTokenBudgetKey`) |
| `DARKBLOOM_PREFILL_DEADLINE_MODE` | `provider-swift/Sources/ProviderCore/Inference/Engine/PrefillDeadlineMode.swift` (`environmentKey`) |
| `DARKBLOOM_TTFT_ADMISSION_FIXES` | `provider-swift/Sources/ProviderCore/Inference/Performance/Deadline/AdmissionRateEstimators.swift` (`DeadlineAdmissionFixes.environmentKey`) |
| `MLX_GATHER_QMM_EXPERT_SLICES` | only when the shell value is exactly `1` (`GemmaOptimizationEnvironment.daemonDrainPassthrough`, `provider-swift/Sources/ProviderCore/Config/GemmaOptimizationEnvironment.swift`) |
Expand Down
Loading
Loading