mlx-bun 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -32
- package/docs/README.md +58 -42
- package/docs/archive/investigations/benchmark-ledger-through-v0.4.0.md +3617 -0
- package/docs/archive/investigations/openjarvis-fit.md +198 -0
- package/docs/archive/investigations/qwen38-27b-campaign-log.md +1092 -0
- package/docs/archive/planning/release-notes-v0.4.0.md +45 -0
- package/docs/archive/planning/release-notes-v0.5.0.md +37 -0
- package/docs/design/batching.md +1535 -50
- package/docs/design/decode-speed-program.md +394 -1171
- package/docs/design/generic-model-support.md +195 -3
- package/docs/design/kv-cache.md +538 -225
- package/docs/design/speculative-decoding.md +552 -50
- package/docs/design/turboquant.md +140 -17
- package/docs/design/unified-engine-frontier-plan.md +259 -150
- package/docs/planning/PRODUCT_ROADMAP.md +21 -6
- package/docs/planning/public-readiness-handoff.md +244 -0
- package/docs/planning/public-readiness.md +149 -0
- package/docs/reference/benchmarks.md +3537 -1112
- package/docs/reference/cli.md +102 -2
- package/docs/reference/distribution.md +45 -13
- package/docs/reference/environment.md +159 -13
- package/docs/reference/library-api.md +18 -4
- package/docs/reference/memory.md +1 -1
- package/docs/reference/models.md +28 -7
- package/docs/reference/server-api.md +257 -33
- package/docs/reference/server-config.md +372 -151
- package/docs/reference/troubleshooting.md +13 -21
- package/package.json +2 -2
- package/src/audio/audiotoolbox.ts +112 -0
- package/src/audio/conformer.ts +8 -0
- package/src/audio/mic-capture.ts +98 -0
- package/src/audio/silero-vad.ts +379 -0
- package/src/audio/whisper-decode.ts +774 -0
- package/src/audio/whisper-fast.ts +732 -0
- package/src/audio/whisper-format.ts +73 -0
- package/src/audio/whisper-mel.ts +185 -0
- package/src/audio/whisper-timing.ts +274 -0
- package/src/audio/whisper-tokenizer.ts +239 -0
- package/src/audio/whisper-transcribe.ts +410 -0
- package/src/backends/mlx/assistant-target.ts +46 -0
- package/src/backends/mlx/autoregressive-draft-rows.ts +120 -0
- package/src/backends/mlx/autoregressive.ts +22 -1
- package/src/backends/mlx/batch-group.ts +464 -236
- package/src/backends/mlx/cache-attachment.ts +67 -0
- package/src/backends/mlx/cache-layout.ts +31 -0
- package/src/backends/mlx/checkpoint-state.ts +53 -0
- package/src/backends/mlx/continuation-persistence.ts +107 -0
- package/src/backends/mlx/continuation-request.ts +43 -0
- package/src/backends/mlx/continuation.ts +77 -0
- package/src/backends/mlx/draft-target.ts +7 -22
- package/src/backends/mlx/encoder-cache.ts +25 -0
- package/src/backends/mlx/fill-append.ts +21 -8
- package/src/backends/mlx/fill-group.ts +497 -0
- package/src/backends/mlx/full-kv-row-append.ts +32 -0
- package/src/backends/mlx/full-kv-row-donor.ts +54 -0
- package/src/backends/mlx/full-transitioning-kv-rows.ts +65 -0
- package/src/backends/mlx/gateway-binding.ts +122 -19
- package/src/backends/mlx/kv-codec.ts +9 -0
- package/src/backends/mlx/kv-maintenance.ts +161 -0
- package/src/backends/mlx/kv-tensor-rows.ts +212 -0
- package/src/backends/mlx/mixed-iteration.ts +62 -0
- package/src/backends/mlx/model-prompt.ts +46 -32
- package/src/backends/mlx/model-serving.ts +5 -4
- package/src/backends/mlx/paged-cache-codec.ts +27 -0
- package/src/backends/mlx/prefill-cohort.ts +100 -0
- package/src/backends/mlx/prefill-policy.ts +26 -0
- package/src/backends/mlx/prefill-rows.ts +244 -0
- package/src/backends/mlx/prefill.ts +1 -1
- package/src/backends/mlx/projected-context-rows.ts +72 -0
- package/src/backends/mlx/prompt-input.ts +29 -0
- package/src/backends/mlx/qwen-prompt-input.ts +40 -0
- package/src/backends/mlx/request-state-policy.ts +54 -0
- package/src/backends/mlx/rollback.ts +45 -4
- package/src/backends/mlx/row-sampling.ts +49 -0
- package/src/backends/mlx/serial-executor.ts +51 -73
- package/src/backends/mlx/speculative-group.ts +438 -0
- package/src/backends/mlx/speculative-round.ts +161 -0
- package/src/backends/mlx/speculative.ts +24 -7
- package/src/backends/mlx/state-rows.ts +104 -0
- package/src/backends/mlx/state-views.ts +21 -1
- package/src/backends/mlx/target-layout-capability.ts +35 -0
- package/src/backends/mlx/transitioning-kv-rows.ts +173 -0
- package/src/cli.ts +333 -36
- package/src/contracts/execution.ts +21 -0
- package/src/contracts/object-cache.ts +8 -0
- package/src/contracts/pi-provider.ts +1 -1
- package/src/contracts/pi.ts +3 -1
- package/src/contracts/prefix-cache.ts +33 -0
- package/src/contracts/resources.ts +7 -0
- package/src/contracts/sampling.ts +23 -0
- package/src/contracts/scheduling.ts +27 -0
- package/src/engine/execution-plan.ts +38 -25
- package/src/engine/execution-tasks.ts +44 -0
- package/src/engine/namespaced-cache.ts +13 -0
- package/src/engine/resources.ts +12 -1
- package/src/engine/scheduler.ts +32 -7
- package/src/fill/fill-session.ts +14 -3
- package/src/fit.ts +29 -15
- package/src/generate.ts +105 -195
- package/src/grammar.ts +13 -0
- package/src/inference/draft-acceptance.ts +41 -0
- package/src/inference/draft-output.ts +49 -0
- package/src/inference/prefill.ts +6 -0
- package/src/inference/rollback.ts +2 -2
- package/src/kv-scheme.ts +92 -12
- package/src/kv-store.ts +183 -93
- package/src/lab/README.md +5 -1
- package/src/lab/paged-kv/paged-attention.ts +117 -0
- package/src/lab/paged-kv/paged-kv-rows.ts +111 -0
- package/src/lab/paged-kv/paged-kv.ts +126 -46
- package/src/md-modules.d.ts +5 -0
- package/src/mlx/array.ts +39 -1
- package/src/mlx/ffi.ts +19 -0
- package/src/mlx/normalized-argmax.ts +116 -0
- package/src/mlx/ops.ts +97 -10
- package/src/model/artifact-identity.ts +73 -0
- package/src/model/batched-kv.ts +235 -0
- package/src/model/batched-mask.ts +12 -4
- package/src/model/batched-quant.ts +8 -2
- package/src/model/batched-quantized-kv.ts +144 -0
- package/src/model/batched-rotating-quant.ts +76 -15
- package/src/model/batched-rotating-state.ts +76 -0
- package/src/model/batched-rotating.ts +64 -22
- package/src/model/batched-row-storage.ts +52 -0
- package/src/model/batched-ssm.ts +52 -0
- package/src/model/batched-turboquant-kv.ts +94 -0
- package/src/model/compiled-decode.ts +7 -1
- package/src/model/decoded-kv-donor.ts +12 -0
- package/src/model/delayed-quantized-kv.ts +72 -0
- package/src/model/delayed-rotating-quantized-kv.ts +93 -0
- package/src/model/delayed-turboquant-kv.ts +57 -0
- package/src/model/factory.ts +26 -0
- package/src/model/fingerprint.ts +12 -0
- package/src/model/full-prefill-padding.ts +56 -0
- package/src/model/full-prefill-row.ts +105 -0
- package/src/model/gemma4-base.ts +183 -82
- package/src/model/gemma4.ts +116 -28
- package/src/model/generated/gemma4-12b.ts +4 -1
- package/src/model/generated/gemma4-26b.ts +4 -1
- package/src/model/generated/gemma4-e4b.ts +4 -1
- package/src/model/glm52-cache.ts +80 -4
- package/src/model/glm52-mla.ts +12 -6
- package/src/model/glm52.ts +19 -40
- package/src/model/kv-attention-view.ts +70 -0
- package/src/model/minicpm5.ts +11 -7
- package/src/model/profile.ts +29 -4
- package/src/model/quantized-append-attention.ts +31 -0
- package/src/model/qwen3-delta-state.ts +74 -0
- package/src/model/qwen3-delta.ts +59 -36
- package/src/model/qwen3-mrope.ts +7 -9
- package/src/model/qwen3_5.ts +177 -75
- package/src/model/rotating-kv-donor.ts +35 -0
- package/src/model/rotating-kv-layout.ts +262 -0
- package/src/model/rotating-row-transaction.ts +35 -0
- package/src/model/speculative-rotating-kv.ts +101 -0
- package/src/model/ssm-prefill-padding.ts +39 -0
- package/src/model/support.ts +8 -0
- package/src/model/token-groups.ts +66 -0
- package/src/model/trellis-linear.ts +4 -4
- package/src/model/turboquant-codec.ts +89 -0
- package/src/model/universal/dense.ts +14 -13
- package/src/model/whisper.ts +435 -0
- package/src/native/mic_capture.swift +92 -0
- package/src/native-pack.ts +6 -5
- package/src/pi-web.ts +9 -1
- package/src/preflight.ts +31 -15
- package/src/prompt-cache.ts +306 -86
- package/src/runtime-config.ts +1 -5
- package/src/safetensors.ts +9 -2
- package/src/sampler.ts +37 -25
- package/src/serve/audio-routes.ts +323 -0
- package/src/serve/chat-request.ts +2 -0
- package/src/serve/chat-stage.ts +19 -14
- package/src/serve/completion-executor.ts +9 -1
- package/src/serve/discovery-routes.ts +17 -1
- package/src/serve/generated-token-history.ts +57 -0
- package/src/serve/generation-gateway.ts +88 -38
- package/src/serve/model-binding.ts +7 -1
- package/src/serve/model-host.ts +3 -4
- package/src/serve/preparation.ts +3 -3
- package/src/serve/prompt-response-trace.ts +14 -0
- package/src/serve/request-plan.ts +6 -3
- package/src/serve/request-prep.ts +40 -25
- package/src/serve/text-completion-stage.ts +2 -2
- package/src/serve/transcription-server.ts +64 -0
- package/src/serve/transcription-service.ts +502 -0
- package/src/server.ts +185 -261
- package/src/spec/assistant-rows.ts +93 -0
- package/src/spec/assistant-source.ts +28 -18
- package/src/spec/cache-identity.ts +22 -0
- package/src/spec/deepspec-rows.ts +29 -0
- package/src/spec/deepspec-source.ts +12 -10
- package/src/spec/dflash-source.ts +28 -4
- package/src/spec/drafter.ts +153 -142
- package/src/spec/dspark/deepspec-module.ts +95 -120
- package/src/spec/dspark/module-dflash.ts +126 -170
- package/src/spec/glm52-mtp-graph.ts +29 -0
- package/src/spec/glm52-mtp-rows.ts +132 -0
- package/src/spec/glm52-mtp-source.ts +54 -136
- package/src/spec/glm52-mtp-state.ts +33 -0
- package/src/spec/ngram-source.ts +115 -21
- package/src/spec/projected-draft-rows.ts +73 -0
- package/src/spec/qwen-mtp-module.ts +171 -0
- package/src/spec/qwen-mtp-rows.ts +230 -0
- package/src/spec/qwen-mtp-source.ts +84 -226
- package/src/spec/qwen-mtp-state.ts +30 -0
- package/src/spec/serve-loop.ts +73 -69
- package/src/spec/source.ts +93 -15
- package/src/spec/two-model-rows.ts +62 -0
- package/src/spec/two-model.ts +45 -103
- package/src/ssd-cache.ts +107 -36
- package/src/ssd-durability.ts +29 -27
- package/src/storage/host-buffer.ts +24 -0
- package/src/storage/kv-writer.ts +83 -0
- package/src/storage/kv-writer.worker.js +264 -0
- package/src/storage/retention-policy.ts +37 -0
- package/src/tiered-prompt-cache.ts +45 -0
- package/src/vision/embedder.ts +8 -0
- package/src/vision/prompt.ts +101 -65
- package/src/vision/qwen3vl-prompt.ts +101 -64
- package/src/vision/qwen3vl-tower.ts +11 -0
- package/src/vision/siglip.ts +8 -0
- package/src/web/app.html +12 -0
- package/src/web/app.js +217 -57
- package/src/web/src/chat.ts +4 -1
- package/src/web/src/composer.ts +3 -0
- package/src/web/src/voice.ts +141 -0
- package/src/web/sw.js +1 -1
- package/src/backends/mlx/memory-guard.ts +0 -40
- package/src/spec/prefix-state.ts +0 -45
- /package/docs/{planning → archive/planning}/release-notes-v0.3.0.md +0 -0
|
@@ -23,6 +23,39 @@ Sections: [Start flags](#start-flags) · [`--isolate` semantics](#--isolate-sema
|
|
|
23
23
|
· [Fidelity tiers](#fidelity-tiers-and-the-decode-route---l1----l2) · [Feature matrix](#feature-matrix)
|
|
24
24
|
· [Performance & recipes](#performance-characteristics--recipes) · [`GET /stats`](#observability--get-stats).
|
|
25
25
|
|
|
26
|
+
## Configuration ownership
|
|
27
|
+
|
|
28
|
+
CLI presets and explicit flags resolve before model loading. Request preparation
|
|
29
|
+
combines server defaults with request overrides once; explicit request values
|
|
30
|
+
win. A bound execution keeps its immutable runtime snapshot across awaits.
|
|
31
|
+
The tables below own the individual defaults and effective-value rules; this
|
|
32
|
+
map identifies who consumes them.
|
|
33
|
+
|
|
34
|
+
| Settings | Owning interface / implementation | Binding and use |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| Model selection, host/port, isolation, native paths, shutdown | CLI and server host | Startup and process lifecycle; no model-forward policy |
|
|
37
|
+
| Batch capacity, queue/KV budget, prefill cohort budget, `MIXED_PREFILL`, `MIXED_TOKEN_BUDGET` | Scheduling policy and execution group | Choose admission and work size; never choose a codec or sample |
|
|
38
|
+
| Draft kind/model/depth, `DSPARK_MINCONF`, `GRAMMAR_DRAFT_TOKENS` | Draft provider and inference method | Bind provider policy; propose tokens through the shared verifier |
|
|
39
|
+
| `GRAMMAR_BATCH`, `BATCH_SSM`, `QWEN_SPEC_KV4`, compiled/grammar/fill eligibility | Model gateway and execution planner | Resolve supported composition before placement |
|
|
40
|
+
| Temperature, seed, penalties, probability filters, logprobs, `BATCH_VEC_SAMPLE` | Sampling session | Request-owned policy and RNG; selected-token output remains device-backed where supported |
|
|
41
|
+
| Thinking/template defaults, grammar schema, `GRAMMAR`, `TOKEN_MASK` | Chat renderer and grammar controller | Render and compile per request; no scheduling decisions |
|
|
42
|
+
| KV scheme/start/group size, `PAGED_KV`, `PAGED_ATTN`, `TURBOQUANT_FUSED_DECODE` | KV scheme, request-state policy and codec | Capture layout/kernel choice; preserve it through deferred construction and RAM copies |
|
|
43
|
+
| Prompt/SSD budgets, demotion, `SSD_*`, `CACHE_RETENTION`, `SESSION_CACHE`, `MTP_PROMPT_CACHE` | Prefix cache and persistence service | Cache owns residency and session lookup; persistence owns queued storage work |
|
|
44
|
+
| `COMPILED_DECODE`, `COMPILED_GEGLU`, `COMPILED_SWIGLU`, `NO_FUSED_SDPA`, `TRELLIS*`, `MIXED_PACKED_MLP` | Model backend and numerical kernels | Read bound execution policy; select implementations by supported tensor geometry |
|
|
45
|
+
| `RD_PREFILL_CHUNK`, `PREFILL_TAIL_SPLIT`, `EARLY_FIRST_TOKEN`, `BATCH_NO_PIPELINE`, `BATCH_EXTEND` | Prefill/step execution and row state | Preserve method boundaries, output ordering and state ownership; the batch-prefixed names remain compatibility controls |
|
|
46
|
+
| `FILL*`, `GRAMMAR_JUMP` | Fill session or grammar proposal provider | Capture request policy; supported methods consume proposals/appends independently of scheduling |
|
|
47
|
+
| Context limits, checkpoints, media access, trace/debug settings | Request preparation, checkpoint service, media adapter and diagnostics | Each service applies its own options; evaluation-only settings stay in the evaluation adapter |
|
|
48
|
+
|
|
49
|
+
Environment names in this map omit the `MLX_BUN_` prefix. Historical A/B switches
|
|
50
|
+
remain available while their control paths are supported. They are not alternate
|
|
51
|
+
configuration systems. Internal boolean reads use the same `runtimeFlag` port;
|
|
52
|
+
the old `flagOn` wrapper has been removed. CLI aliases remain compatible.
|
|
53
|
+
|
|
54
|
+
Paged request state captures both its cache namespace and its direct-attention
|
|
55
|
+
choice. Changing host settings after binding cannot change later prefetch, lookup,
|
|
56
|
+
publication or cache construction for that request. The same rule applies to
|
|
57
|
+
TurboQuant's fused codec across copies and delayed precision conversion.
|
|
58
|
+
|
|
26
59
|
## Start flags
|
|
27
60
|
|
|
28
61
|
How flags are parsed (`src/cli.ts` `opt`/`flag`/`positional`):
|
|
@@ -65,31 +98,39 @@ oracle. See [Fidelity tiers](#fidelity-tiers-and-the-decode-route---l1----l2).
|
|
|
65
98
|
|
|
66
99
|
### Memory, admission, and caches
|
|
67
100
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
101
|
+
Memory estimates are advisory by default. The server attempts requests without
|
|
102
|
+
rejecting a prompt or shortening `max_tokens` based on predicted GPU headroom.
|
|
103
|
+
`fit` and `/stats.admission.max_safe_context` remain estimates; they do not
|
|
104
|
+
set the default execution limit. Explicit `--memory-budget`, `--kv-budget`,
|
|
105
|
+
and context caps remain opt-in restrictions. GLM-5.2's allocated context
|
|
106
|
+
layout retains its configured capacity.
|
|
107
|
+
|
|
108
|
+
When batch rows finish, full-attention caches drop padding shared by every
|
|
109
|
+
surviving row, matching MLX-LM while preserving each row's absolute position.
|
|
110
|
+
|
|
111
|
+
Qwen prefills longer than four tokens materialize each layer and its cache
|
|
112
|
+
state before continuing, bounding deferred buffer lifetimes. Cache maintenance
|
|
113
|
+
demotes least recently used snapshots under allocator pressure without
|
|
114
|
+
refusing the request. With SSD enabled, an unwritten victim stays in RAM until
|
|
115
|
+
its queued write completes. The RAM target can be exceeded while writes are
|
|
116
|
+
pending or failing;
|
|
117
|
+
it does not promise that every workload fits.
|
|
118
|
+
Actual allocation failures use the ordinary error path when recoverable;
|
|
119
|
+
a native Metal allocation failure can terminate the process.
|
|
120
|
+
Recurrent-cache hits lend independently owned views before any donor is
|
|
121
|
+
reclaimed. The request can advance those views while the original boundary
|
|
122
|
+
remains in RAM or in a completed SSD snapshot. Persistence stays asynchronous.
|
|
82
123
|
|
|
83
124
|
| Flag | Arg | Default | Lane/tier | What it does |
|
|
84
125
|
| --- | --- | --- | --- | --- |
|
|
85
|
-
| `--memory-budget` | GB (decimal, ×10⁹) |
|
|
126
|
+
| `--memory-budget` | GB (decimal, ×10⁹) | unset; memory estimates are advisory | both (per request) | Explicit opt-in budget. Sets the allocator limit and enforces the fit estimate: a prompt leaving no generation slot gets **400** (`type: memory_admission`); a broader completion cap is reduced to the remaining context. Estimates account for active KV quantization and prefill temporaries. Not an aggregate batch cap — see `--kv-budget`. GLM-5.2 also uses this value in its resource plan before loading. |
|
|
86
127
|
| `--kv-budget` | GB (decimal) | off | batch | Aggregate KV budget across concurrently admitted batch rows: a joiner whose projected KV (prompt + `max_tokens`, window-capped) would exceed it **queues** until rows finish; a request over the budget alone is rejected. Without it, N large-context rows can collectively exceed memory. Reported in `/stats.batch.kv_budget_bytes`. |
|
|
87
|
-
| `--prompt-cache` | GB (binary GiB) | `8` | both | RAM prefix-KV
|
|
88
|
-
| `--ssd-cache` | dir | off | both | SSD cold tier under the prompt cache ([docs/design/kv-cache.md](../design/kv-cache.md)): prefix KV spills to disk on RAM eviction and idle demotion, is
|
|
128
|
+
| `--prompt-cache` | GB (binary GiB) | `8` | both | RAM prefix-KV residency target, managed by LRU. `--prompt-cache 0` disables it. RAM hits lend zero-copy views, including recurrent Qwen and method state. With SSD enabled, eviction persists an unwritten donor before removing it from RAM; pending writes can temporarily exceed the target. A successful write alone does not evict RAM. The target does not reserve that much memory. SSD persistence runs in the background; RAM reuse never waits for a write. Explicit cache flush and graceful shutdown report durability, including snapshots lost before persistence. Batch-lane joiners `take()` the longest usable prefix at admission; completed decode publishes reusable processed-token state through the same interface. |
|
|
129
|
+
| `--ssd-cache` | dir | off | both | SSD cold tier under the prompt cache ([docs/design/kv-cache.md](../design/kv-cache.md)): prefix KV spills to disk on RAM eviction and idle demotion, is also persisted after publication by a dedicated CPU worker while inference continues (`MLX_BUN_SSD_WRITEBEHIND=0` disables proactive writes), and **survives restarts**. Entries are keyed by model fingerprint + effective KV scheme + backend numerical identity + tokenizer hash + adapter namespace. MLX includes its runtime version and GPU architecture; older numerical identities use separate directories. `SIGINT`/`SIGTERM` drains active requests and flushes dirty snapshots before exit (`MLX_BUN_SHUTDOWN_TIMEOUT_MS`); `POST /admin/cache/flush` is the explicit boundary. Requires the RAM cache. |
|
|
89
130
|
| `--ssd-cache-max` | GB (binary GiB; `0` = unlimited) | unlimited | both | Optional SSD tier byte cap; oldest-mtime entries are evicted only when a positive cap is configured. Warns and is ignored without `--ssd-cache`. |
|
|
90
131
|
| `--ssd-cache-verify` | (bool) | off | both | Verify every tensor hash on restore (reads all bytes eagerly, defeating lazy fault-in) — integrity paranoia only; the header hash is always verified. Warns and is ignored without `--ssd-cache`. |
|
|
91
|
-
| `--ssd-demote-idle` | seconds | `300` with `--ssd-cache`, else off | both | Prompt-cache entries unused this long spill to the SSD tier and free their GPU memory; the next hit restores them.
|
|
92
|
-
| `--generation-checkpoint` | output tokens | off |
|
|
132
|
+
| `--ssd-demote-idle` | seconds | `300` with `--ssd-cache`, else off | both | Prompt-cache entries unused this long spill to the SSD tier and free their GPU memory; the next hit restores them. The cache sweeps by entry age independently of scheduler activity; RAM remains resident until SSD coverage exists. `0` disables. Warns and is ignored without `--ssd-cache`. |
|
|
133
|
+
| `--generation-checkpoint` | output tokens | off | qualified requests | Queues an owned in-flight generation snapshot every N emitted tokens. Repeating the identical request after a restart replays the saved assistant prefix and continues from its already-sampled next token. Requires `--ssd-cache`. Shared execution qualifies ordinary requests with supported row-cache layouts, including Qwen, Llama, MiniCPM and Gemma4, with or without adapters, excluding media, grammar, fill, paging, logprobs or speculative methods; existing serial qualification remains available. Explicit cache flush drains queued writes. Completed generations remove their checkpoint, while client cancellation preserves the latest checkpoint. |
|
|
93
134
|
|
|
94
135
|
Generation checkpoint identity includes stop strings, sampling/KV policy, the
|
|
95
136
|
resolved execution method, compiled/grammar policy, and artifact/implementation
|
|
@@ -100,22 +141,55 @@ identity. MLX runtime or GPU architecture changes select a fresh cache
|
|
|
100
141
|
directory and leave the previous directory intact. A different backend codec
|
|
101
142
|
identity refuses incompatible files. Adapter namespaces include the mounted weight contents and
|
|
102
143
|
scale, so a changed adapter starts with a fresh prefix and checkpoint.
|
|
103
|
-
Native media and grammar preparation
|
|
104
|
-
|
|
105
|
-
|
|
144
|
+
Native media and grammar preparation uses the backend execution lease between
|
|
145
|
+
decode iterations when the backend supports queued preparation. Exclusive model
|
|
146
|
+
changes retain drain priority. Media downloads and container transcoding run
|
|
147
|
+
outside that lease; a slow remote URL does not hold up decode. Preparations
|
|
148
|
+
retain a reservation through request
|
|
149
|
+
completion. Gemma4 and Qwen shared serving can retain up to `--batch` media preparations;
|
|
150
|
+
other media bindings retain one. Grammar preparation retains up to `--batch`. Generation and preparation
|
|
106
151
|
queues each allow 64 waiting requests; overflow returns `429` before a response
|
|
107
152
|
stream opens, or a terminal stream error after it opens. Disconnects release
|
|
108
153
|
queued reservations and completed preparation resources.
|
|
109
154
|
|
|
155
|
+
Ordinary requests in the continuous scheduler can join an ongoing prefill
|
|
156
|
+
between chunks when their execution context is compatible and batch capacity
|
|
157
|
+
is available. Scheduling also budgets the initial prefill work in a cohort, so
|
|
158
|
+
long prompts can be prepared one at a time through the continuous executor
|
|
159
|
+
while decode remains batched. Subsequent forwards process real-token chunks from admitted requests
|
|
160
|
+
together. Each request keeps its own cache-maintenance and checkpoint boundaries.
|
|
161
|
+
Arrival timing can change batch geometry and near-tie generated text. Qwen MTP,
|
|
162
|
+
prompt lookup and standalone drafting use the same target prefill driver.
|
|
163
|
+
Their providers prepare companion state through a separate interface;
|
|
164
|
+
scheduling determines admission and work budgets.
|
|
165
|
+
|
|
110
166
|
Disconnected serial requests leave the admission queue immediately. Active AR
|
|
111
167
|
requests check cancellation between prefill chunks and decode steps; a native
|
|
112
168
|
operation already running completes before that boundary.
|
|
113
169
|
|
|
170
|
+
|
|
171
|
+
Qwen image/video and Gemma image/audio encoder features use the existing
|
|
172
|
+
prompt-cache RAM budget and, when configured, its SSD persistence layer.
|
|
173
|
+
Exact encoder-weight, computation-setting and input hashes identify reusable
|
|
174
|
+
features; each request still renders its own tokens, timestamps, masks and
|
|
175
|
+
positions. Qwen hashes prepared pixels and grids; Gemma hashes image/WAV bytes
|
|
176
|
+
within each encoder's versioned schema. No separate media-cache capacity is
|
|
177
|
+
allocated. `--prompt-cache 0` disables retention. CPU preprocessing and media
|
|
178
|
+
extraction still run before feature lookup, outside the native execution queue.
|
|
179
|
+
Encoder reuse is independent of batch/method selection. Experimental Gemma
|
|
180
|
+
media KV reuse is controlled by `MLX_BUN_MEDIA_PREFIX_CACHE` below. Cache counters
|
|
181
|
+
are documented in [server-api.md](server-api.md).
|
|
182
|
+
|
|
183
|
+
|
|
114
184
|
### Runtime isolation
|
|
115
185
|
|
|
116
186
|
| Flag | Arg | Default | Lane/tier | What it does |
|
|
117
187
|
| --- | --- | --- | --- | --- |
|
|
118
188
|
| `--isolate` | (bool) | off | both | Run the inference engine as a **child process** on a unix socket while this process owns CPU application routes and proxies inference — instant under any GPU load, survives engine crashes (auto-respawn). Full semantics in [`--isolate` semantics](#--isolate-semantics). |
|
|
189
|
+
| `--whisper-model` | path \| query | first downloaded `whisper` checkpoint, resolved on the first `/v1/audio/*` request | both | Whisper checkpoint served beside the chat model for [audio transcription](server-api.md#post-v1audiotranscriptions--post-v1audiotranslations-speech-to-text). Serving a Whisper checkpoint as the MAIN model (`serve mlx-community/whisper-large-v3-turbo`) starts a **transcription-only server** (audio routes, `/v1/models`, `/health`, `/stats`; no chat model, no prompt cache). |
|
|
190
|
+
| `--whisper-idle-unload` | seconds | `0` | both | How long the Whisper weights (and MLX's allocator cache) stay after a take. Default `0`: released right after every take, so the chat model has the memory back before it prefills the dictated prompt; the process drops by ≈1.4 GB and the next take pages them back in from the OS file cache (a cold 11 s take is ≈520 ms vs 365 warm on the M1 Max, `TranscriptionService`). Reported per response in `mlx_bun.timings.load_ms`. |
|
|
191
|
+
| `--whisper-resident` | flag | off | both | Never dispose the Whisper weights (sotto's always-loaded behaviour). |
|
|
192
|
+
| `--preload` | flag | off | both | Transcription-only server: load the Whisper weights before listening instead of on the first request. |
|
|
119
193
|
| `--model-pool` | n (≥1) | `1` | both | With `--isolate`: max **resident** model engines. A request whose `model` field is an **exact** `/v1/models` id spawns/routes to that model's own engine child (spawn-overlap: the new model loads while the old keeps serving). Over the cap the least-recently-used engine is drained (`POST /admin/drain` over its socket), demotes its prompt cache to the SSD tier, and exits; switching back respawns it with state restored from disk. Without `--isolate` the flag warns and is ignored. |
|
|
120
194
|
|
|
121
195
|
### Scheduling
|
|
@@ -128,39 +202,65 @@ operation already running completes before that boundary.
|
|
|
128
202
|
|
|
129
203
|
| Flag | Arg | Default | Lane/tier | What it does |
|
|
130
204
|
| --- | --- | --- | --- | --- |
|
|
131
|
-
| `--kv-quant` | `config` \| `off` \| `4` \| `8` \| `turbo[:k<bits>v<bits>]` | `off` (bf16) | see row | KV-cache quantization. `off` = bf16 (the L1 default: quantized KV measured 5–20% slower decode than bf16 at ≤16k on both stacks, so it is an opt-in that buys **memory headroom**). `4`/`8` = **uniform** bits (group 64, start 0 — mlx-lm's `--kv-bits` scheme); with fused-sdpa off (the default for uniform) our unfused quantized SDPA is op-for-op mlx-lm's `quantized_scaled_dot_product_attention`, so uniform is **bit-exact L1**; uniform requests
|
|
132
|
-
| `--paged-kv` | (bool) | off |
|
|
133
|
-
| `--paged-kv-block-size` | n | `256` |
|
|
205
|
+
| `--kv-quant` | `config` \| `off` \| `4` \| `8` \| `turbo[:k<bits>v<bits>]` | `off` (bf16) | see row | KV-cache quantization. `off` = bf16 (the L1 default: quantized KV measured 5–20% slower decode than bf16 at ≤16k on both stacks, so it is an opt-in that buys **memory headroom**). `4`/`8` = **uniform** bits (group 64, start 0 — mlx-lm's `--kv-bits` scheme); with fused-sdpa off (the default for uniform) our unfused quantized SDPA is op-for-op mlx-lm's `quantized_scaled_dot_product_attention`, so uniform is **bit-exact L1**; uniform requests use shared B=1/B>1 execution where the loaded cache layout supports affine conversion. `config` = **per-layer mixed precision** from the model's `kv_config.json` — optiq-only → **L2**; per-layer configs **batch** on every shipped model (full-attention and rotating layers; gated bit-exact per row vs the serial composition). `turbo[:k<bits>v<bits>]` = **TurboQuant** ([docs/design/turboquant.md](../design/turboquant.md)): rotation-based KV quantization, default `k8v3`; `kBits` ∈ {2,4,5,8}, `vBits` ∈ {2,3,4,5,8}; a separate axis (mutually exclusive with `config`/`4`/`8`), uses the existing decoded or deferred rotated-value attention path, **full-attention layers only** (sliding-window layers stay bf16 with a one-time warning), refuses head dims outside `TURBOQUANT_HEAD_DIMS`, and supports shared ordinary and grouped drafting execution at B=1/B>1 including positive library conversion thresholds when the cache layout qualifies. Any explicit `--kv-quant` overrides the tier preset. |
|
|
206
|
+
| `--paged-kv` | (bool) | off | shared / optional | Full-attention block pools through the common cache-layout and attention interfaces. Supports bf16 and uniform affine `--kv-quant 4|8`; affine pages encode from their first token. Default attention gathers into stock SDPA; `MLX_BUN_PAGED_ATTN=1` selects the experimental direct Metal reader. RAM/SSD reuse uses a separate numerical namespace. Gemma4-family only; draft models, per-layer KV schemes and TurboQuant pages remain unsupported. Media/adapter requests retain their existing non-paged behavior. Env mirror `MLX_BUN_PAGED_KV=1`. |
|
|
207
|
+
| `--paged-kv-block-size` | n | `256` | shared | Tokens per KV block (`--paged-kv` only); 256 = the plain cache's growth step. |
|
|
134
208
|
|
|
135
209
|
### Adapters and speculative decoding
|
|
136
210
|
|
|
137
|
-
Qwen MTP
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
RAM
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
`
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
211
|
+
In v0.4.0, Qwen MTP publishes aligned target/draft
|
|
212
|
+
prefill snapshots through the shared prompt cache by default. The RAM budget
|
|
213
|
+
includes the draft KV and pending hidden row; configured SSD persistence
|
|
214
|
+
queues those tensors with the target state and supports reuse after restart.
|
|
215
|
+
RAM hits retain immutable snapshots for later requests. Target, draft-weight,
|
|
216
|
+
adapter-revision and KV-policy identities separate incompatible state.
|
|
217
|
+
`usage.cached_tokens` reports the reused target prefix.
|
|
218
|
+
`MLX_BUN_MTP_PROMPT_CACHE=0` disables this reuse. Completed decode also
|
|
219
|
+
publishes checkpoints for processed tokens through the same cache.
|
|
220
|
+
Long-conversation performance acceptance remains open.
|
|
221
|
+
|
|
222
|
+
Uniform KV4 attention automatically groups three query heads for the key
|
|
223
|
+
multiplication on M4 Pro when B≤2, L=3, GQA6/D256, N≥8192 and bf16/f32
|
|
224
|
+
match the qualified shape. Masking, softmax and value multiplication retain
|
|
225
|
+
their existing geometry. This internal selection needs no additional flag;
|
|
226
|
+
other shapes and machines keep the existing implementation. Exactness and
|
|
227
|
+
timing evidence are in [benchmarks.md](benchmarks.md#three-query-affine-attention-head-grouping).
|
|
228
|
+
|
|
229
|
+
In v0.4.0, Qwen uniform affine KV4 with
|
|
230
|
+
`quantizedKvStart=0` supports configured speculative execution by default.
|
|
231
|
+
`MLX_BUN_QWEN_SPEC_KV4=0` restores the ordinary-decode compatibility control. Recurrent state and draft KV keep their original precision. Shared Qwen MTP
|
|
232
|
+
also supports bf16, uniform KV8 and TurboQuant at start zero; per-layer mixed
|
|
233
|
+
KV remains incompatible. Strict legacy serial speculation retains bf16/KV4.
|
|
234
|
+
The KV4 control does not disable bf16, KV8 or TQ shared speculation. Six paired M4 Pro combined suites and two completed Kanban tasks support
|
|
235
|
+
this default. Configuring a drafter and selecting KV4 remain explicit choices.
|
|
236
|
+
|
|
237
|
+
The shared prefill policy selects a chunk once per request. The usual size is
|
|
238
|
+
2,048 tokens. For recurrent-attention models with materialized SDPA scores,
|
|
239
|
+
it halves that size until the estimated per-layer score workspace is at most
|
|
240
|
+
1 GiB (minimum eight queries, where native fused decode attention applies).
|
|
241
|
+
Qwen3.8-27B therefore uses 2,048 at 10,398 prompt tokens and 256 at 78,678.
|
|
242
|
+
This changes the work size; it does not reject or shorten the request.
|
|
243
|
+
Ordinary and speculative execution consume the same bound policy.
|
|
244
|
+
|
|
245
|
+
`MLX_BUN_RD_PREFILL_CHUNK` selects an explicit fixed chunk. A group option
|
|
246
|
+
supersedes the environment, and a library request's `prefillChunkSize`
|
|
247
|
+
supersedes either. Explicit values bypass the automatic choice.
|
|
248
|
+
`MLX_BUN_RD_CONTEXT_LIMIT` sets an explicit request context cap
|
|
249
|
+
without enlarging it. Both controls require positive integers; the context
|
|
250
|
+
cap is unset by default. Sampling and the published model context remain
|
|
251
|
+
independent of prefill chunk selection. To reproduce a seeded response, keep
|
|
252
|
+
the prefill chunk policy fixed along with the model, runtime, machine and
|
|
253
|
+
sampling settings. Changing chunk boundaries can change numerical results
|
|
254
|
+
and the sampled continuation. The [Kanban comparison](benchmarks.md#full-kanban-after-decode-integration)
|
|
255
|
+
records this effect on the same M4 Pro with identical initial request JSON.
|
|
156
256
|
|
|
157
257
|
| Flag | Arg | Default | Lane/tier | What it does |
|
|
158
258
|
| --- | --- | --- | --- | --- |
|
|
159
|
-
| `--adapter` | dir | none |
|
|
160
|
-
| `--draft-model` | path \| query | none |
|
|
161
|
-
| `--draft-kind` | `two-model` \| `assistant` \| `dspark` \| `deepspec` \| `mtp` \| `ngram` | auto | serial | Override drafter detection. `mtp` = a native multi-token-prediction head split from the target's release (`*_mtp` model_type; shares the target's embeddings/lm-head, defaults `--num-draft-tokens` to its trained `block_size − 1`, rolls DeltaNet caches back by snapshot/replay on partial rejects); `mtp` alone mounts the companion bundled at `<model>/mtp/` when present. Qwen MTP companions accept dense or affine-quantized projections using their checkpoint metadata; changing the draft can change acceptance and speed. `ngram` = **model-free prompt lookup** (drafts copied from the request's own prompt+generation; port of prompt-lookup decoding / vLLM's `ngram` proposer) — mount it **alone** (`--draft-kind ngram` with a `--draft-model` is refused, as is any other kind without one); lossless by the same verify, a no-match round degrades to one plain target step. Any other value fails startup. |
|
|
162
|
-
| `--num-draft-tokens` | n (integer ≥ 1) | `3` (`ngram`: `10`; DSpark: pinned ≤ its trained `gamma`) |
|
|
163
|
-
| `--ngram-max` / `--ngram-min` | k (integer ≥ 1) | `3` / `1` | serial | `--draft-kind ngram` only: longest/shortest trailing k-gram searched (longest first, first occurrence wins). `--ngram-min` > `--ngram-max` fails startup; either flag without `ngram` warns and is ignored. |
|
|
259
|
+
| `--adapter` | dir | none | compatible adapter groups | Mount a LoRA adapter at startup (same machinery as `POST /v1/adapters`; the id is the directory basename) and make it the default for requests without an `adapter` field. A request's explicit `adapter` — including `"none"` — wins; hot-swap via `/v1/adapters` is unchanged. A bad adapter fails startup. Alias `--adapter-path`. |
|
|
260
|
+
| `--draft-model` | path \| query | none | shared Qwen methods; full-attention/rotating lookup/standalone and Gemma assistant/DeepSpec/DSpark; other combinations serial | **Speculative decoding**: a drafter proposes tokens the target verifies in one forward — exact results, faster decode when drafts land. Resolves like the main model. Kind is auto-detected: a full same-tokenizer model (mlx_lm.server parity, L1 token-for-token; tokenizer-family mismatch fails startup), a Gemma `-assistant` KV-borrowing drafter (L2 vs optiq `spec_generate`), a locally trained **DSpark** checkpoint (`dspark.json`), or a released DeepSpec `Gemma4DSparkModel` drafter. Qwen MTP, prompt lookup and standalone drafting use the shared executor at one or several active rows, including logprobs. Supported full-attention and rotating targets, including Llama, MiniCPM and Gemma, also share bf16, uniform KV4/KV8 or per-layer affine KV or TurboQuant prompt lookup and standalone drafting. Rotating target transactions retain different accepted lengths across the sliding window and publish paired RAM/SSD state. Gemma assistant drafting shares the same execution at B1/B>1 with bf16, uniform KV4/KV8 or per-layer affine KV or TurboQuant target storage. Its hidden-state companion and target KV use the RAM/SSD cache; donor attention owns row validity while the assistant graph stays independent of storage. DeepSpec and DSpark share bf16, uniform KV4/KV8 or per-layer affine KV or TurboQuant target execution and projected-context RAM/SSD companions. DeepSpec supports bf16 or affine-quantized draft weights; DSpark supports its Markov/RNN heads. Confidence selects each row's proposal length independently. Other provider/target combinations still run serial. Unsupported speculative compositions use ordinary execution when their own features support it. Composes with structured output; Qwen MTP, prompt lookup, standalone, Gemma assistant, DeepSpec and DSpark drafting use the shared RAM/SSD prefix cache by default (`MLX_BUN_MTP_PROMPT_CACHE=0` disables); other speculative sources start fresh. Telemetry: `usage.speculation`. |
|
|
261
|
+
| `--draft-kind` | `two-model` \| `assistant` \| `dspark` \| `deepspec` \| `mtp` \| `ngram` | auto | shared Qwen methods; full-attention/rotating lookup/standalone and Gemma assistant/DeepSpec/DSpark; other combinations serial | Override drafter detection. `mtp` = a native multi-token-prediction head split from the target's release (`*_mtp` model_type; shares the target's embeddings/lm-head, defaults `--num-draft-tokens` to its trained `block_size − 1`, rolls DeltaNet caches back by snapshot/replay on partial rejects); `mtp` alone mounts the companion bundled at `<model>/mtp/` when present. Qwen MTP companions accept dense or affine-quantized projections using their checkpoint metadata; changing the draft can change acceptance and speed. `ngram` = **model-free prompt lookup** (drafts copied from the request's own prompt+generation; port of prompt-lookup decoding / vLLM's `ngram` proposer) — mount it **alone** (`--draft-kind ngram` with a `--draft-model` is refused, as is any other kind without one); lossless by the same verify, a no-match round degrades to one plain target step. Any other value fails startup. |
|
|
262
|
+
| `--num-draft-tokens` | n (integer ≥ 1) | `3` (`ngram`: `10`; DSpark: pinned ≤ its trained `gamma`) | method-dependent | Drafts per verify round (mlx_lm.server's default; `mlx_lm.generate`'s is 2). |
|
|
263
|
+
| `--ngram-max` / `--ngram-min` | k (integer ≥ 1) | `3` / `1` | Qwen and full-attention targets shared / other models serial | `--draft-kind ngram` only: longest/shortest trailing k-gram searched (longest first, first occurrence wins). `--ngram-min` > `--ngram-max` fails startup; either flag without `ngram` warns and is ignored. |
|
|
164
264
|
| `--mtp` | `on` \| `off` | `on` for GLM-5.2 | serial+spec | GLM-5.2 checkpoint-native MTP row as the server's drafter, using the bounded auxiliary expert tier and the exact serial verify loop (`usage.lane: "serial+spec"`). `off` removes the draft so ordinary GLM requests can use continuous batching. Other model families ignore it. |
|
|
165
265
|
| `--context-length` | tokens (integer ≥ 1) | `4096` (GLM-5.2) | both | Context reserved by GLM-5.2's header-only resource equation; also the request-admission ceiling, reported in `/stats.glm52`. An impossible plan fails before committing model memory. Ignored by other families. |
|
|
166
266
|
|
|
@@ -172,18 +272,25 @@ profile or sampling policy.
|
|
|
172
272
|
| `--temperature` | n ∈ [0, 5] | `generation_config.json`, else `0.7` | both | Server-wide sampling default; a per-request `temperature` wins; the browser chat (sends none) inherits it. Alias `--temp` (mlx_lm.server spelling — note its *default* there is `0.0`; pass `--temp 0` for that behavior). |
|
|
173
273
|
| `--top-p` | n ∈ [0, 1] | `generation_config.json`, else `0` (off) | both | Server-wide top-p default (per-request `top_p` wins). |
|
|
174
274
|
| `--top-k` | n ∈ [0, 1e6] | `generation_config.json`, else `0` (off) | both | Server-wide top-k default (per-request `top_k` wins). |
|
|
175
|
-
| `--max-tokens` | n ∈ [1, 1e7] | GLM-5.2: `128` (memory-plan reservation); otherwise none —
|
|
275
|
+
| `--max-tokens` | n ∈ [1, 1e7] | GLM-5.2: `128` (memory-plan reservation); otherwise none — an omitted cap generates until EOS/stop or an explicitly configured limit | both | Completion cap when a request omits `max_tokens` (mlx_lm.server flag). DEVIATION when unset: `mlx_lm.server` stops a defaulted request at 512 — `--max-tokens 512` reproduces it. For GLM-5.2 the value is also reserved by the pre-open resource equation and must fit inside `--context-length`. Note: `max_tokens` also feeds `--kv-budget` row projections (prompt + cap), so an uncapped request cannot fit a finite explicit KV budget; set `--max-tokens` or send a request cap when using that budget. |
|
|
176
276
|
| `--hlg-sampling` | `on`\|`off` | off | serial / Lab | Piecewise tone-curve (HLG) sampling: rolls off the top-token region, boosts the mids, gentles the tail; the gain folds from `--temperature`. Design: [docs/archive/hlg-sampling.md](../archive/hlg-sampling.md). |
|
|
177
277
|
| `--hlg-width` | nats ∈ [0, 100] | `4` | serial | HLG mid-region half-width. Only with `--hlg-sampling on`. |
|
|
178
278
|
| `--hlg-shoulder` | nats ∈ [0, 100] | `4` | serial | HLG highlight rolloff scale. Only with `--hlg-sampling on`. |
|
|
179
279
|
| `--hlg-toe` | nats ∈ [0, 100] | `6` | serial | HLG shadow rolloff scale. Only with `--hlg-sampling on`. |
|
|
180
280
|
| `--hlg-pivot-offset` | nats ∈ [0, 100] | `6` | serial | HLG pivot: nats below the top token. Only with `--hlg-sampling on`. |
|
|
181
281
|
|
|
282
|
+
Greedy sampling without requested logprobs uses a shared normalized-selection
|
|
283
|
+
kernel after applying penalties and grammar masks. It preserves dtype-rounded
|
|
284
|
+
scores and lowest-ID ties while avoiding a full normalized vocabulary output.
|
|
285
|
+
Independent speculative verification uses the same operation. Requests needing
|
|
286
|
+
logprobs, stochastic sampling or a custom sampler keep their existing operations;
|
|
287
|
+
no new flag is required. Measurements are in [benchmarks](benchmarks.md#fused-normalized-greedy-selection).
|
|
288
|
+
|
|
182
289
|
### Media and UX
|
|
183
290
|
|
|
184
291
|
| Flag | Arg | Default | Lane/tier | What it does |
|
|
185
292
|
| --- | --- | --- | --- | --- |
|
|
186
|
-
| `--allow-private-media` | (bool) | off |
|
|
293
|
+
| `--allow-private-media` | (bool) | off | both (model-qualified media) | Let `image_url`/`audio_url`/`video_url` parts fetch from **private/loopback/link-local** hosts. Off by default: a request's URL is attacker-controlled, so `src/media-fetch.ts` refuses non-http(s) schemes and private/loopback/link-local/CGNAT destinations — including hosts that *resolve* there and every redirect hop (SSRF guard). Independent of the flag, every remote fetch has a 10 s timeout and a 64 MB streaming-enforced cap; violations are clean `400`s. `data:` URLs are never policy-checked. Env mirror `MLX_BUN_ALLOW_PRIVATE_MEDIA=1`. |
|
|
187
294
|
| `--no-open` | (bool) | off | both | Skip the automatic browser open. By default an interactive TTY opens `http://<host>:<port>/#/chat` once the server is ready; non-TTY runs never open. Parent-only under `--isolate`. |
|
|
188
295
|
|
|
189
296
|
### Parity tier and kill switches
|
|
@@ -217,14 +324,20 @@ mlx-bun serve <model> --temp 0 --top-p 0 --top-k 0 --max-tokens 512 --batch 1
|
|
|
217
324
|
`generation_config.json` (we inject its sampling defaults, optiq-style);
|
|
218
325
|
its unset-request defaults are temperature 0.0, top-p/top-k off.
|
|
219
326
|
- `--max-tokens 512` — its cap when a request omits `max_tokens` (ours is
|
|
220
|
-
none: run to EOS or
|
|
221
|
-
|
|
222
|
-
moves the stopping point and `finish_reason`.
|
|
327
|
+
none: run to EOS/stop or an explicit operator limit). The cap changes the stopping
|
|
328
|
+
point and `finish_reason`.
|
|
223
329
|
- `--batch 1` — strict serial, arrival-independent numerics. (`--batch N`
|
|
224
330
|
is itself bit-parity with mlx-lm at B=N; pin 1 for golden regeneration.)
|
|
225
331
|
- Already matching without flags: host/port, bf16 KV (`--kv-quant off`),
|
|
226
332
|
the L1 kernel preset (`--l1` is the default), logprobs caps, error text.
|
|
227
333
|
|
|
334
|
+
These flags align sampling and caps. Exact generated trajectories also need
|
|
335
|
+
matching prefill and cache boundaries. Stock MLX-LM HTTP splits system and
|
|
336
|
+
thinking segments before reserving the final token. Different forward shapes
|
|
337
|
+
can change near-tie greedy choices even inside the same Python model.
|
|
338
|
+
The benchmark's explicit `--reference-prefill unsplit` control and the saved
|
|
339
|
+
MiniCPM/Qwen investigation are documented in [benchmarks.md](benchmarks.md).
|
|
340
|
+
|
|
228
341
|
The kill switches are bit-exact A/B levers; **the naked default is the L1
|
|
229
342
|
set** (2026-07-05: an output-changing lever earns a default only by beating
|
|
230
343
|
the L1 baseline in a paired A/B, and none did — the losing kernels were
|
|
@@ -336,7 +449,7 @@ chat stage (`src/serve/chat-stage.ts`). Full field list: [server-api.md](./serve
|
|
|
336
449
|
All `MLX_BUN_*` variables are captured once at process start into an
|
|
337
450
|
immutable snapshot (`src/runtime-config.ts`); CLI flags install overrides
|
|
338
451
|
into the same snapshot before the model loads. Boolean levers read the
|
|
339
|
-
literal strings `"1"`/`"0"` — `
|
|
452
|
+
literal strings `"1"`/`"0"` — `runtimeFlag` treats any other value as unset.
|
|
340
453
|
Under `--isolate` the whole environment is inherited by the engine child.
|
|
341
454
|
|
|
342
455
|
### Serving levers (flag-backed and lane kill switches)
|
|
@@ -344,23 +457,28 @@ Under `--isolate` the whole environment is inherited by the engine child.
|
|
|
344
457
|
| Env var | CLI flag | Default | Effect |
|
|
345
458
|
| --- | --- | --- | --- |
|
|
346
459
|
| `MLX_BUN_COMPILED_DECODE` | `--compiled-decode` | on (`"0"` disables) | Compiled decode graph replay (serial lane; batch lane at B=1). |
|
|
347
|
-
| `
|
|
348
|
-
| `
|
|
460
|
+
| `MLX_BUN_MEDIA_PREFIX_CACHE` | (env only) | on (`=0` disables) | Reuse prepared Gemma image/audio or Qwen image/video conversation KV in the shared executor. Media contents, encoder identity and preceding tokens scope the ordinary RAM/SSD cache. Generated follow-ups reuse state; rewinds before a delayed-precision boundary recompute. Qwen recurrent layers require an exact retained prefix. Explicit serial retains encoder-only reuse. |
|
|
461
|
+
| `MLX_BUN_MIXED_PREFILL` | — | off (`=1`) | Lab mixed prefill/decode execution for Gemma 4 and Qwen3.5/3.8 text groups, including grouped speculative methods. The scheduler reserves running tokens before prompt work; the model packs feed-forward operations across real tokens while attention and KV state retain their original group geometry. Methods supply candidate-token demand and per-group hidden taps; speculative verification preserves its existing matmul geometry. Packed matmuls can select different kernels from solo decode; this does not claim solo-logit identity or a measured serving win. |
|
|
462
|
+
| `MLX_BUN_MIXED_PACKED_MLP` | — | on (`=0` disables) | Lab control inside mixed model work: disable feed-forward packing while keeping the same scheduling budget and attention geometry, to measure packing separately from chunk scheduling. No effect when mixed execution is off. |
|
|
463
|
+
| `MLX_BUN_MIXED_TOKEN_BUDGET` | — | `256` | Total real tokens in an enabled mixed iteration, including running decode rows. At least one token per participating row progresses. A lone preparation retains its existing chunk setting. Precision transitions and checkpoint endpoints remain method-owned. |
|
|
464
|
+
| `MLX_BUN_EARLY_FIRST_TOKEN` | — | on (`=0` disables) | Eligible ordinary generation yields token zero before constructing the next decode step; later decode remains pipelined. The continuous scheduler yields after preparation creates its first active row when no other request is queued, allowing prepared output to flush before decode. It then rechecks cancellation, admission and shutdown; queued short admissions still group together. Serial fill, grammar, checkpoint resume and single-token budgets retain their existing order. If a native consumer stops at the first yield and retains caller-owned caches, a non-aborted return completes that token’s M=1 forward before returning the cache, preserving the ordinary pipeline’s boundary for prefix reuse. Aborted requests do not start another forward; generation-owned caches need no alignment. The setting is captured by generation and the batch runtime. Native M1/M4 state and continuation, HTTP cancellation/overlap and cached/SSD gates pass. Monitored paired chat measurements support earlier visible output; they do not establish higher decode throughput, and an invisible token zero need not improve client latency. See benchmarks.md. |
|
|
465
|
+
| `MLX_BUN_TURBOQUANT_FUSED_DECODE` | — | on (`=0` disables) | Packed K/V decode fusion for an existing `--kv-quant turbo:...` cache, captured when each cache is created. A shared Metal operation unpacks keys and values, applies the existing key zero/scale and Lloyd-Max value scale, and preserves the codec's eager or deferred inverse rotation. It accepts supported bit widths, head dimensions 64/128/256/512 and 32/64-element groups with fp16/bf16/f32 metadata. Eager k8v3 with B1/H4, head dimension 256, fp16 metadata, group32 and at least 8192 cached tokens also fuses inverse rotation; other shapes keep the existing rotation path. Unsupported inputs, CPU streams and shapeless traces retain ordinary operations. Quantization, stored cache format and serving eligibility are unchanged. Joint-decoder Qwen native/serial and repeated long-context HTTP gates pass. The inverse operation passes both integrated Qwen model gates and six HTTP pairs per quant. MiniCPM/Gemma deferred-consumer serving gates also pass. The shared codec/layout supports ordinary and supported drafting groups without changing this kernel selection. Gemma now owns pre-write row positions across cache appends; the fix passes native checks on both Macs. The combined fused-k8v3/MTP3 pressure fixture passes on M4 and M1 with exact responses/usage and durable SSD writes. Codec policy is resolved once for ordinary, batched and delayed caches; `=0` retains the unfused control. This does not enable TurboQuant quantization itself: `--kv-quant` remains a separate choice. |
|
|
349
466
|
| `MLX_BUN_NO_FUSED_SDPA` | `--fused-sdpa` (inverted) | follows `--kv-quant` | `=1` forces the stock unfused SDPA everywhere. |
|
|
350
467
|
| `MLX_BUN_COMPILED_GEGLU` | `--compiled-activations` | on (`"0"` disables) | Gemma geglu via mlx-lm's `@mx.compile` closure. `=0` → uncompiled composition (same parity, slower). |
|
|
351
468
|
| `MLX_BUN_COMPILED_SWIGLU` | `--compiled-activations` | on (`!== "0"`) | Compiled SwiGLU on MiniCPM5 decode and prefill, matching mlx-lm. An enclosing compiled graph owns its own fusion. qwen3/qwen3.5/universal compile unconditionally. |
|
|
352
469
|
| `MLX_BUN_FORCE_WIRE` | `--force-wire` | off (`=1`) | Wire weights for the generation. |
|
|
353
470
|
| `MLX_BUN_TRELLIS` | — | `kernel` (`=expand`) | Packed trellis-coded weights (`mode: "trellis"` modules, Q2b — design: `docs/design/turboquant.md`). `kernel` serves them through the Metal decode kernels (M≤4 matvec; larger M expands one tensor to bf16 and runs a stock matmul). `=expand` decodes every trellis tensor at LOAD into 8-bit g64 affine (+~4 GiB at 27B, the eval-carrier numerics) and serves it through the stock quantized path — the fallback for a machine where the kernels lose. |
|
|
354
|
-
| `MLX_BUN_TRELLIS_VARIANT` | — | `
|
|
471
|
+
| `MLX_BUN_TRELLIS_VARIANT` | — | `13` | Trellis kernel variant (see [Q2b experiments](../design/turboquant.md)): `6` = code computed inline × reciprocal, weight served as f32 code×scale; `1` adds a residual step and bf16 rounding to reproduce the fake-quant artifact's weights. `0`/`2`/`3`/`4`/`5` are bench-only decoder variants. Variants `7`–`13` retain variant-6 decode values; `13` is the measured default. These variants tune work assignment; `11` tiles eligible short axis-1 prefills, `12` adds split-K axis-0 prefill at M=5..8, and `13` also vectorizes remaining bf16 expansion for k2/k3/k4, T=256, L=12. On MLX 0.32.2/M3+ the axis-1 M5..15 path instead uses direct packed decoding with native wide-matvec arithmetic when Qwen's RMSNorm establishes aligned row-contiguous inputs; callers without that layout proof use native expansion/matmul. Qwen27B additionally selects an integer codebook for its interleaved k3 down projection at M=3/4 with bf16 activations; other calls retain the computed decoder. Prefill rounds weights to the activation dtype. |
|
|
355
472
|
| `MLX_BUN_TRELLIS_ASYNC_EXPAND` | — | off (`=1`) | Experimental variant-13 expansion scheduling. Submit an expanded projection asynchronously while MLX active allocation is below 75% of the device's recommended working set; retain blocking evaluation above it. Other variants are unchanged. Uses the execution's runtime-policy snapshot and preserves the caller's layer barriers. The threshold is not a total-memory cap. Qwen27B integrated native, repeated serial/continuous HTTP and both saved-agent pressure gates pass on M4 Pro 24 GB. Broader-model, combined-optimization and quiet M4 Pro acceptance remain. |
|
|
356
|
-
| `MLX_BUN_PAGED_KV` | `--paged-kv` | off (`=1`) | Paged KV cache; the same
|
|
473
|
+
| `MLX_BUN_PAGED_KV` | `--paged-kv` | off (`=1`) | Paged KV cache; the same eligibility and separate RAM/SSD namespace as the flag. |
|
|
357
474
|
| `MLX_BUN_ALLOW_PRIVATE_MEDIA` | `--allow-private-media` | off (`=1`) | Permit media fetches to private/loopback/link-local hosts (timeout + size cap still apply). |
|
|
358
475
|
| `MLX_BUN_EXPERT_OFFLOAD` | `--expert-offload` | off | `=<dir>` — the path of a built expert-offload file, activated at module load (`src/expert-offload.ts`) for scripts and library runs that never parse serve flags. The CLI flag builds the file and activates it itself. |
|
|
359
476
|
| `MLX_BUN_PREFILL_TAIL_SPLIT` | — | on (`"0"` disables) | Oracle prefill convention: drain the prompt to len−1, then compute step-0 logits from a separate L=1 forward of the last prompt token (mlx-lm `generate_step` and its batched engine). Both lanes. The spec lane follows its own oracle's shape under the same flag (mlx-lm `speculative_generate_step`: target and draft drain to len−1, no separate step 0). `=0` restores the full-final-chunk convention everywhere — ulp-different at step 0, flips near-tie greedy streams vs mlx-lm. |
|
|
360
477
|
| `MLX_BUN_GRAMMAR` | — | on (`"0"` disables) | `=0` disables structured-output mask compilation; requested constraints take the graceful-degrade route (chat prompt injection + a `Warning` header; raw completions header only). |
|
|
361
478
|
| `MLX_BUN_TOKEN_MASK` | `host` \| `metal` | `host` | Experimental grammar-mask implementation. `metal` uploads packed bits and applies the same additive mask in a compiled shared Metal kernel. Captured when the grammar controller is created; serving performance gates remain open. |
|
|
362
|
-
| `MLX_BUN_GRAMMAR_JUMP` | — | **off** (`=1`) |
|
|
363
|
-
| `
|
|
479
|
+
| `MLX_BUN_GRAMMAR_JUMP` | — | **off** (`=1`) | Grammar-supplied continuations. Eligible shared requests without a configured drafter propose xgrammar's forced string to the existing target verifier; the sampler validates every emitted token, including requested logprobs. Candidates leave the matcher unchanged until sampling. Affine/TurboQuant layouts compose through their speculative capabilities; paged requests keep ordinary grammar sampling. Explicit serial execution retains direct jump-forward: it emits retokenized forced spans with one multi-token forward, skips jumping with logprobs, and can choose different tokens than ordinary sampling. A configured drafter retains its own proposal policy. This remains opt-in; tokenization/verification width can change numerical trajectories. |
|
|
480
|
+
| `MLX_BUN_GRAMMAR_DRAFT_TOKENS` | — | `3` | Maximum grammar candidates per shared verification round when `MLX_BUN_GRAMMAR_JUMP=1`. Changes proposal depth, independently of scheduler capacity. |
|
|
481
|
+
| `MLX_BUN_FILL` | — | **off** (`=strict` \| `=echo`) | **Token fast-forwarding.** Strict mode appends tool-call spans determined by the request's schema and chat template, then resumes sampling. Request-local parsing excludes ambiguous literals and incomplete delimiters; closed, single-required-property schemas qualify for key/call-close assertions. Echo mode additionally proposes text copied from the session and verifies it with the request's sampler. Shared execution supports seeded requests and the qualified bf16/affine/TurboQuant row layouts. Homogeneous echo cohorts use the existing grouped target verifier; mixed proposed/unproposed rows retain one-position sampling. Rejected suffixes are rolled back before reusable state is published. Wider verification can change floating-point rounding relative to sequential decode, so sampled text need not be identical. Explicit serial fill still excludes fixed seeds and uses its existing model/cache eligibility. Fill is disabled for logprobs, structured output, media, a mounted draft model and shared paging. Strict appends bypass sampling and therefore change behavior policy at nonzero temperature. Both modes remain opt-in; see the shared-fill section below and `usage.fill`. |
|
|
364
482
|
| `MLX_BUN_FILL_MAX_SPAN` | — | `32` (floor 2) | Hard cap on one injected span. |
|
|
365
483
|
| `MLX_BUN_FILL_APPEND_CHUNK_SIZE` | — | `0` (model limit) | Execution chunk cap for assert-policy fill, captured by each FillSession. Zero selects the model's qualified limit; a positive value can lower that limit. The Qwen 27B text path on `applegpu_g16s`, validated on the M4 Pro, supports up to four positions with supported affine projections and optional Trellis MLPs. It rechecks the limit after each chunk and splits at MLX's attention arithmetic boundaries to preserve one-token numerics. Other configurations use one position per forward. The engine commits the complete span before emission and resumes sampling after it, with no intermediate vocabulary heads or verification. Verify-policy proposals keep a single forward for recurrent rollback. The injected-token cap is unchanged. Library callers can set `FillSession`'s `appendChunkSize` option. Held-out, broader-model and quiet M4 Pro acceptance remain. |
|
|
366
484
|
| `MLX_BUN_FILL_K` | — | `8` (floor 2) | Echo anchor length: the k-gram that must match before a copied span is proposed (the corpus study's token-level threshold). |
|
|
@@ -371,9 +489,15 @@ Under `--isolate` the whole environment is inherited by the engine child.
|
|
|
371
489
|
| `MLX_BUN_BATCH_SSM` | — | on (`"0"` forces serial) | `=0` excludes SSMCache (Qwen3.5 gated-DeltaNet hybrids) from the batch capability gate → those models route serial. |
|
|
372
490
|
| `MLX_BUN_BATCH_EXTEND` | — | on (`"0"` reverts) | Joining rows append to the running batch's KV in one pad+concat (mlx-lm `BatchKVCache.extend`). `=0` reverts to whole-batch re-merge (numerically equivalent, O(B·S)). |
|
|
373
491
|
| `MLX_BUN_BATCH_VEC_SAMPLE` | — | on (`"0"` reverts) | Vectorized greedy batch sampling; `=0` falls back to per-row sampling (bit-equal A/B). |
|
|
374
|
-
| `MLX_BUN_BATCH_NO_PIPELINE` | — | off (`=1`) | Read each batch step's tokens synchronously instead of pipelined (A/B lever; numerically equivalent, slower).
|
|
375
|
-
| `MLX_BUN_SSD_WRITEBEHIND` | — | on (`"0"` disables) |
|
|
376
|
-
| `
|
|
492
|
+
| `MLX_BUN_BATCH_NO_PIPELINE` | — | off (`=1`) | Read each batch step's tokens synchronously instead of pipelined (A/B lever; numerically equivalent, slower). Captured when the execution group is constructed. |
|
|
493
|
+
| `MLX_BUN_SSD_WRITEBEHIND` | — | on (`"0"` disables) | Proactive persistence after cache publication. A CPU worker packs, hashes and writes immutable state without a generation lock. Writing does not evict RAM. `=0` keeps eviction-triggered persistence; RAM victims remain resident until their SSD copy commits. |
|
|
494
|
+
| `MLX_BUN_SSD_LAYOUT` | — | `whole` | `blocks` writes immutable content-addressed blocks with atomic checkpoint manifests (format 5). Existing whole files remain readable. Shared blocks count once toward an explicit SSD cap and survive deletion of other referencing checkpoints. Experimental space/time tradeoff; see benchmarks. |
|
|
495
|
+
| `MLX_BUN_SSD_SEGMENTED` | — | on (`"0"` disables) | With block storage, read contiguous spans directly and pack arbitrary strides in at most 1 MiB scratch. `=0` retains whole-tensor CPU packing for paired measurements. |
|
|
496
|
+
| `MLX_BUN_SSD_PREFETCH` | — | on (`"0"` disables) | Prepare cold prefixes before execution, using a separate CPU read queue and owned page-aligned allocations. Concurrent identical reads coalesce. Cancellation releases request interest; the cache chooses residency. `=0` retains synchronous restore for comparison. |
|
|
497
|
+
| `MLX_BUN_SESSION_CACHE` | — | on (`"0"` disables) | Honor application session affinity for checkpoint lookup and soft RAM retention. `=0` ignores session metadata for paired HTTP measurements. Full input is still required; see server-api.md for body/header fields and session closure. |
|
|
498
|
+
| `MLX_BUN_CACHE_RETENTION` | — | `lru` | `cost-size` selects GreedyDual-style reuse/size retention, with reused prefix tokens as the processing-cost proxy. This changes RAM residency only; SSD durability remains independent. |
|
|
499
|
+
| `MLX_BUN_PAGED_ATTN` | — | off | With paged KV, `1` selects direct Metal reads for short causal queries (≤8 tokens), bf16 or affine KV4/KV8. Longer prefill and explicit masks use the established SDPA shape dispatch. Lab numerical contract: tolerance-tested against the same stored values, not an L1 bit-exact claim. |
|
|
500
|
+
| `MLX_BUN_SSD_SPILL_QUEUE_GB` | — | `2` (GiB; any finite value ≥ 0) | Pending snapshot cap for optional interrupted-generation checkpoints. Older queued intervals may be superseded; `=0` retains the newest plus any in-flight interval. Normal prompt-history persistence does not use this drop policy; its cache owns RAM residency and SSD demotion. Counters in `/stats.ssd_cache`. |
|
|
377
501
|
| `MLX_BUN_SHUTDOWN_TIMEOUT_MS` | — | `120000` (any finite value > 0) | Maximum time `serve` gives active requests plus the SSD durability flush after `SIGINT`/`SIGTERM`; on timeout it logs the remaining snapshot/spill counters and exits. |
|
|
378
502
|
| `MLX_BUN_DSPARK_MINCONF` | — | checkpoint-driven | Overrides the DSpark/DeepSpec draft scheduler's minimum-confidence threshold (draft-length pruning). Spec lane only ([docs/design/speculative-decoding.md](../design/speculative-decoding.md)). |
|
|
379
503
|
| `MLX_BUN_MEMORY_BATCH` | — | `1` (integer ≥ 1) | Row width for `mlx-bun memory` model calls. 1 = serial (batching measured 1.7–1.9× slower on the heterogeneous extract/chunk workload — [docs/design/dreaming-nightly-pipeline.md](../design/dreaming-nightly-pipeline.md)). |
|
|
@@ -396,16 +520,27 @@ Under `--isolate` the whole environment is inherited by the engine child.
|
|
|
396
520
|
|
|
397
521
|
| Env var | Value | Effect |
|
|
398
522
|
| --- | --- | --- |
|
|
399
|
-
| `MLX_BUN_P2R_TRACE` | `=1` | Per-request prompt→response phase trace (admission wait, prefill, token-zero,
|
|
400
|
-
| `MLX_BUN_P2R_SYNC` | `=1` (with `MLX_BUN_P2R_TRACE`) |
|
|
523
|
+
| `MLX_BUN_P2R_TRACE` | `=1` | Per-request prompt→response phase trace (request-slot wait, execution admission wait, cache prefetch/restore, prefill forward/evaluation/maintenance/checkpoints, mixed-forward token counts, token-zero, bounded initial token routing, response writes) for `/v1/chat/completions` and `/v1/completions`; records print to stderr as JSON lines. The trace id is `x-mlx-bun-trace-id` when the request sends it. |
|
|
524
|
+
| `MLX_BUN_P2R_SYNC` | `=1` (with `MLX_BUN_P2R_TRACE`) | Token-zero attribution mode: synchronizes hidden/cache state, projection and sampling at the instrumented boundaries. This changes overlap and slows the traced request. Ordinary prefill traces add no synchronization: forward includes any backend evaluation, while evaluate measures the remaining state wait. |
|
|
525
|
+
| `MLX_BUN_SPEC_TRACE` | `=1` | Explicit serial speculative-loop round diagnostics, captured once at run setup. |
|
|
401
526
|
| `MLX_BUN_LANE_DEBUG` | `=1` | Logs each request's scheduling placement (`mechanism` + shape) to stderr. |
|
|
402
|
-
| `MLX_BUN_BATCH_STEP_TRACE` | `=1` | Per-step phase timing in the batch scheduler (build / read / emit / gap),
|
|
527
|
+
| `MLX_BUN_BATCH_STEP_TRACE` | `=1` | Per-step phase timing in the batch scheduler (build / read / emit / gap), captured when the execution group is constructed; summarized by `stepTraceReport()`. |
|
|
403
528
|
| `MLX_BUN_GRAMMAR_DEBUG` | `=1` | Logs per-step grammar row state in the batch scheduler. |
|
|
404
529
|
| `MLX_BUN_PREFILL_MEM_LOG` | `=1` | Logs active/peak memory after each serial prefill chunk. |
|
|
405
530
|
| `MLX_BUN_EXPERT_TRACE` | `=<path>` | Records every MoE router decision as JSONL to that path (adds a per-call GPU→host sync — a measurement tool, not a serving path). |
|
|
406
531
|
| `MLX_BUN_PI_DEBUG` | any non-empty | Extra `[pi-web]` logging (prompt fingerprint, tool/memory surface) for the web-chat pi session. |
|
|
407
532
|
| `MLX_BUN_EVAL_DEBUG` | `=1` | HumanEval: pipe the sandbox's stderr and print failures. |
|
|
408
533
|
|
|
534
|
+
P2R records include a process-local `startedAtMs` origin to align concurrent
|
|
535
|
+
requests. Prefill `workId` attributes identify shared spans recorded on several
|
|
536
|
+
rows; these spans and their nested children must not be summed as separate
|
|
537
|
+
GPU work. The first eight token-routing spans stop at the first semantic event
|
|
538
|
+
and distinguish hidden channel markers from visible output. With tracing
|
|
539
|
+
enabled, `bench-serve.ts all` retains complete records by child PID in
|
|
540
|
+
`promptResponseTraces`, including records emitted during shutdown. Summarize a
|
|
541
|
+
saved report with `bun scripts/bench/prefill-trace.ts report.md.json --out
|
|
542
|
+
breakdown.json`. Clocks from different server processes are independent.
|
|
543
|
+
|
|
409
544
|
### Eval and training
|
|
410
545
|
|
|
411
546
|
| Env var | Default | Effect |
|
|
@@ -440,6 +575,10 @@ it. Only a second concurrent request causes a batch layout to exist. The
|
|
|
440
575
|
flag declares the concurrency cap; active rows select B=1 or B=N inside
|
|
441
576
|
the scheduler.
|
|
442
577
|
|
|
578
|
+
No flag is needed to enable this default. The cap is a maximum, not a minimum
|
|
579
|
+
group size: a lone eligible request starts at B=1. The serial executor remains
|
|
580
|
+
available through `--batch 1` and for unsupported request compositions.
|
|
581
|
+
|
|
443
582
|
`--batch 1` pins the strict serialized single-queue path: one generation
|
|
444
583
|
at a time, arrival-independent numerics (a request's bits never depend on
|
|
445
584
|
what else was in flight). Pin it for golden regeneration and
|
|
@@ -454,8 +593,9 @@ row for bf16, and per-row oracle-gated for the quantized compositions:
|
|
|
454
593
|
- **`--kv-quant config`** (per-layer mixed precision) **batches** on
|
|
455
594
|
every shipped model — full-attention and rotating layers — applied per
|
|
456
595
|
row, gated bit-exact for unpadded rows vs the serial composition.
|
|
457
|
-
- **`--kv-quant 4|8`**
|
|
458
|
-
|
|
596
|
+
- **`--kv-quant 4|8`** uses shared affine conversion and batches on supported
|
|
597
|
+
full-attention, rotating and hybrid recurrent models.
|
|
598
|
+
- **`turbo`** uses encoded shared rows for qualified start-zero full-attention caches; sliding layers stay bf16.
|
|
459
599
|
|
|
460
600
|
### Scheduling declaration (`GenerationGateway.place`)
|
|
461
601
|
|
|
@@ -470,18 +610,18 @@ GPU (one `AsyncMutex`).
|
|
|
470
610
|
|
|
471
611
|
| Request property | Continuous scheduler? |
|
|
472
612
|
| --- | --- |
|
|
473
|
-
| vision / audio / video parts |
|
|
474
|
-
| LoRA `adapter` (resolves to ≥1) |
|
|
475
|
-
| `logprobs` / `top_logprobs` |
|
|
476
|
-
| explicit `seed` |
|
|
477
|
-
| KV quant active | ✅ batches for per-layer `config`
|
|
478
|
-
| `--kv-quant turbo` |
|
|
479
|
-
| `--draft-model` mounted |
|
|
613
|
+
| vision / audio / video parts | Gemma4 image/audio and Qwen image/video use atomic media prefill followed by shared decode; diffusion retains its separate serial method |
|
|
614
|
+
| LoRA `adapter` (resolves to ≥1) | ✅ identical ordered adapter sets share a group; different sets wait for the next group |
|
|
615
|
+
| `logprobs` / `top_logprobs` | ✅ ordinary and qualified MTP/lookup/standalone-draft groups capture per-request probabilities; other exclusions still apply |
|
|
616
|
+
| explicit `seed` | ✅ request-local random stream; reproducibility also depends on model arithmetic and batch composition |
|
|
617
|
+
| KV quant active | ✅ batches for per-layer `config` and uniform `4`/`8` schemes on supported cache layouts |
|
|
618
|
+
| `--kv-quant turbo` | ✅ qualified TQ layouts; ordinary and supported grouped drafting library requests also support delayed row-local conversion |
|
|
619
|
+
| `--draft-model` mounted | ✅ qualified MTP, lookup, standalone, assistant, DeepSpec and DSpark/DFlash groups; provider and request capabilities determine eligibility; supported ordinary requests batch |
|
|
480
620
|
| `repetition_penalty` / `min_p` / `xtc_*` / `logit_bias` / presence+frequency penalties | ✅ batches — per-row logits processors over per-row device-side history (Qwen3.5 ships a *default* repetition penalty, so this is load-bearing) |
|
|
481
621
|
| structured output (`response_format` / `guided_*`) | ✅ batches — per-row grammar matchers (`MLX_BUN_GRAMMAR_BATCH=0` forces serial) |
|
|
482
622
|
| `temperature` / `top_p` / `top_k` | ✅ batches (each row samples with its own seed) |
|
|
483
623
|
| `stop` sequences | ✅ batches (per-row `StopMatcher`) |
|
|
484
|
-
| `tools` / `tool_choice` | ✅ batches (per-row tool router) |
|
|
624
|
+
| `tools` / `tool_choice` | ✅ batches (per-row tool router); opt-in `MLX_BUN_FILL=strict` uses the shared known-token method |
|
|
485
625
|
| `--thinking` / `enable_thinking` | ✅ batches (template-render concern) |
|
|
486
626
|
| multi-turn / long prompt | ✅ batches with prompt-cache reuse: a joiner restores the longest usable cached prefix and prefills only the suffix (`cached_tokens` reported) |
|
|
487
627
|
|
|
@@ -508,64 +648,85 @@ declared composition may still require the serial mechanism as shown above.
|
|
|
508
648
|
| Option | serial (`--batch 1`) | `--batch N` (N>1) |
|
|
509
649
|
| --- | --- | --- |
|
|
510
650
|
| `--kv-quant config` | ✅ applied to all requests | ✅ batches where the loaded cache capability supports the per-layer scheme; otherwise routes serial |
|
|
511
|
-
| `--kv-quant 4`/`8` | ✅ applied to all requests |
|
|
512
|
-
| `--kv-quant turbo[:k<bits>v<bits>]` | ✅
|
|
651
|
+
| `--kv-quant 4`/`8` | ✅ applied to all requests | ✅ server start=0 converts during prefill and batches on supported cache layouts; delayed library thresholds use qualified shared affine row layouts |
|
|
652
|
+
| `--kv-quant turbo[:k<bits>v<bits>]` | ✅ ordinary decode; strict serial speculation remains excluded | ✅ ordinary TQ, including delayed library conversion; supported grouped drafting also supports delayed library conversion |
|
|
513
653
|
| `--kv-quant off` / unset | ✅ bf16 (the L1 default) | ✅ bf16 |
|
|
514
|
-
| `--paged-kv` | ✅
|
|
654
|
+
| `--paged-kv` | ✅ | ✅ Gemma4 bf16/affine4/8 with separate RAM/SSD namespace; experimental direct attention is opt-in |
|
|
515
655
|
| `--memory-budget` | ✅ per-request admission | ✅ per-request admission — not aggregate (use `--kv-budget`) |
|
|
516
656
|
| `--kv-budget` | n/a | ✅ aggregate queue/reject across rows |
|
|
517
|
-
| `--prompt-cache` / `--ssd-cache` | ✅ prefix reuse + SSD restore | ✅
|
|
657
|
+
| `--prompt-cache` / `--ssd-cache` | ✅ prefix/output reuse + SSD restore | ✅ immutable prefill/output checkpoints, session lookup and queued SSD persistence |
|
|
518
658
|
| `--temperature`/`--top-p`/`--top-k` | ✅ | ✅ (per-row) |
|
|
519
659
|
| `--thinking` | ✅ | ✅ |
|
|
520
|
-
| vision / audio / video request | ✅ |
|
|
521
|
-
| LoRA `adapter` | ✅ | ✅
|
|
660
|
+
| vision / audio / video request | ✅ | Gemma4 image/audio and Qwen image/video shared; diffusion via its serial method |
|
|
661
|
+
| LoRA `adapter` | ✅ | ✅ compatible groups on adapter-capable backends |
|
|
522
662
|
| `repetition_penalty` / `min_p` / `xtc_*` / `logit_bias` / presence+frequency | ✅ | ✅ (batches — per-row processors) |
|
|
523
|
-
| `seed` | ✅ | ✅
|
|
663
|
+
| `seed` | ✅ | ✅ request-local sampling |
|
|
524
664
|
| `tools` / `stop` | ✅ | ✅ (batches) |
|
|
525
665
|
| structured output (`response_format`/`guided_*`) | ✅ (mask in the decode loop) | ✅ (batches; per-row matchers) |
|
|
526
|
-
| `--draft-model` / `--draft-kind` | ✅ spec decode
|
|
527
|
-
| GLM `--mtp on` | ✅ native MTP spec decode |
|
|
666
|
+
| `--draft-model` / `--draft-kind` | ✅ eligible spec decode | ✅ qualified MTP, lookup, standalone, Gemma assistant/DeepSpec/DSpark groups, including grammar/logprobs |
|
|
667
|
+
| GLM `--mtp on` | ✅ native MTP spec decode | ✅ native MTP uses grouped state/verification; tiny-model and oracle tests pass, final Colibri artifact testing is deferred |
|
|
528
668
|
| `--compiled-decode` | ✅ | ✅ at **B=1 only**: a lone request's adopted serial-class caches replay the same compiled step; B>1 steps run the plain graph |
|
|
529
|
-
| `--fused-sdpa`
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
-
|
|
544
|
-
|
|
545
|
-
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
669
|
+
| `--fused-sdpa` | ✅ eligible affine attention | ✅ kernel eligibility depends on dtype, quantization and mask geometry |
|
|
670
|
+
| `--force-wire` | ✅ serial wired scope | not applied by the shared executor |
|
|
671
|
+
|
|
672
|
+
### Shared execution and kernel settings
|
|
673
|
+
|
|
674
|
+
The scheduler selects request work. The inference method advances it through
|
|
675
|
+
model-owned numerical operations. Specialized kernels and sampling policies
|
|
676
|
+
remain available wherever their backend capabilities qualify; batching does
|
|
677
|
+
not disable performance settings as a category.
|
|
678
|
+
|
|
679
|
+
- `--compiled-decode` uses the qualified compiled graph for one active,
|
|
680
|
+
unpadded request. Multi-row steps use the batched graph.
|
|
681
|
+
- `--fused-sdpa` follows affine kernel eligibility. Padded/array masks can
|
|
682
|
+
require the ordinary attention operation; this is an attention decision.
|
|
683
|
+
- `--force-wire` controls the explicit serial wired scope. The shared executor
|
|
684
|
+
does not enter that scope.
|
|
685
|
+
- Trellis, compiled activations, affine row reuse and TurboQuant kernel choices
|
|
686
|
+
belong to the numerical backend and remain independent of admission policy.
|
|
687
|
+
|
|
688
|
+
`MLX_BUN_FILL=strict` uses a grouped method for eligible tool requests. Each
|
|
689
|
+
row owns its fill session and sampler history. Known positions bypass sampling;
|
|
690
|
+
when all next positions are known, the method omits the vocabulary head.
|
|
691
|
+
Shared fill uses the model-qualified multi-position append when all active
|
|
692
|
+
rows have known spans and the model permits that geometry. Qualified Qwen B1
|
|
693
|
+
uses its specialized append; wider rows currently advance one position per step. The shared method supports
|
|
694
|
+
bf16, affine KV4/KV8 and supported TurboQuant layouts, including explicit seeds.
|
|
695
|
+
It does not use compiled replay, interrupted-generation checkpoints, paging,
|
|
696
|
+
probability metadata, media, grammar or a mounted draft provider.
|
|
697
|
+
`MLX_BUN_FILL=echo` uses the same shared method with sampled verification and
|
|
698
|
+
row-specific rollback. Ordinary rows can join with empty proposals; eligible
|
|
699
|
+
plain-greedy requests reuse independent verification sampling. With a Qwen MTP
|
|
700
|
+
companion, echo proposals use the speculative method and the provider consumes
|
|
701
|
+
accepted tokens before resuming learned drafting. Asserted template spans remain
|
|
702
|
+
sampled in this combination. Other draft providers are not yet qualified. Fill stays off by default;
|
|
703
|
+
per-model performance acceptance remains separate from numerical replay.
|
|
704
|
+
|
|
705
|
+
Executors capture an immutable runtime configuration. Later host configuration
|
|
706
|
+
changes do not change an active request's kernel choices. TurboQuant storage
|
|
707
|
+
carries its decode policy through RAM copies, row extraction and delayed
|
|
708
|
+
conversion; restored SSD state is opened under the receiving binding's policy.
|
|
709
|
+
|
|
710
|
+
## Known limitations under shared execution
|
|
711
|
+
|
|
712
|
+
1. Gemma4 image/audio uses shared decode after an indivisible embeddings prefill.
|
|
713
|
+
Qwen image/video positions stay with each request through shared decode; diffusion retains its separate serial method. Strict tool-call fill
|
|
714
|
+
and echo verification have shared methods. Qwen MTP supports verified echo;
|
|
715
|
+
asserted fill with a drafter, other providers and shared paging remain unsupported. Grammar has shared masking and opt-in verified
|
|
716
|
+
proposals; direct serial jump-forward is a different algorithm.
|
|
717
|
+
2. Aggregate admission is opt-in through `--kv-budget`. Without it, concurrent
|
|
718
|
+
contexts can exceed available memory. Default fit estimates remain advisory.
|
|
719
|
+
3. Native GLM MTP has tiny-model/same-B oracle coverage; final Colibri artifact
|
|
720
|
+
testing is deferred. DSpark/DFlash execution has fixture coverage, with no
|
|
721
|
+
trained checkpoint available for a performance claim.
|
|
722
|
+
4. Paged Gemma storage supports bf16/affine4/8. TurboQuant pages, per-layer
|
|
723
|
+
paged KV and paged speculative methods remain unsupported. Qualified
|
|
724
|
+
ordinary resume and adapter resume are implemented; exact combinations are
|
|
725
|
+
tracked in [batching](../design/batching.md).
|
|
726
|
+
5. Stock bf16, affine mixed-KV and TurboQuant retain separate correctness
|
|
727
|
+
contracts. A passing storage test does not qualify an untested model or
|
|
728
|
+
numerical geometry. Existing accepted matrices remain in the design and
|
|
729
|
+
benchmark references.
|
|
569
730
|
|
|
570
731
|
## Fidelity tiers and the decode route (`--l1` / `--l2`)
|
|
571
732
|
|
|
@@ -616,16 +777,16 @@ Everything mlx-bun serves, with its default, lane, fidelity tier, and knob.
|
|
|
616
777
|
| Runtime isolation (crash-isolated engine child behind a proxy parent) | off | both | — | `--isolate` |
|
|
617
778
|
| Model pool (LRU-capped resident engines under `--isolate`) | 1 | both | — | `--model-pool <n>` |
|
|
618
779
|
| Mixed-precision KV (`kv_config.json`, optiq's scheme) | off | serial + batch (per-layer configs batch) | L2 | `--kv-quant config`, `--l2` |
|
|
619
|
-
| Uniform quantized KV (mlx-lm's `--kv-bits` scheme) | off | serial | L1 | `--kv-quant 4\|8` |
|
|
620
|
-
| TurboQuant KV (rotation-based: affine keys + FWHT/Lloyd-Max values) | off | serial
|
|
780
|
+
| Uniform quantized KV (mlx-lm's `--kv-bits` scheme) | off | serial + batch | L1 | `--kv-quant 4\|8` |
|
|
781
|
+
| TurboQuant KV (rotation-based: affine keys + FWHT/Lloyd-Max values) | off | serial + qualified shared ordinary/drafting | Lab (codec oracle-backed; composition gates apply) | `--kv-quant turbo[:k<bits>v<bits>]` (default `k8v3`) |
|
|
621
782
|
| Compiled decode (bit-exact graph replay) | on | serial, batch at B=1 | L1/L2 | `--compiled-decode on\|off` |
|
|
622
783
|
| Compiled activations (mlx-lm's `@mx.compile` geglu/swiglu) | on | both | L1 | `--compiled-activations on\|off` |
|
|
623
784
|
| Fused SDPA (optiq-exact quantized-KV attention) | follows `--kv-quant` | serial | L2 | `--fused-sdpa on\|off` |
|
|
624
|
-
| Paged KV (vLLM-style block pool, gather before the stock SDPA) | off |
|
|
625
|
-
| Speculative decoding (two-model / Gemma `-assistant` / DSpark / DeepSpec / native MTP head) | off |
|
|
785
|
+
| Paged KV (vLLM-style block pool, gather before the stock SDPA) | off | shared B1/B>1 | gated bit-exact vs plain `KVCache` | `--paged-kv`, `--paged-kv-block-size <n>` |
|
|
786
|
+
| Speculative decoding (two-model / Gemma `-assistant` / DSpark / DeepSpec / native MTP head) | off | shared Qwen methods; full-attention/rotating lookup/standalone and Gemma assistant/DeepSpec/DSpark; other combinations serial | per-drafter oracle (L1 two-model, L2 assistant, DeepSpec reference, Lab DSpark) | `--draft-model`, `--draft-kind`, `--num-draft-tokens` |
|
|
626
787
|
| GLM-5.2 checkpoint-native MTP | on for GLM-5.2 | serial+spec | oracle trajectory + synthetic HTTP gate | `--mtp on\|off` |
|
|
627
|
-
| Model-free prompt-lookup speculation (vLLM `ngram` port) | off |
|
|
628
|
-
|
|
|
788
|
+
| Model-free prompt-lookup speculation (vLLM `ngram` port) | off | Qwen and full-attention targets shared / other models serial | lossless by verify (gated vs non-spec greedy) | `--draft-kind ngram`, `--ngram-max`, `--ngram-min`, `--num-draft-tokens` (default 10) |
|
|
789
|
+
| Estimated memory admission | off (advisory) | both | — | `--memory-budget <GB>` opts in |
|
|
629
790
|
| Aggregate KV admission for batch rows | off | batch | — | `--kv-budget <GB>` |
|
|
630
791
|
| Expert offload (MoE experts on mmap) | off | serial | Lab | `--expert-offload` |
|
|
631
792
|
| Extend-join (O(1) batch admission) | on | batch | L1 (mlx-lm `extend`) | `MLX_BUN_BATCH_EXTEND=0` |
|
|
@@ -637,25 +798,25 @@ Everything mlx-bun serves, with its default, lane, fidelity tier, and knob.
|
|
|
637
798
|
| Feature | Default | Lane | Tier | Knob |
|
|
638
799
|
| --- | --- | --- | --- | --- |
|
|
639
800
|
| Structured output (`response_format` json_object/json_schema) | on | both | L2 (oMLX) | request field; `MLX_BUN_GRAMMAR=0` kills |
|
|
640
|
-
| Structured-output
|
|
641
|
-
| Token fast-forwarding for tool calls (template-determined spans
|
|
642
|
-
| Echo injection (session self-copy spans, verified against the same forward's logits) | off | serial
|
|
801
|
+
| Structured-output continuations (shared verified proposals / serial direct jump) | off | shared and serial | Lab | `MLX_BUN_GRAMMAR_JUMP=1` |
|
|
802
|
+
| Token fast-forwarding for tool calls (template-determined spans) | off | serial + shared strict method | opt-in; identity tested on covered fixtures, parser/held-out gates remain (`tests/parity/fill-strict.test.ts`) | `MLX_BUN_FILL=strict` |
|
|
803
|
+
| Echo injection (session self-copy spans, verified against the same forward's logits) | off | shared bf16/affine/TurboQuant; explicit serial eligibility remains separate | Lab (paired A/B on task success + wall clock before any default) | `MLX_BUN_FILL=echo`, `MLX_BUN_FILL_K`, `MLX_BUN_FILL_CANDIDATES`, `MLX_BUN_FILL_INDEX_MAX` |
|
|
643
804
|
| `guided_grammar` (EBNF) / `guided_regex`¹ / `guided_choice` / `structured_outputs` | on | both | L2 | request fields |
|
|
644
|
-
| Structured output × speculative decoding | on when both active | serial | Lab | — |
|
|
645
|
-
| Quantized KV × speculative decoding |
|
|
805
|
+
| Structured output × speculative decoding | on when both active | Qwen grouped MTP, lookup and standalone drafting / eligible serial methods | Lab | — |
|
|
806
|
+
| Quantized KV × speculative decoding | Shared Qwen supports uniform KV4/KV8 and TQ with zero or positive conversion thresholds; strict serial supports qualified KV4; per-layer mixed KV remains excluded | Qwen grouped MTP, lookup and standalone drafting / eligible serial methods | scheme and method gates | `MLX_BUN_QWEN_SPEC_KV4=0` disables the KV4 composition |
|
|
646
807
|
| Tool calling (Gemma sentinel / CPM+Qwen XML / GLM `arg_key`+`arg_value`) + `role:"tool"` loops | on | both | — | request `tools` |
|
|
647
|
-
| Vision (`image_url`; PNG/JPEG/HEIC/AVIF/WebP/TIFF/GIF/BMP) | on for models with a tower; SSRF guard on remote URLs | serial | L1/L2 | `--allow-private-media` |
|
|
808
|
+
| Vision (`image_url`; PNG/JPEG/HEIC/AVIF/WebP/TIFF/GIF/BMP) | on for models with a tower; SSRF guard on remote URLs | Gemma4 shared; other media bindings serial | L1/L2 | `--allow-private-media` |
|
|
648
809
|
| Video input (`video_url`/`video`; AVFoundation sidecar, 2 fps, ≤768 frames, 256 MB body cap; never with audio) | on for Qwen3.5-family | serial | mlx-vlm oracle | `--allow-private-media`, `MLX_BUN_FRAME_EXTRACT` |
|
|
649
810
|
| Audio input (`input_audio`/`audio`/`audio_url`; WAV native, mp3/m4a/flac/ogg/aiff via CoreAudio; ≤30 s per clip; mixes with images) | on for models with `audio_config` + sidecar tower (e4b) | serial³ | L2 (greedy stream exact vs optiq's internal model) | `--allow-private-media` |
|
|
650
|
-
| LoRA adapters (mount at start / hot-swap) | off |
|
|
811
|
+
| LoRA adapters (mount at start / hot-swap) | off | compatible groups | — | `--adapter <dir>`, `POST /v1/adapters` |
|
|
651
812
|
| Sampling: temperature / top-p / top-k / min-p / XTC / logit_bias / presence+frequency+repetition penalties | per request | both | L1 (mlx-lm-faithful) | request fields / server defaults |
|
|
652
|
-
| `logprobs` / `top_logprobs` | off |
|
|
653
|
-
| Fixed `seed` reproducibility | off |
|
|
813
|
+
| `logprobs` / `top_logprobs` | off | both | L1 | request fields |
|
|
814
|
+
| Fixed `seed` reproducibility | off | both | — | request field; compare the same execution composition |
|
|
654
815
|
| Thinking-mode control (hybrid-reasoning models) | model default | both | — | `--thinking`, `chat_template_kwargs`, `reasoning_effort` |
|
|
655
816
|
| Stop sequences / streaming / usage accounting | on | both | — | request fields |
|
|
656
817
|
| HLG tone-curve sampling | off | serial | Lab | `--hlg-sampling on` |
|
|
657
|
-
| Spec-decode telemetry (`usage.speculation`) | on with a draft | serial | — | — |
|
|
658
|
-
| Token-fast-forwarding telemetry (`usage.fill`) | on with `MLX_BUN_FILL=strict` | serial | — | — |
|
|
818
|
+
| Spec-decode telemetry (`usage.speculation`) | on with a draft | Qwen shared MTP, lookup and standalone drafting / eligible serial methods | — | — |
|
|
819
|
+
| Token-fast-forwarding telemetry (`usage.fill`) | on with `MLX_BUN_FILL=strict` | serial + shared | — | — |
|
|
659
820
|
| Per-turn lane telemetry (`usage.lane`: serial / serial+spec / batched) | on | both | — | — |
|
|
660
821
|
|
|
661
822
|
### Model coverage (per-model validated cells)
|
|
@@ -666,7 +827,7 @@ Everything mlx-bun serves, with its default, lane, fidelity tier, and knob.
|
|
|
666
827
|
| Gemma 4 (1B/e4b/12B/26B, + vision e4b/12B, + audio e4b) | ✅ L1/L2 | ✅ | sliding+full interleaved; MoE 26B |
|
|
667
828
|
| Qwen3.5 (gated-DeltaNet hybrid) | ✅ L1/L2 | ✅ (SSM path) | `MLX_BUN_BATCH_SSM=0` reverts |
|
|
668
829
|
| Qwen3.8-27B (same qwen3_5 graph) | ✅ L1 | ✅ (SSM path) | native MTP head via `--draft-model`/`--draft-kind mtp` (lossless-gated; slower on a quiet box — opt-in); images and video serve (mlx-vlm oracle) |
|
|
669
|
-
| GLM-5.2 / Colibri | ✅ chat/text, Messages, Responses, SSE, tools, grammar, logprobs | ✅ compressed MLA/DSA scheduler | native MTP
|
|
830
|
+
| GLM-5.2 / Colibri | ✅ chat/text, Messages, Responses, SSE, tools, grammar, logprobs | ✅ compressed MLA/DSA scheduler | native MTP shares the executor; final Colibri artifact testing is deferred; embeddings, vision/audio, adapters, training unsupported |
|
|
670
831
|
| DiffusionGemma-26B (non-autoregressive) | ✅ (own engine) | — serial always | first bit-exact non-AR port |
|
|
671
832
|
| Tier-0 universal (llama/qwen2/qwen3/olmo2/…, 11 archs) | ✅ L1 | ✅ plain full-attention archs² | gemma2-family / sliding-window universal → serial |
|
|
672
833
|
|
|
@@ -712,19 +873,33 @@ composition cells in one run).
|
|
|
712
873
|
On 12B+ add `--draft-model <small-same-tokenizer>`.
|
|
713
874
|
- *Several clients at once (throughput):*
|
|
714
875
|
`mlx-bun serve <model> --batch 4 --ssd-cache <dir> --kv-budget <GB>` —
|
|
715
|
-
|
|
716
|
-
|
|
876
|
+
supports the qualified grouped methods and cache layouts in the compatibility
|
|
877
|
+
matrix. Use the default cap eight unless a workload calls for another cap.
|
|
717
878
|
- *UI must never lag / survive engine crashes:* add `--isolate`
|
|
718
879
|
(`--model-pool 2` to keep two models resident).
|
|
719
880
|
- *Reproducibility:* bare / `--l1` (≡ mlx-lm), `--l1 --batch 1` (strict
|
|
720
881
|
serial), `--l2` (≡ optiq).
|
|
721
882
|
- *Memory-tight big model:* `--kv-quant config|4|8|turbo` +
|
|
722
883
|
`--memory-budget <GB>` + `--ssd-cache <dir>`; MoE adds
|
|
723
|
-
`--expert-offload`.
|
|
724
|
-
|
|
725
|
-
**
|
|
726
|
-
|
|
727
|
-
|
|
884
|
+
`--expert-offload`. Start-zero TurboQuant supports shared execution.
|
|
885
|
+
|
|
886
|
+
**Remaining exclusions:** fill combined with media, speculation or paging, and unsupported provider/layout
|
|
887
|
+
combinations. Qualified ordinary resume, paged storage and grouped draft
|
|
888
|
+
providers are implemented; see the compatibility matrix above.
|
|
889
|
+
Qwen ordinary, shared MTP and prompt lookup support positive library thresholds for uniform
|
|
890
|
+
affine KV4/KV8 and TurboQuant. Ordinary Gemma supports positive affine KV4/KV8
|
|
891
|
+
thresholds, including sliding-window layers. Other-model delayed affine remains
|
|
892
|
+
open. Qwen MTP
|
|
893
|
+
prefill and completed decode state use the common RAM/SSD cache. Generated
|
|
894
|
+
checkpoints contain only processed tokens; persistence uses the existing
|
|
895
|
+
queue. Chat preparation preserves generated token IDs when their decoded text
|
|
896
|
+
exactly prefixes the next rendered request, including provenance recovered from
|
|
897
|
+
SSD headers. This avoids a full prefill when re-encoding identical generated
|
|
898
|
+
text would choose a different BPE segmentation. Edited text retains ordinary
|
|
899
|
+
tokenization. Input token counts can differ from encoding the full prompt again;
|
|
900
|
+
cache state is always matched by exact IDs and execution namespace.
|
|
901
|
+
Strict serial deletion is deferred. Remaining feature and performance work
|
|
902
|
+
is tracked in Phase 6/18.
|
|
728
903
|
|
|
729
904
|
## Observability — `GET /stats`
|
|
730
905
|
|
|
@@ -750,3 +925,49 @@ preparation wait during that job. Shutdown cancels queued jobs and terminates th
|
|
|
750
925
|
host's active job before releasing its lease. Resident model weights remain
|
|
751
926
|
loaded. Under isolation, the parent coordinates all of its model-pool workers.
|
|
752
927
|
This controls execution, not memory capacity or independently launched servers.
|
|
928
|
+
|
|
929
|
+
### Delayed KV conversion in library requests
|
|
930
|
+
|
|
931
|
+
The CLI keeps `quantizedKvStart=0`. A library `KvScheme("turbo", ...)` can
|
|
932
|
+
set a positive threshold for ordinary or Qwen MTP shared execution. Every row converts
|
|
933
|
+
at its own existing maintenance boundary. During the mixed phase, the
|
|
934
|
+
cache retains plain and encoded rows independently while model attention
|
|
935
|
+
still runs at the shared batch size. The fetched attention state restores
|
|
936
|
+
only the rotated value rows; once all rows convert, the standard packed
|
|
937
|
+
batch layout takes over. Shared MTP converts committed history before a
|
|
938
|
+
verification round; crossing the threshold inside that round converts at
|
|
939
|
+
resolution after rollback and before checkpoint publication. Rejected tokens
|
|
940
|
+
cannot set the conversion offset.
|
|
941
|
+
|
|
942
|
+
Qwen ordinary, shared MTP and prompt lookup also support positive `quantizedKvStart` with
|
|
943
|
+
uniform affine KV4/KV8. Affine and TQ adapters share the same row-transition
|
|
944
|
+
lifecycle. During mixed affine precision, each row uses its existing plain or
|
|
945
|
+
quantized attention arithmetic; after conversion, the packed batch layout owns
|
|
946
|
+
attention. The model binding declares this support; scheduling does not choose
|
|
947
|
+
the codec or conversion boundary. Ordinary Gemma also supports delayed affine
|
|
948
|
+
conversion in full and sliding-window layers. Rotating rows retain the same
|
|
949
|
+
physical columns while converting independently, so shared attention masks stay
|
|
950
|
+
aligned. Gemma speculative methods and other-model delayed affine remain open.
|
|
951
|
+
|
|
952
|
+
A delayed conversion records the earliest reusable prefix offset. RAM and
|
|
953
|
+
SSD reuse preserve earlier plain donors and never trim converted state
|
|
954
|
+
below that boundary. Older TQ SSD files without this metadata remain
|
|
955
|
+
usable at their stored offset, but cannot serve shorter prefixes. The
|
|
956
|
+
start-zero default-group cache keys are unchanged; positive TQ and affine
|
|
957
|
+
thresholds, and non-default affine group sizes, have distinct keys.
|
|
958
|
+
No memory budget or admission default changes.
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
Supported grouped draft providers also accept TurboQuant with positive library
|
|
962
|
+
conversion thresholds. Full-attention layers use the selected codec; sliding
|
|
963
|
+
layers stay bf16. Generated target and method-companion snapshots preserve
|
|
964
|
+
precision through RAM and queued SSD persistence. Defaults are unchanged.
|
|
965
|
+
Composition evidence and remaining gaps: [batching design](../design/batching.md).
|
|
966
|
+
|
|
967
|
+
The programmatic `createServer` option `quantizedKvStart` sets the absolute
|
|
968
|
+
per-row offset at which the selected KV scheme converts. Omission preserves
|
|
969
|
+
the existing start-zero server policy. This option is resolved once with the
|
|
970
|
+
KV scheme and shared by request preparation, execution, and checkpoint identity.
|
|
971
|
+
Generation checkpoints preserve encoded state and each cache's earliest reusable
|
|
972
|
+
offset; restoring a checkpoint does not re-quantize it. TurboQuant retains its
|
|
973
|
+
existing full-attention scope, with sliding-window caches in bf16.
|