mlx-bun 0.0.7 → 0.0.9

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 (138) hide show
  1. package/README.md +112 -20
  2. package/docs/design/batching-v2-plan.md +515 -0
  3. package/docs/design/bucketing-stage.md +196 -0
  4. package/docs/design/compat-cli-surface-design.md +11 -11
  5. package/docs/design/diffusion-gemma-port.md +602 -0
  6. package/docs/design/docs-reorg-plan.md +1 -1
  7. package/docs/design/dreaming-nightly-pipeline.md +291 -0
  8. package/docs/design/dspark-speculative-decoding.md +106 -0
  9. package/docs/design/generic-model-support.md +381 -0
  10. package/docs/design/memory-inference-path.md +422 -0
  11. package/docs/design/memory-synthesis.md +287 -0
  12. package/docs/design/minicpm5-decode-megakernel.md +484 -0
  13. package/docs/design/mlx-lm-tool-parity-plan.md +535 -0
  14. package/docs/design/orpo-dynamic-lambda.md +41 -0
  15. package/docs/design/orpo-training.md +35 -5
  16. package/docs/design/parallel-slots.md +12 -1
  17. package/docs/design/parity-tier-dag.md +13 -5
  18. package/docs/design/spec-decode-larger-targets.md +229 -0
  19. package/docs/design/tauri-desktop-app.md +2 -2
  20. package/docs/design/the-dreaming-handoff.md +141 -0
  21. package/docs/design/the-dreaming-master-plan.md +446 -0
  22. package/docs/design/write-pipeline-entity.md +468 -0
  23. package/docs/investigations/curve-bisector-routing.md +1 -1
  24. package/docs/investigations/decode-roofline-lookagain.md +262 -0
  25. package/docs/investigations/dspark-handoff.md +58 -0
  26. package/docs/investigations/kernel-perf-review-2026-07.md +92 -0
  27. package/docs/planning/PRODUCT_ROADMAP.md +2 -2
  28. package/docs/planning/curve-sampler-research-plan.md +331 -0
  29. package/docs/planning/memory-docs-and-dag-plan.md +185 -0
  30. package/docs/planning/pi-integration-review.md +178 -0
  31. package/docs/planning/release-notes-v0.0.9.md +122 -0
  32. package/docs/planning/web-ui-pass-plan.md +213 -0
  33. package/docs/planning/website-readme-pass-plan.md +224 -0
  34. package/docs/reference/cli.md +255 -0
  35. package/docs/reference/embedding.md +7 -2
  36. package/docs/reference/library-api.md +22 -3
  37. package/docs/reference/memory.md +5 -5
  38. package/docs/reference/models.md +137 -0
  39. package/docs/reference/orpo-quickstart.md +6 -0
  40. package/docs/reference/server-api.md +187 -9
  41. package/docs/reference/server-config.md +40 -9
  42. package/docs/reference/training.md +25 -11
  43. package/package.json +1 -1
  44. package/src/anthropic.ts +22 -0
  45. package/src/assets/curve-designer.html +1 -1
  46. package/src/chat-template.ts +25 -7
  47. package/src/cli.ts +1029 -86
  48. package/src/config.ts +54 -3
  49. package/src/diffusion/diffusion-generate.ts +436 -0
  50. package/src/download.ts +99 -8
  51. package/src/embed.ts +77 -0
  52. package/src/eval/perplexity.ts +164 -0
  53. package/src/eval/runner.ts +19 -7
  54. package/src/eval/tasks/bfcl.ts +1 -1
  55. package/src/generate.ts +196 -19
  56. package/src/harness-pi.ts +43 -17
  57. package/src/index.ts +2 -0
  58. package/src/lora.ts +2 -2
  59. package/src/memory/article.ts +558 -0
  60. package/src/memory/chunk-validation.ts +150 -0
  61. package/src/memory/chunk.ts +305 -12
  62. package/src/memory/cluster.ts +344 -17
  63. package/src/memory/coverage.ts +134 -0
  64. package/src/memory/crosslink.ts +0 -0
  65. package/src/memory/db.ts +184 -45
  66. package/src/memory/entity.ts +203 -0
  67. package/src/memory/gate.ts +187 -0
  68. package/src/memory/history.ts +152 -0
  69. package/src/memory/ingest.ts +324 -11
  70. package/src/memory/model.ts +321 -0
  71. package/src/memory/normalize.ts +671 -0
  72. package/src/memory/parse.ts +22 -0
  73. package/src/memory/pipeline.ts +242 -30
  74. package/src/memory/prompts.ts +42 -0
  75. package/src/memory/query.ts +334 -0
  76. package/src/memory/reconcile.ts +734 -0
  77. package/src/memory/redirect.ts +108 -0
  78. package/src/memory/reindex.ts +325 -0
  79. package/src/memory/resolve.ts +307 -0
  80. package/src/memory/route.ts +272 -0
  81. package/src/memory/schedule.ts +6 -4
  82. package/src/memory/stages.ts +774 -0
  83. package/src/memory/synthesize.ts +1629 -20
  84. package/src/memory/tools.ts +446 -96
  85. package/src/memory/vault.ts +462 -35
  86. package/src/memory/wikify.ts +1057 -16
  87. package/src/mlx/ffi.ts +11 -0
  88. package/src/mlx/ops.ts +113 -0
  89. package/src/model/compiled-decode.ts +43 -8
  90. package/src/model/diffusion-gemma.ts +1026 -0
  91. package/src/model/factory.ts +35 -8
  92. package/src/model/flash-attention.ts +4 -2
  93. package/src/model/fused-decode-kernel.ts +14 -7
  94. package/src/model/fused-mlp-kernel.ts +169 -0
  95. package/src/model/fused-swiglu-kernel.ts +240 -0
  96. package/src/model/gemma4-base.ts +62 -6
  97. package/src/model/gemma4.ts +33 -2
  98. package/src/model/minicpm5.ts +106 -8
  99. package/src/model/qwen3.ts +276 -0
  100. package/src/model/steel-linear-kernel.ts +96 -0
  101. package/src/model/support.ts +45 -7
  102. package/src/model/universal/archs.ts +332 -0
  103. package/src/model/universal/dense.ts +576 -0
  104. package/src/model/universal/modules.ts +163 -0
  105. package/src/model/universal/rope.ts +366 -0
  106. package/src/pi-provider.ts +1 -1
  107. package/src/pi-terminal.ts +29 -8
  108. package/src/pi-web.ts +19 -2
  109. package/src/quantize/config-writer.ts +1 -1
  110. package/src/registry.ts +215 -7
  111. package/src/responses.ts +23 -0
  112. package/src/sampler.ts +220 -9
  113. package/src/serve/batch-scheduler.ts +272 -80
  114. package/src/serve/generation-gateway.ts +90 -18
  115. package/src/server.ts +643 -50
  116. package/src/spec/drafter.ts +81 -49
  117. package/src/spec/dspark/data-dflash.ts +156 -0
  118. package/src/spec/dspark/data.ts +201 -0
  119. package/src/spec/dspark/generate-dflash.ts +193 -0
  120. package/src/spec/dspark/generate.ts +290 -0
  121. package/src/spec/dspark/loss.ts +213 -0
  122. package/src/spec/dspark/module-dflash.ts +361 -0
  123. package/src/spec/dspark/module.ts +540 -0
  124. package/src/spec/dspark/sample.ts +112 -0
  125. package/src/spec/generate.ts +40 -19
  126. package/src/status-page.html +1 -1
  127. package/src/tokenizer.ts +7 -0
  128. package/src/train/diffusion-lora.ts +216 -0
  129. package/src/train/flash-cce.ts +70 -15
  130. package/src/train/fuse.ts +243 -0
  131. package/src/train/index.ts +3 -0
  132. package/src/train/job.ts +8 -0
  133. package/src/train/loss.ts +289 -30
  134. package/src/train/prefix-shared.ts +33 -5
  135. package/src/train/segmented.ts +67 -11
  136. package/src/train/trainer.ts +92 -28
  137. package/src/vision/diffusion-vision.ts +620 -0
  138. package/src/web/skills/memory/SKILL.md +40 -17
package/README.md CHANGED
@@ -1,10 +1,39 @@
1
1
  # mlx-bun
2
2
 
3
+ **One command, chatting in under a minute** — a fully local AI on your
4
+ Apple Silicon Mac's GPU, no Python, no API key:
5
+
6
+ ```sh
7
+ curl -fsSL https://mlx-bun.dev/install.sh | sh
8
+ mlx-bun
9
+ ```
10
+
11
+ Docs: **[mlx-bun.dev](https://mlx-bun.dev)**
12
+
3
13
  Native MLX inference for Bun, and the beginning of a one-command local AI
4
14
  product for Apple Silicon Macs. `mlx-bun` detects the machine, starts a useful
5
15
  local assistant, exposes OpenAI/Anthropic-compatible APIs, and gives
6
16
  TypeScript apps direct access to MLX without Python or a sidecar server.
7
17
 
18
+ Six goals, in one binary:
19
+
20
+ 1. **A drop-in replacement for `mlx_lm.server`** — same port, endpoints,
21
+ request fields, and flags; stop the Python server, start `mlx-bun serve`,
22
+ the same curl works ([site guide](https://mlx-bun.dev/guides/drop-in-mlx-lm/)).
23
+ 2. **A TypeScript library** — embed MLX generation in Bun/Tauri/Electron apps,
24
+ or ship it as a signed single-binary sidecar
25
+ ([library](./docs/reference/library-api.md), [embedding](./docs/reference/embedding.md)).
26
+ 3. **Bit-exact, fast, and memory-honest** — logit parity with the Python
27
+ reference as the correctness oracle, measured speed wins, and a
28
+ deterministic `fit` memory contract ([benchmarks](#benchmarks),
29
+ [correctness](#correctness)).
30
+ 4. **One command, under a minute** — the appliance path above; the default
31
+ experience needs zero configuration ([getting started](#getting-started)).
32
+ 5. **A personal memory** — a local, git-tracked wiki your assistant reads and
33
+ (via local synthesis) writes ([memory](#personal-memory)).
34
+ 6. **An AI lab** — training, speculative decoding, and sampling research kept
35
+ next to the runtime that serves them ([the lab](#the-lab)).
36
+
8
37
  The product bet is that local AI on Mac is a finite optimization problem, not
9
38
  an infinite configuration maze: Apple ships a known set of chip/RAM/bandwidth
10
39
  SKUs, the supported model list is curated, and the task mode is explicit. That
@@ -36,7 +65,7 @@ mlx-bun
36
65
 
37
66
  Self-contained (binary + MLX runtime) and notarized, so it runs without a
38
67
  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`.
68
+ `MLX_BUN_INSTALL_DIR`, or pin a release with `MLX_BUN_VERSION=v0.0.8`.
40
69
 
41
70
  ### Homebrew
42
71
 
@@ -93,7 +122,7 @@ model named, it does everything for you:
93
122
  3. starts downloading `gemma-4-e4b` (the stronger 4B model) in the
94
123
  background — it becomes the default on your next `mlx-bun serve`;
95
124
  4. opens the chat UI in your browser at
96
- [`http://localhost:8090/#/chat`](http://localhost:8090/#/chat)
125
+ [`http://localhost:8080/#/chat`](http://localhost:8080/#/chat)
97
126
  (pass `--no-open` to skip).
98
127
 
99
128
  Want a specific model instead? Name it — `mlx-bun serve e4b` (substring
@@ -105,7 +134,7 @@ your machine.
105
134
  **Prefer the API?** It's OpenAI-compatible — any OpenAI client works:
106
135
 
107
136
  ```sh
108
- curl http://localhost:8090/v1/chat/completions \
137
+ curl http://localhost:8080/v1/chat/completions \
109
138
  -H 'Content-Type: application/json' \
110
139
  -d '{
111
140
  "messages": [{"role": "user", "content": "Hello!"}],
@@ -117,9 +146,13 @@ That's it. The server serves the one model it was started with (the
117
146
  request's `model` field is ignored and the loaded model id is echoed
118
147
  back in responses).
119
148
 
149
+ Longer walkthrough on the site:
150
+ [Installation](https://mlx-bun.dev/getting-started/installation/) and
151
+ [Quickstart](https://mlx-bun.dev/getting-started/quickstart/).
152
+
120
153
  ## What mlx-bun is
121
154
 
122
- `mlx-bun` has four faces, all sharing one native runtime:
155
+ `mlx-bun` has several faces, all sharing one native runtime:
123
156
 
124
157
  - **The local AI product** — run `mlx-bun` or `bunx mlx-bun` and get a
125
158
  working local chat UI plus a local server. The default path should feel like
@@ -128,25 +161,57 @@ back in responses).
128
161
  - **The app developer library** — embed local MLX inference inside Bun,
129
162
  Tauri, Electron, and other TypeScript applications without running Python in
130
163
  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
164
  - **The background agent runtime** — leave a local OpenAI-compatible endpoint
135
165
  available for scripts, recurring jobs, app integrations, and per-request
136
166
  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.
167
+ - **The local memory layer** and **the AI lab** — each gets its own section
168
+ below.
145
169
 
146
170
  The default experience is intentionally opinionated. Power users can override
147
171
  models, budgets, KV modes, adapters, and flags; the average user should not
148
172
  need to know those knobs exist.
149
173
 
174
+ ## Personal memory
175
+
176
+ `mlx-bun memory init` creates a git-tracked Markdown wiki at
177
+ `~/.mlx-bun/wiki`; `Reference/` is seeded with read-only symlinks to
178
+ mlx-bun's own docs, and the built-in pi agents read both those docs and your
179
+ articles quietly (`memory_search`, `memory_section`, etc.) and can open it in
180
+ Obsidian for you (`mlx-bun memory open [article]`). Chat-time memory is
181
+ read-only; synthesis is the separate writer path: `mlx-bun memory synthesize`
182
+ runs the built-in local pipeline (segment → extract → route → create/patch →
183
+ reconcile → link → wikify) that turns your conversations into cross-linked
184
+ subject articles, using the same local models with a fine-tuned chunking LoRA
185
+ adapter.
186
+
187
+ It's your data in your format: plain Markdown, git history, editable in any
188
+ tool, never leaves the machine. Reference:
189
+ [docs/reference/memory.md](./docs/reference/memory.md); synthesis design:
190
+ [docs/design/memory-synthesis.md](./docs/design/memory-synthesis.md); on the
191
+ site: [Personal memory](https://mlx-bun.dev/guides/memory/).
192
+
193
+ ## The lab
194
+
195
+ Parity, evals, kernels, training, and sampling research live next to the
196
+ runtime that serves them:
197
+
198
+ - **LoRA fine-tuning on your Mac** (SFT / DPO / ORPO) — `mlx-bun train
199
+ <model> --data <dir>`, with a flash-CCE Metal head, segmented backward, and
200
+ prefix-sharing so long-context preference training fits laptop memory;
201
+ watch runs live with `mlx-bun train-watch`
202
+ ([training](./docs/reference/training.md),
203
+ [quickstart](./docs/reference/orpo-quickstart.md)).
204
+ - **The curve designer** — HLG tone-curve sampling with an interactive
205
+ designer in the server UI at `/curves`
206
+ ([design](./docs/design/hlg-sampling.md)).
207
+ - **Speculative decoding research (DSpark)** — a KV-injection drafter
208
+ ([design](./docs/design/dspark-speculative-decoding.md)).
209
+ - The full research trail — including dead ends — is tracked in
210
+ [docs/design/](./docs/design/) and
211
+ [docs/investigations/](./docs/investigations/).
212
+
213
+ On the site: [The lab](https://mlx-bun.dev/about/lab/).
214
+
150
215
  ## Supported models
151
216
 
152
217
  Scope is deliberate: a few model families held to **bit-exact** logit
@@ -164,7 +229,9 @@ Currently MiniCPM5, the Gemma-4 OptiQ quants, and Qwen3.5-4B:
164
229
  Not sure what fits your machine? `bun src/cli.ts fit <model> --ctx 8192`
165
230
  gives a deterministic answer (see below). The larger
166
231
  `Qwen3.6-27B-OptiQ-4bit` is still in bring-up — parity and serving polish
167
- remain (see [PLAN.md](./PLAN.md)).
232
+ remain (see [PLAN.md](./PLAN.md)). Downloading, cache layout, and reclaiming
233
+ disk: [docs/reference/models.md](./docs/reference/models.md); on the site:
234
+ [Choosing a model](https://mlx-bun.dev/getting-started/models/).
168
235
 
169
236
  ## Why
170
237
 
@@ -204,8 +271,12 @@ bun src/cli.ts ls # list models (size, params, quant, capabili
204
271
  bun src/cli.ts ls --vision --max-size 10GB
205
272
  bun src/cli.ts fit gemma --ctx 32768 # memory contract: fits? max context? predicted tok/s
206
273
  bun src/cli.ts fit gemma --ctx 8192 --skus # ...same, across the Apple Silicon lineup
207
- bun src/cli.ts serve gemma --port 8090 # OpenAI-compatible server
274
+ bun src/cli.ts serve gemma --port 8080 # OpenAI-compatible server
208
275
  bun src/cli.ts serve gemma --memory-budget 18 # ...with admission control (GB)
276
+ bun src/cli.ts generate gemma "a haiku about metal shaders" # raw one-shot generation
277
+ bun src/cli.ts train e4b --data ./pref-data --method orpo # LoRA fine-tune (SFT/DPO/ORPO)
278
+ bun src/cli.ts memory init # git-tracked Markdown wiki at ~/.mlx-bun/wiki
279
+ bun src/cli.ts memory synthesize # conversations -> cross-linked wiki articles, all local
209
280
  bun src/cli.ts pi # built-in agentic coding CLI (pi's TUI, in-process)
210
281
  bun src/cli.ts evals # recorded benchmark runs
211
282
  bun src/cli.ts harness pi # connect your own pi install to the local server
@@ -223,11 +294,14 @@ MoE active-expert bytes for decode), calibrated prefill transient, and
223
294
  the machine's wired-memory ceiling. Predictions are recorded next to
224
295
  measured peaks in the eval DB.
225
296
 
297
+ Every verb, with flags: [docs/reference/cli.md](./docs/reference/cli.md);
298
+ on the site: [CLI reference](https://mlx-bun.dev/reference/cli/).
299
+
226
300
  ## HTTP API
227
301
 
228
302
  `serve` exposes an OpenAI-compatible API. Anything that speaks the
229
303
  OpenAI protocol can point at it — the OpenAI SDK
230
- (`baseURL: "http://localhost:8090/v1"`, any non-empty `apiKey`), or
304
+ (`baseURL: "http://localhost:8080/v1"`, any non-empty `apiKey`), or
231
305
  agent CLIs like pi/OpenClaw via their provider config.
232
306
 
233
307
  - **`POST /v1/chat/completions`** — streaming (SSE) and non-streaming;
@@ -278,21 +352,30 @@ agent CLIs like pi/OpenClaw via their provider config.
278
352
  up front is the only defense. Ceiling visible at `GET /stats`.
279
353
  - **Anthropic Messages API** (`POST /v1/messages`, on by default) —
280
354
  point any Anthropic-SDK tool at the server
281
- (`ANTHROPIC_BASE_URL=http://localhost:8090`); Claude Code runs
355
+ (`ANTHROPIC_BASE_URL=http://localhost:8080`); Claude Code runs
282
356
  against it as a fully local backend. Streaming event grammar, native
283
357
  tool_use/tool_result mapping, image blocks via the vision path.
284
358
  - **OpenAI Responses API** (`POST /v1/responses`) — the protocol
285
359
  Codex/Cursor/Continue speak; includes `previous_response_id`
286
360
  resumption backed by a TTL + byte-capped store (visible in /stats).
361
+ - **OpenAI Embeddings API** (`POST /v1/embeddings`) — when the served
362
+ model is an embedding model (`mlx-bun serve Qwen3-Embedding-4B-4bit-DWQ`):
363
+ last-token pooled, L2-normalized vectors, bit-exact vs mlx-lm. Also a
364
+ one-shot CLI: `mlx-bun embed <model> --text "…"`.
287
365
  - **`GET /v1/models`**, **`GET /stats`** (cache hit rates, bytes,
288
366
  active KV scheme, response store), **`GET/POST/DELETE /v1/adapters`**,
289
367
  plus **`GET /library`**, **`GET /fit`**, **`GET /downloads`**, and
290
368
  **`GET /v1`** (a self-describing index of every endpoint).
291
369
 
370
+ Guide with examples on the site:
371
+ [The HTTP API](https://mlx-bun.dev/guides/http-api/); coming from
372
+ `mlx_lm.server`:
373
+ [Drop-in for mlx-lm](https://mlx-bun.dev/guides/drop-in-mlx-lm/).
374
+
292
375
  ## Library
293
376
 
294
377
  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"`)
378
+ `mlx-bun` (current: 0.0.8) — import from the package (`from "mlx-bun"`)
296
379
  or `./src/index` in a clone; `bunx mlx-bun` runs the CLI without
297
380
  installing. Full reference:
298
381
  [docs/reference/library-api.md](./docs/reference/library-api.md). For shipping inside a
@@ -326,6 +409,9 @@ KV caches can be persisted to disk (page-aligned files that reload as
326
409
  zero-copy GPU-safe mmaps — see `src/kv-store.ts`) so a standard agent
327
410
  preamble prefills once, ever.
328
411
 
412
+ On the site: [Using the library](https://mlx-bun.dev/guides/library/) and
413
+ [Embedding in a Mac app](https://mlx-bun.dev/guides/embedding/).
414
+
329
415
  ## Benchmarks
330
416
 
331
417
  Head-to-head against the Python stacks (mlx-lm 0.31.3, mlx-optiq 0.2.1),
@@ -368,6 +454,9 @@ both served it from the same machine state). One further optiq cell
368
454
  (12B/kv=config) is blocked on an upstream `quantized_matmul` bug. Both
369
455
  are documented in the results file.
370
456
 
457
+ On the site (with the honest negatives spelled out):
458
+ [Benchmarks](https://mlx-bun.dev/about/benchmarks/).
459
+
371
460
  ## Correctness
372
461
 
373
462
  Logit parity with mlx-lm (same weights, Python reference) is the
@@ -387,6 +476,9 @@ bun test # fast tier runs everywhere; model-loaded tests run only
387
476
  # when the reference snapshot is in your HF cache
388
477
  ```
389
478
 
479
+ On the site: [Correctness](https://mlx-bun.dev/about/correctness/) and
480
+ [How it compares](https://mlx-bun.dev/about/comparison/).
481
+
390
482
  ## Troubleshooting
391
483
 
392
484
  - **`dlopen` / `libmlxc.dylib` not found** — the MLX runtime