mlx-bun 0.0.4 → 0.0.6

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.
Files changed (90) hide show
  1. package/README.md +175 -93
  2. package/docs/dag/training-inference-map.html +575 -0
  3. package/docs/design/adapters-end-to-end.md +50 -46
  4. package/docs/design/compat-cli-surface-design.md +10 -8
  5. package/docs/design/docs-reorg-plan.md +14 -1
  6. package/docs/design/hlg-sampling.md +12 -2
  7. package/docs/design/memory-system.md +193 -295
  8. package/docs/design/optimization_plan.md +4 -2
  9. package/docs/design/orpo-dynamic-lambda.md +179 -0
  10. package/docs/design/orpo-future-enhancements.md +340 -0
  11. package/docs/design/orpo-training.md +1212 -0
  12. package/docs/design/parallel-slots.md +34 -26
  13. package/docs/design/parity-tier-dag.md +143 -0
  14. package/docs/design/runtime-isolation.md +1 -1
  15. package/docs/design/segmented-backward-training.md +58 -39
  16. package/docs/design/tauri-desktop-app.md +127 -0
  17. package/docs/design/w4a16-compute-precision-spike.md +232 -0
  18. package/docs/investigations/orpo-base-uf-experiment-and-directions.md +120 -0
  19. package/docs/investigations/orpo-flash-cce-pin-leak.md +167 -0
  20. package/docs/investigations/orpo-uf-testing-handoff.md +126 -0
  21. package/docs/{segmented-backward-handoff.md → investigations/segmented-backward-handoff.md} +1 -1
  22. package/docs/investigations/starter-model-port-handoff.md +32 -13
  23. package/docs/investigations/steel-flash-cce-handoff.md +489 -0
  24. package/docs/investigations/trainer-validation-experiment.md +173 -0
  25. package/docs/planning/IDEAS.md +29 -0
  26. package/docs/planning/PRODUCT_ROADMAP.md +147 -27
  27. package/docs/planning/chunk-task-roadmap.md +1 -1
  28. package/docs/planning/journal.md +161 -0
  29. package/docs/reference/distribution.md +61 -5
  30. package/docs/reference/library-api.md +29 -14
  31. package/docs/reference/memory.md +77 -0
  32. package/docs/reference/orpo-quickstart.md +130 -0
  33. package/docs/reference/server-api.md +105 -7
  34. package/docs/reference/server-config.md +12 -5
  35. package/docs/reference/training.md +296 -0
  36. package/package.json +1 -1
  37. package/src/cli.ts +651 -18
  38. package/src/eval/ifeval.ts +138 -0
  39. package/src/eval/runner.ts +76 -6
  40. package/src/eval/tasks/bfcl.ts +49 -15
  41. package/src/eval/tasks/gsm8k.ts +21 -9
  42. package/src/eval/tasks/hashhop.ts +33 -4
  43. package/src/eval/tasks/humaneval.ts +30 -8
  44. package/src/eval/tasks/ifeval.ts +52 -18
  45. package/src/eval/tasks/mmlu.ts +85 -74
  46. package/src/eval/ultrafeedback.ts +60 -0
  47. package/src/jobs/runner.ts +6 -0
  48. package/src/lora.ts +12 -7
  49. package/src/memory/chunk.ts +25 -0
  50. package/src/memory/cluster.ts +24 -0
  51. package/src/memory/db.ts +114 -0
  52. package/src/memory/ingest.ts +22 -0
  53. package/src/memory/pipeline.ts +63 -0
  54. package/src/memory/prompts.ts +23 -0
  55. package/src/memory/schedule.ts +163 -0
  56. package/src/memory/synthesize.ts +29 -0
  57. package/src/memory/tools.ts +399 -0
  58. package/src/memory/vault.ts +694 -0
  59. package/src/memory/wikify.ts +23 -0
  60. package/src/mlx/metal-kernel.ts +31 -4
  61. package/src/model/flash-attention.ts +37 -19
  62. package/src/model/fused-geglu-kernel.ts +111 -0
  63. package/src/model/gemma4-base.ts +39 -1
  64. package/src/model/gemma4.ts +196 -21
  65. package/src/model/minicpm5.ts +44 -3
  66. package/src/pi-provider.ts +29 -13
  67. package/src/pi-session.ts +81 -0
  68. package/src/pi-terminal.ts +13 -24
  69. package/src/pi-web.ts +246 -166
  70. package/src/quantize/job.ts +17 -2
  71. package/src/quantize/quantizer.ts +26 -2
  72. package/src/server.ts +216 -47
  73. package/src/tokenizer.ts +6 -2
  74. package/src/train/dataset.ts +29 -6
  75. package/src/train/flash-cce.ts +1175 -0
  76. package/src/train/job.ts +64 -3
  77. package/src/train/lora-params.ts +53 -4
  78. package/src/train/loss.ts +947 -0
  79. package/src/train/optimizer.ts +10 -3
  80. package/src/train/prefix-shared.ts +435 -0
  81. package/src/train/rank.ts +36 -0
  82. package/src/train/segmented.ts +1148 -3
  83. package/src/train/steel-qmm-header.ts +1461 -0
  84. package/src/train/trainer.ts +570 -54
  85. package/src/train/watch.ts +542 -0
  86. package/src/web/app.html +285 -19
  87. package/src/web/skills/memory/SKILL.md +97 -0
  88. package/src/web/skills/web-research/SKILL.md +3 -1
  89. package/src/web/skills.ts +46 -8
  90. /package/{docs → src/assets}/curve-designer.html +0 -0
package/README.md CHANGED
@@ -1,21 +1,44 @@
1
1
  # mlx-bun
2
2
 
3
- Native MLX inference for Bun. Run quantized LLMs on Apple Silicon from
4
- TypeScript — no Python, no sidecar server, one runtime.
5
-
6
- Measured head-to-head on an M4 Pro (24 GB), same models, same day:
7
- logits **bit-exact** against the Python reference; served over HTTP the
8
- **fastest stack on every model tested** (TTFT 45–89 ms vs python's
9
- 220–327 ms, zero server overhead vs mlx-lm's −5–6%); prefill up to
10
- **1.8×** mlx-lm at 8k context; cold start → first token of a cached
11
- prompt in **394 ms**. Full table: [benchmarks](#benchmarks).
3
+ Native MLX inference for Bun, and the beginning of a one-command local AI
4
+ product for Apple Silicon Macs. `mlx-bun` detects the machine, starts a useful
5
+ local assistant, exposes OpenAI/Anthropic-compatible APIs, and gives
6
+ TypeScript apps direct access to MLX without Python or a sidecar server.
7
+
8
+ The product bet is that local AI on Mac is a finite optimization problem, not
9
+ an infinite configuration maze: Apple ships a known set of chip/RAM/bandwidth
10
+ SKUs, the supported model list is curated, and the task mode is explicit. That
11
+ means defaults can be chosen from measured device × model × mode profiles
12
+ instead of asking every user to become an ML systems engineer.
13
+
14
+ Measured head-to-head on an M4 Pro (24 GB), same models, same machine
15
+ state: logits **bit-exact** against the Python reference; served over
16
+ HTTP the **fastest stack on every model tested** — fastest decode, plus
17
+ TTFT **34–85 ms** vs python's 218–326 ms at **~0% server overhead**
18
+ (mlx-lm pays −5–6%); server start to ready in **0.17–0.47 s**, 2–5×
19
+ faster than the Python servers. Full table: [benchmarks](#benchmarks).
12
20
 
13
21
  ## Getting started
14
22
 
15
23
  You need an Apple Silicon Mac (MLX is Metal-only, so macOS only by
16
- design). Three ways in.
24
+ design). Four ways in.
25
+
26
+ ### Direct download (recommended)
27
+
28
+ No Homebrew, Bun, or git — just curl the install script. It downloads the
29
+ signed, notarized self-contained binary from the latest release and puts
30
+ `mlx-bun` on your PATH:
31
+
32
+ ```sh
33
+ curl -fsSL https://mlx-bun.dev/install.sh | sh
34
+ mlx-bun
35
+ ```
36
+
37
+ Self-contained (binary + MLX runtime) and notarized, so it runs without a
38
+ Gatekeeper prompt. Installs to `~/.mlx-bun` by default — override with
39
+ `MLX_BUN_INSTALL_DIR`, or pin a release with `MLX_BUN_VERSION=v0.0.4`.
17
40
 
18
- ### Homebrew (recommended)
41
+ ### Homebrew
19
42
 
20
43
  A self-contained, signed + notarized binary — no toolchain to install by
21
44
  hand:
@@ -68,8 +91,7 @@ model named, it does everything for you:
68
91
  2. downloads the sub-GB `MiniCPM5-1B` starter and serves it, so you're
69
92
  chatting in well under a minute;
70
93
  3. starts downloading `gemma-4-e4b` (the stronger 4B model) in the
71
- background — it becomes the default on your next `mlx-bun serve`, on a
72
- 16 GB+ Mac;
94
+ background — it becomes the default on your next `mlx-bun serve`;
73
95
  4. opens the chat UI in your browser at
74
96
  [`http://localhost:8090/#/chat`](http://localhost:8090/#/chat)
75
97
  (pass `--no-open` to skip).
@@ -95,22 +117,54 @@ That's it. The server serves the one model it was started with (the
95
117
  request's `model` field is ignored and the loaded model id is echoed
96
118
  back in responses).
97
119
 
120
+ ## What mlx-bun is
121
+
122
+ `mlx-bun` has four faces, all sharing one native runtime:
123
+
124
+ - **The local AI product** — run `mlx-bun` or `bunx mlx-bun` and get a
125
+ working local chat UI plus a local server. The default path should feel like
126
+ an appliance: download the starter model, start chatting quickly, then move
127
+ to the stronger recommended model as it becomes available.
128
+ - **The app developer library** — embed local MLX inference inside Bun,
129
+ Tauri, Electron, and other TypeScript applications without running Python in
130
+ the background.
131
+ - **The AI lab** — keep parity, evals, kernels, LoRA/ORPO training, adapter
132
+ routing, and performance experiments close to the runtime that will actually
133
+ serve them.
134
+ - **The background agent runtime** — leave a local OpenAI-compatible endpoint
135
+ available for scripts, recurring jobs, app integrations, and per-request
136
+ adapter routing.
137
+ - **The local memory layer** — `mlx-bun memory init` creates a git-tracked
138
+ Markdown wiki at `~/.mlx-bun/wiki`; `Reference/` is seeded with read-only
139
+ symlinks to mlx-bun's own docs, and the built-in pi agents read both those
140
+ docs and your articles quietly (`memory_search`, `memory_section`, etc.) and can open it in Obsidian for you
141
+ (`mlx-bun memory open [article]`). Chat-time memory is read-only; synthesis is
142
+ the separate writer path. The planned synthesis pipeline uses the same local
143
+ models with stage-specific LoRA adapters (chunk, bucket, synthesize, edit)
144
+ trained by the project creator and distributed from Hugging Face.
145
+
146
+ The default experience is intentionally opinionated. Power users can override
147
+ models, budgets, KV modes, adapters, and flags; the average user should not
148
+ need to know those knobs exist.
149
+
98
150
  ## Supported models
99
151
 
100
152
  Scope is deliberate: a few model families held to **bit-exact** logit
101
153
  parity with the Python reference, rather than dozens held to none.
102
- Currently MiniCPM5 plus the Gemma-4 OptiQ quants:
154
+ Currently MiniCPM5, the Gemma-4 OptiQ quants, and Qwen3.5-4B:
103
155
 
104
156
  | Model | Download | Fits on | Vision | Notes |
105
157
  |---|---|---|---|---|
106
158
  | [`mlx-community/MiniCPM5-1B-OptiQ-4bit`](https://huggingface.co/mlx-community/MiniCPM5-1B-OptiQ-4bit) | 0.92 GB | 8 GB | — | Sub-GB option for 8 GB machines; bit-exact 100-step oracle parity (bf16 + mixed KV), tool calling + agent loop verified |
107
- | [`mlx-community/gemma-4-e4b-it-OptiQ-4bit`](https://huggingface.co/mlx-community/gemma-4-e4b-it-OptiQ-4bit) | 7.0 GB | 16 GB | — | **Recommended starter** (16 GB+); ~54 tok/s |
108
- | [`mlx-community/gemma-4-12B-it-OptiQ-4bit`](https://huggingface.co/mlx-community/gemma-4-12B-it-OptiQ-4bit) | 8.4 GB | 16 GB | ✓ | Vision sidecar + tool calling, both verified end-to-end |
109
- | [`mlx-community/gemma-4-26B-A4B-it-OptiQ-4bit`](https://huggingface.co/mlx-community/gemma-4-26B-A4B-it-OptiQ-4bit) | 18 GB | 24 GB | — | MoE (top-8 of 128 experts); ~54 tok/s — the python servers crash loading it on 24 GB |
159
+ | [`mlx-community/Qwen3.5-4B-OptiQ-4bit`](https://huggingface.co/mlx-community/Qwen3.5-4B-OptiQ-4bit) | 3.1 GB | 8 GB | — | bf16-KV bit-exact parity (vs mlx-lm); thinking + tool calling; ~74 tok/s predicted |
160
+ | [`mlx-community/gemma-4-e4b-it-OptiQ-4bit`](https://huggingface.co/mlx-community/gemma-4-e4b-it-OptiQ-4bit) | 7.0 GB | 16 GB | ✓ | **Recommended starter** (16 GB+); ~56 tok/s |
161
+ | [`mlx-community/gemma-4-12B-it-OptiQ-4bit`](https://huggingface.co/mlx-community/gemma-4-12B-it-OptiQ-4bit) | 8.4 GB | 16 GB | ✓ | Vision + tool calling, both verified end-to-end |
162
+ | [`mlx-community/gemma-4-26B-A4B-it-OptiQ-4bit`](https://huggingface.co/mlx-community/gemma-4-26B-A4B-it-OptiQ-4bit) | 18 GB | 24 GB | — | MoE (top-8 of 128 experts); ~54 tok/s |
110
163
 
111
164
  Not sure what fits your machine? `bun src/cli.ts fit <model> --ctx 8192`
112
- gives a deterministic answer (see below). Qwen 3.x is next on the
113
- roadmap (see [PLAN.md](./PLAN.md)).
165
+ gives a deterministic answer (see below). The larger
166
+ `Qwen3.6-27B-OptiQ-4bit` is still in bring-up — parity and serving polish
167
+ remain (see [PLAN.md](./PLAN.md)).
114
168
 
115
169
  ## Why
116
170
 
@@ -131,7 +185,7 @@ one:
131
185
  - **`bun:ffi`** — lowest-overhead FFI of any JS runtime; binds `mlx-c`
132
186
  directly, no node-gyp, no binding compilation.
133
187
  - **Lazy native weight loading** — mlx's loader materializes tensors on
134
- first use; opening an 8.9 GB model takes milliseconds, and warm
188
+ first use; opening an 8.4 GB model takes milliseconds, and warm
135
189
  restarts are near-instant on cached pages.
136
190
  - **`Bun.Image`** — native OS image codecs (HEIC, AVIF, WebP, JPEG, …)
137
191
  for the vision path, EXIF auto-orientation included.
@@ -152,9 +206,11 @@ bun src/cli.ts fit gemma --ctx 32768 # memory contract: fits? max conte
152
206
  bun src/cli.ts fit gemma --ctx 8192 --skus # ...same, across the Apple Silicon lineup
153
207
  bun src/cli.ts serve gemma --port 8090 # OpenAI-compatible server
154
208
  bun src/cli.ts serve gemma --memory-budget 18 # ...with admission control (GB)
209
+ bun src/cli.ts pi # built-in agentic coding CLI (pi's TUI, in-process)
155
210
  bun src/cli.ts evals # recorded benchmark runs
211
+ bun src/cli.ts harness pi # connect your own pi install to the local server
156
212
  ./benchmark.sh # head-to-head matrix vs mlx-lm/optiq (reboot first;
157
- # preflight-gated, resumable, writes benchmarks-h2h-<date>.md)
213
+ # preflight-gated, resumable, writes benchmarks-h2h-<date>-<host>.md)
158
214
  ```
159
215
 
160
216
  Model arguments are substring queries against the registry (`e4b`,
@@ -177,15 +233,18 @@ agent CLIs like pi/OpenClaw via their provider config.
177
233
  - **`POST /v1/chat/completions`** — streaming (SSE) and non-streaming;
178
234
  `temperature`, `top_p`, `top_k`, `max_tokens`, `seed`,
179
235
  `repetition_penalty`, `stop` (string or array, matched on decoded
180
- text with streaming hold-back); omitted sampling fields default to
181
- the model's own `generation_config.json` recipe; usage includes
182
- `cached_tokens`. Full schemas in
236
+ text with streaming hold-back), `reasoning_effort` (thinking on/off for
237
+ Qwen3.5 / MiniCPM5 — `none` disables, any level enables), and an `hlg`
238
+ tone-curve sampling override;
239
+ omitted sampling fields default to the model's own
240
+ `generation_config.json` recipe; usage includes `cached_tokens`.
241
+ Full schemas in
183
242
  [docs/reference/server-api.md](./docs/reference/server-api.md); start
184
243
  flags and the `--batch N` compatibility matrix in
185
244
  [docs/reference/server-config.md](./docs/reference/server-config.md).
186
245
  - **Tool calling** — pass OpenAI `tools`; each family's native format
187
246
  is parsed into `tool_calls` JSON with `finish_reason: "tool_calls"`
188
- (Gemma 4 `<|tool_call>` sentinel tokens; MiniCPM5
247
+ (Gemma 4 `<|tool_call>` sentinel tokens; MiniCPM5 / Qwen3.5
189
248
  `<function name=…>` XML with schema-aware argument decoding);
190
249
  `role: "tool"` round-trips, including multi-turn agent loops.
191
250
  - **Vision** — `image_url` content parts (data: URLs or http/s), on
@@ -195,16 +254,17 @@ agent CLIs like pi/OpenClaw via their provider config.
195
254
  common token prefix across requests (multi-turn conversations
196
255
  re-prefill only the new turn) — automatic, no client changes.
197
256
  Entries are adapter-specific when LoRA adapters are in play.
198
- - **LoRA hot-swap** — mount adapters at startup (`--adapter id=dir`)
199
- or at runtime (`POST /v1/adapters`), select per request with the
200
- `adapter` body field (`"id"`, stacked `"a+b"`, or `"none"`). The
201
- base model never reloads; an unselected adapter costs nothing.
257
+ - **LoRA hot-swap** — mount adapters at runtime (`POST /v1/adapters`)
258
+ and discover on-disk ones (`GET /v1/adapters/available`), select per
259
+ request with the `adapter` body field (`"id"`, stacked `"a+b"`, or
260
+ `"none"`). The base model never reloads; an unselected adapter costs
261
+ nothing.
202
262
  - **Mixed-precision KV** — when the model repo ships `kv_config.json`
203
263
  (every Gemma-4 OptiQ repo does), per-layer KV quantization applies
204
- automatically (full-attention layers; sliding layers stay bf16).
205
- Measured decode-neutral at 8k on the 12B with KV bytes ÷4 on the
206
- quantized layers. `--no-kv-quant` forces bf16; `--kv-bits N` forces
207
- uniform bits. Long prefills over quantized caches run a fused
264
+ automatically; the config sets bits per layer for both full-attention
265
+ and sliding-window (rotating) layers (Phase 9). Measured decode-neutral
266
+ at 8k on the 12B with KV bytes ÷4 on the quantized layers. `--kv-quant off` forces bf16; `--kv-quant 4|8`
267
+ forces uniform bits. Long prefills over quantized caches run a fused
208
268
  FlashAttention-2 tiling that never materializes the full scores
209
269
  matrix (bounded transient; `MLX_BUN_NO_FUSED_SDPA=1` to disable).
210
270
  `MLX_BUN_FUSED_DECODE=1` extends the tiling to single-token decode —
@@ -225,27 +285,30 @@ agent CLIs like pi/OpenClaw via their provider config.
225
285
  Codex/Cursor/Continue speak; includes `previous_response_id`
226
286
  resumption backed by a TTL + byte-capped store (visible in /stats).
227
287
  - **`GET /v1/models`**, **`GET /stats`** (cache hit rates, bytes,
228
- active KV scheme, response store), **`GET/POST/DELETE /v1/adapters`**.
288
+ active KV scheme, response store), **`GET/POST/DELETE /v1/adapters`**,
289
+ plus **`GET /library`**, **`GET /fit`**, **`GET /downloads`**, and
290
+ **`GET /v1`** (a self-describing index of every endpoint).
229
291
 
230
292
  ## Library
231
293
 
232
- The server is one consumer of a library-first API. Not yet published to
233
- npm — clone the repo and import from `src/`. Full reference:
294
+ The server is one consumer of a library-first API. Published to npm as
295
+ `mlx-bun` (current: 0.0.4) — import from the package (`from "mlx-bun"`)
296
+ or `./src/index` in a clone; `bunx mlx-bun` runs the CLI without
297
+ installing. Full reference:
234
298
  [docs/reference/library-api.md](./docs/reference/library-api.md). For shipping inside a
235
299
  Mac app (Tauri/Electron sidecar), `./scripts/build-binary.sh` produces
236
300
  a relocatable single-binary bundle — recipe incl. signing/notarization
237
301
  in [docs/reference/embedding.md](./docs/reference/embedding.md).
238
302
 
239
303
  ```ts
240
- import { loadModelConfig } from "./src/config";
241
- import { Weights } from "./src/weights";
242
- import { Gemma4Model } from "./src/model/gemma4";
243
- import { generate } from "./src/generate";
244
- import { loadTokenizer } from "./src/tokenizer";
245
- import { ChatTemplate } from "./src/chat-template";
304
+ import {
305
+ createModel, // dispatches to Gemma4 / MiniCPM5 / Qwen3.5
306
+ Weights, loadModelConfig, loadTokenizer, ChatTemplate, generate,
307
+ } from "mlx-bun"; // or "./src/index" in a clone
246
308
 
247
309
  const dir = "/path/to/hf/snapshot";
248
- const model = new Gemma4Model(await Weights.open(dir), await loadModelConfig(dir));
310
+ const config = await loadModelConfig(dir);
311
+ const model = createModel(await Weights.open(dir), config); // RuntimeModel
249
312
  const tok = await loadTokenizer(dir);
250
313
  const template = await ChatTemplate.load(dir);
251
314
 
@@ -266,43 +329,44 @@ preamble prefills once, ever.
266
329
  ## Benchmarks
267
330
 
268
331
  Head-to-head against the Python stacks (mlx-lm 0.31.3, mlx-optiq 0.2.1),
269
- same machine (M4 Pro 24 GB), same day, same HF snapshots, preflight-gated
270
- clean machine, median-of-N with warmups discarded. Full curated table
271
- (parity / performance / quality) with per-row provenance:
272
- [benchmarks/RESULTS.md](./benchmarks/RESULTS.md).
332
+ same machine (M4 Pro 24 GB), same HF snapshots, the 2026-06-14
333
+ cleared-machine run, preflight-gated, median-of-N with warmups
334
+ discarded. Full curated table (parity / performance / quality) with
335
+ per-row provenance: [benchmarks/RESULTS.md](./benchmarks/RESULTS.md).
336
+
337
+ **Served (warm)** — how agents actually use a local model.
338
+ decode tok/s · TTFT ms · start s:
273
339
 
274
- | | mlx-bun | mlx-lm | optiq |
340
+ | model | mlx-bun | mlx-lm | optiq |
275
341
  |---|---|---|---|
276
- | **TTFT, served (warm)** | **45–90 ms** | 219–224 ms | 222–331 ms |
277
- | **server start → ready** | **0.36–0.47 s** | 0.76–0.98 s | 0.79–1.00 s |
278
- | **decode through HTTP** (e4b / 12B / 26B) | **54.5** / 25.2 / **54.9** | 53.5 / — / 52.2 | 53.5 / **25.5** / † |
279
- | **server tax vs own direct decode** | **≈ 0%** | −5…−7% | ≈ 0% |
280
- | **direct decode** (engine only) | −1.9…−4.4% vs mlx-lm | baseline | −0.8…−1.2% |
281
- | **12B decode @8k context** | 23.3 (23.0 kv-mixed) | **24.4** | 23.2 kv-mixed |
282
-
283
- Honest negatives, same table: in this matrix our direct decode trailed
284
- mlx-lm on every model (12B −1.9%, 26B −2.9%, e4b −4.4% at short
285
- context; the 12B gap grew to −4.5% @8k), and optiq's served 12B edges
286
- ours by ~1% (25.5 vs 25.2) while paying 3.7× the TTFT. **Post-matrix
287
- (2026-06-11) the decode gap was root-caused and fixed** — a
288
- prefill→decode allocator-reclaim stall that mlx-lm clears with
289
- `mx.clear_cache` and bills to prompt time (we billed it to decode);
290
- after the reference-faithful fix, same-session paired runs put the 12B
291
- *ahead* at short context (25.1 vs 24.0) and at parity @8k (23.8 vs
292
- 23.9). Clean-machine re-measure pending; e4b retains a ~5% per-step
293
- host-overhead residual (see PLAN.md "Decode gap RESOLVED"). Served through HTTP — how agents actually use a local
294
- model — mlx-bun has the fastest decode on e4b and the 26B, and the
295
- fastest TTFT and startup everywhere by 2–5×. † = cell failed: optiq
296
- serve produced no output on the 26B (the Metal OOM crash class from
297
- python's non-lazy load transient — reproduced in isolation; mlx-bun
298
- and mlx-lm both served the same model from the same machine state).
299
- One further optiq cell is blocked on an upstream optiq bug; both are
300
- documented in the results file.
301
-
302
- These numbers are the 2026-06-11 cleared-machine re-run with the
303
- long-context guard active (every @8k row verified at its requested
304
- context — an earlier harness bug had fed python @8k baselines
305
- ~31-token prompts; fixed, guarded, and re-measured).
342
+ | MiniCPM5-1B | **252.9** · 34 · 0.17 | — | 223.6 · 64 · 0.84 |
343
+ | gemma-4-e4b | **55.7** · 44 · 0.36 | 53.5 · 218 · 0.98 | 53.4 · 221 · 0.78 |
344
+ | gemma-4-12B | **25.9** · 85 · 0.38 | — | 25.5 · 326 · 1.24 |
345
+ | gemma-4-26B | **54.2** · 45 · 0.47 | 52.3 · 228 · 0.77 | — |
346
+
347
+ Across every served model mlx-bun has the fastest decode and the fastest
348
+ TTFT/startup (2–5×), at **~0% server tax** vs its own direct engine —
349
+ mlx-lm pays −5–6%, optiq −1 to −10%.
350
+
351
+ **Direct (engine only).** Decode is at parity-to-slightly-behind mlx-lm
352
+ (e4b +1.1%, 12B +0.4%, 26B −1.1%, MiniCPM5 −0.9% — within the per-step
353
+ host-overhead residual), and prefill leads on the larger models (12B
354
+ 1.2×, 26B 1.1×, MiniCPM5 2.3×; e4b trails at 0.8×). The earlier decode
355
+ deficit was root-caused and fixed (2026-06-11) — a prefill→decode
356
+ allocator-reclaim stall mlx-lm clears with `mx.clear_cache` and bills to
357
+ prompt time; see PLAN.md "Decode gap RESOLVED".
358
+
359
+ **Long context (12B).** At 16k and 64k mlx-bun holds decode parity with
360
+ mlx-lm on bf16 (16k 23.9 = 23.9; 64k 20.9 = 20.9) while optiq drops to
361
+ 21.6 then collapses to 12.3 at 64k; mixed-KV trades ~2 tok/s for ~5 GB
362
+ lower peak.
363
+
364
+ Two cross-stack served cells are absent: no mlx-lm 12B row, and optiq
365
+ produced no output on the 26B (the Metal-OOM class from python's
366
+ non-lazy load transient — reproduced in isolation; mlx-bun and mlx-lm
367
+ both served it from the same machine state). One further optiq cell
368
+ (12B/kv=config) is blocked on an upstream `quantized_matmul` bug. Both
369
+ are documented in the results file.
306
370
 
307
371
  ## Correctness
308
372
 
@@ -319,8 +383,8 @@ findings). Golden files are regenerated only by explicit scripts
319
383
  (`scripts/regen-*.ts`) running the Python oracle.
320
384
 
321
385
  ```sh
322
- bun test # fast tier runs everywhere; model-loaded tests auto-skip
323
- # unless the reference snapshot is in your HF cache
386
+ bun test # fast tier runs everywhere; model-loaded tests run only
387
+ # when the reference snapshot is in your HF cache
324
388
  ```
325
389
 
326
390
  ## Troubleshooting
@@ -343,19 +407,37 @@ bun test # fast tier runs everywhere; model-loaded tests auto-skip
343
407
  ## Status
344
408
 
345
409
  Pre-alpha, moving fast. See [PLAN.md](./PLAN.md) for phases, exit
346
- criteria, measured numbers, and the findings log. Complete: load path,
347
- bit-exact model port (12B dense / e4b per-layer-input / 26B MoE),
348
- sampling + serving (tools, vision, prompt cache), registry/fit/KV
349
- persistence, quantized + mixed-precision KV serving (rotating-cache
350
- KV-quant included, Phase 9) with fused quantized prefill (Phase 10),
351
- LoRA hot-swap with per-request selection, resumable verified downloads
352
- (`mlx-bun get`), memory admission control, and the head-to-head
353
- benchmark harness, and the decode-gap root-cause fix (clear_cache
354
- placement + boundary accounting, 2026-06-11 — 12B now at-or-above
355
- mlx-lm decode in paired runs). Open: e4b's ~5% host-overhead decode
356
- residual (Phase 7), Anthropic messages + Responses API (Phase 11),
357
- SigLIP vision for e4b/26B, Qwen 3.x, the embeddable single-binary
358
- build.
410
+ criteria, measured numbers, and the findings log.
411
+
412
+ **Complete** — load path; bit-exact model port (MiniCPM5, Qwen3.5-4B,
413
+ e4b per-layer-input, 12B dense, 26B MoE); sampling + serving (tools, vision,
414
+ prompt cache); registry / fit / KV persistence; quantized +
415
+ mixed-precision KV serving (rotating-cache KV-quant, Phase 9) with fused
416
+ quantized prefill (Phase 10); LoRA hot-swap with per-request selection;
417
+ segmented-backward LoRA training (SFT / DPO / ORPO, with an `[M,vocab]`-free
418
+ flash-CCE head + prefix-sharing for long-context preference data — `mlx-bun
419
+ train <model> --data <dir>`, see [training guide](docs/reference/training.md));
420
+ resumable
421
+ verified downloads (`mlx-bun get`); memory admission control; the
422
+ head-to-head benchmark harness; the decode-gap root-cause fix
423
+ (2026-06-11); Anthropic Messages + Responses API (`/v1/messages` and
424
+ `/v1/responses`, Phase 11); SigLIP vision sidecar for e4b
425
+ (commit 4625fe5); the embeddable single-binary build (signed +
426
+ notarized — Homebrew, direct-download, and npm/bunx).
427
+
428
+ **In progress** — `Qwen3.6-27B` bring-up (Phase 14f): same architecture
429
+ as the verified 4B (untied + larger geometry); parity and serving polish
430
+ remain. MTP speculation and Qwen3-VL vision deferred.
431
+
432
+ **Experimental** — opt-in, default-off, still being hardened: transparent
433
+ expert offload for MoE models (`serve --expert-offload`, Phase 20:
434
+ page-aligned mmap-backed experts, bit-exact — 26B-A4B 17.1→4.2 GB
435
+ resident, decode unregressed); batched serving (`--batch N`, Phase 18:
436
+ continuous-batching bf16 B=N decode, B=2 bit-parity verified for
437
+ MiniCPM5/12B/e4b/26B; throughput polish remains).
438
+
439
+ **Open** — e4b's ~5% per-step host-overhead decode residual (Phase 7);
440
+ SigLIP vision for 26B.
359
441
 
360
442
  ## License
361
443