mlx-bun 0.0.11 → 0.0.13

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 (82) hide show
  1. package/README.md +63 -27
  2. package/THIRD_PARTY_LICENSES.md +9 -0
  3. package/docs/design/colibri-glm52-port.md +1486 -0
  4. package/docs/design/pre-colibri-stabilization.md +329 -0
  5. package/docs/investigations/colibri-oracle-pin.md +1284 -0
  6. package/docs/investigations/indexshare-performance-spike.md +357 -0
  7. package/docs/planning/release-notes-v0.0.12.md +80 -0
  8. package/docs/planning/release-notes-v0.0.13.md +77 -0
  9. package/docs/reference/cli.md +28 -2
  10. package/docs/reference/distribution.md +25 -1
  11. package/docs/reference/embedding.md +5 -2
  12. package/docs/reference/features-matrix.md +5 -2
  13. package/docs/reference/library-api.md +41 -13
  14. package/docs/reference/models.md +49 -2
  15. package/docs/reference/server-api.md +113 -20
  16. package/docs/reference/server-config.md +21 -14
  17. package/docs/reference/training.md +10 -1
  18. package/package.json +1 -1
  19. package/src/anthropic.ts +54 -44
  20. package/src/chat-template.ts +189 -11
  21. package/src/cli.ts +127 -8
  22. package/src/config.ts +81 -26
  23. package/src/diffusion/diffusion-generate.ts +14 -8
  24. package/src/download.ts +103 -12
  25. package/src/eval/ifeval.ts +63 -120
  26. package/src/eval/runner.ts +14 -5
  27. package/src/eval/tasks/ifeval.ts +167 -31
  28. package/src/expert-io.ts +391 -0
  29. package/src/expert-residency.ts +1134 -0
  30. package/src/expert-usage.ts +415 -0
  31. package/src/generate.ts +114 -17
  32. package/src/hf-push.ts +1 -1
  33. package/src/index.ts +14 -2
  34. package/src/jobs/runner.ts +37 -18
  35. package/src/kv-store.ts +147 -8
  36. package/src/lora.ts +77 -14
  37. package/src/media-fetch.ts +198 -56
  38. package/src/mlx/array.ts +43 -0
  39. package/src/mlx/autograd.ts +51 -14
  40. package/src/mlx/checkpoint.ts +46 -13
  41. package/src/mlx/custom-vjp.ts +83 -35
  42. package/src/model/factory.ts +96 -5
  43. package/src/model/gemma4-base.ts +32 -0
  44. package/src/model/glm52-atlas.ts +511 -0
  45. package/src/model/glm52-cache.ts +706 -0
  46. package/src/model/glm52-config.ts +262 -0
  47. package/src/model/glm52-container.ts +305 -0
  48. package/src/model/glm52-coupling.ts +388 -0
  49. package/src/model/glm52-dsa.ts +602 -0
  50. package/src/model/glm52-expert-layout.ts +253 -0
  51. package/src/model/glm52-layout.ts +152 -0
  52. package/src/model/glm52-memory.ts +473 -0
  53. package/src/model/glm52-mla.ts +786 -0
  54. package/src/model/glm52-moe.ts +223 -0
  55. package/src/model/glm52-pilot.ts +537 -0
  56. package/src/model/glm52-reference.ts +445 -0
  57. package/src/model/glm52-residency.ts +557 -0
  58. package/src/model/glm52-resident-weights.ts +135 -0
  59. package/src/model/glm52-streamed-experts.ts +453 -0
  60. package/src/model/glm52-streamed-metal.ts +610 -0
  61. package/src/model/glm52-weights.ts +503 -0
  62. package/src/model/glm52.ts +1153 -0
  63. package/src/model/support.ts +8 -1
  64. package/src/native/expert_io.c +523 -0
  65. package/src/native-pack.ts +6 -4
  66. package/src/responses.ts +62 -49
  67. package/src/serve/batch-scheduler.ts +95 -16
  68. package/src/serve/generation-gateway.ts +41 -16
  69. package/src/server.ts +471 -93
  70. package/src/spec/glm52-mtp-source.ts +392 -0
  71. package/src/spec/serve-loop.ts +99 -18
  72. package/src/spec/source.ts +31 -6
  73. package/src/ssd-cache.ts +6 -2
  74. package/src/tool-call.ts +30 -2
  75. package/src/train/job.ts +0 -10
  76. package/src/train/lora-params.ts +17 -6
  77. package/src/train/trainer.ts +59 -26
  78. package/src/web/app.html +13 -2
  79. package/src/web/app.js +30 -3
  80. package/src/web/src/status.ts +51 -3
  81. package/src/web-tools.ts +54 -2
  82. package/src/weights.ts +82 -19
package/README.md CHANGED
@@ -90,8 +90,9 @@ nothing to install:
90
90
  bunx mlx-bun
91
91
  ```
92
92
 
93
- First run fetches the MLX native runtime (~52 MB) and the model into your
94
- caches, then serves. (Bun only — `npx mlx-bun` under Node exits with a
93
+ First run fetches the MLX native runtime plus the streamed-expert helper
94
+ (~52 MB) and the model into your caches, then serves. (Bun only — `npx
95
+ mlx-bun` under Node exits with a
95
96
  "requires Bun" notice by design.)
96
97
 
97
98
  ### From source
@@ -116,7 +117,8 @@ mlx-bun
116
117
  Bare `mlx-bun` is an alias for `mlx-bun serve`. On its first run, with no
117
118
  model named, it does everything for you:
118
119
 
119
- 1. pulls the MLX native runtime (~52 MB) into `~/Library/Caches/mlx-bun/`
120
+ 1. pulls the MLX native runtime plus streamed-expert helper (~52 MB) into
121
+ `~/Library/Caches/mlx-bun/`
120
122
  (skipped on the Homebrew install — the runtime ships in the bottle);
121
123
  2. downloads the sub-GB `MiniCPM5-1B` starter and serves it, so you're
122
124
  chatting in well under a minute;
@@ -221,9 +223,9 @@ On the site: [The lab](https://mlx-bun.dev/about/lab/).
221
223
 
222
224
  ## Supported models
223
225
 
224
- Scope is deliberate: a few model families held to **bit-exact** logit
225
- parity with the Python reference, rather than dozens held to none.
226
- Currently MiniCPM5, the Gemma-4 OptiQ quants, and Qwen3.5-4B:
226
+ Scope is deliberate: a few model families held to explicit oracle contracts,
227
+ rather than dozens held to none. Currently MiniCPM5, the Gemma-4 OptiQ quants,
228
+ the Qwen 3.x family, and the direct-container GLM-5.2 path:
227
229
 
228
230
  | Model | Download | Fits on | Vision | Notes |
229
231
  |---|---|---|---|---|
@@ -232,13 +234,33 @@ Currently MiniCPM5, the Gemma-4 OptiQ quants, and Qwen3.5-4B:
232
234
  | [`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 |
233
235
  | [`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 |
234
236
  | [`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 |
237
+ | [`mlx-community/Qwen3.8-27B-OptiQ-4bit`](https://huggingface.co/mlx-community/Qwen3.8-27B-OptiQ-4bit) | 20.4 GB | 32 GB (24 GB with `--memory-budget`) | text-only for now | Current-gen Qwen; bf16-KV bit-exact parity (vs mlx-lm); thinking with `reasoning_effort` (xhigh/medium/low) + `preserve_thinking` + tool calling; MTP speculation, vision + video in bring-up |
238
+ | [`mateogrgic/GLM-5.2-colibri-int4-with-int8-mtp`](https://huggingface.co/mateogrgic/GLM-5.2-colibri-int4-with-int8-mtp) | ~384 GB / 357 GiB | 32 GB + fast disk | — | Direct streamed Colibri container; true top-8, native MTP, bounded 25 GiB process plan; warm single-stream performance is disk-bound and below the aspirational 2 tok/s target |
235
239
 
236
240
  Not sure what fits your machine? `bun src/cli.ts fit <model> --ctx 8192`
237
- gives a deterministic answer (see below). The larger
238
- `Qwen3.6-27B-OptiQ-4bit` is still in bring-up — parity and serving polish
239
- remain (see [PLAN.md](./PLAN.md)). Downloading, cache layout, and reclaiming
240
- disk: [docs/reference/models.md](./docs/reference/models.md); on the site:
241
- [Choosing a model](https://mlx-bun.dev/getting-started/models/).
241
+ gives a deterministic answer (see below). Downloading, cache layout, and
242
+ reclaiming disk: [docs/reference/models.md](./docs/reference/models.md);
243
+ on the site: [Choosing a model](https://mlx-bun.dev/getting-started/models/).
244
+
245
+ ### GLM-5.2: 32 GB quickstart
246
+
247
+ Choose a volume with at least the artifact remainder plus 1 GiB free before
248
+ starting; mlx-bun checks this before the first payload and credits resumable
249
+ partials. The validated artifact revision and exact 25 GiB serving command are
250
+ documented in the [model-management guide](./docs/reference/models.md#glm-52-on-a-32-gb-mac):
251
+
252
+ ```sh
253
+ export HF_HUB_CACHE=/Volumes/FastSSD/huggingface/hub # optional large fast volume
254
+ mlx-bun get mateogrgic/GLM-5.2-colibri-int4-with-int8-mtp \
255
+ --revision 3cc8db99b1b13fc79325d987ba3c1c430766b3b8
256
+ mlx-bun scan
257
+ mlx-bun serve GLM-5.2-colibri --memory-budget 26.8435456 \
258
+ --context-length 4096 --max-tokens 128 --mtp on
259
+ ```
260
+
261
+ Rerun `get` after interruption; partial files resume and every completed blob
262
+ is checksum-verified. The model remains in the standard Hugging Face cache—no
263
+ Python environment and no second converted copy inside this repository.
242
264
 
243
265
  ## Why
244
266
 
@@ -278,6 +300,7 @@ bun src/cli.ts ls # list models (size, params, quant, capabili
278
300
  bun src/cli.ts ls --vision --max-size 10GB
279
301
  bun src/cli.ts fit gemma --ctx 32768 # memory contract: fits? max context? predicted tok/s
280
302
  bun src/cli.ts fit gemma --ctx 8192 --skus # ...same, across the Apple Silicon lineup
303
+ bun src/cli.ts fit GLM-5.2 # streamed plan: disk vs resident slabs + measured speed
281
304
  bun src/cli.ts serve gemma --port 8080 # OpenAI-compatible server
282
305
  bun src/cli.ts serve gemma --memory-budget 18 # ...with admission control (GB)
283
306
  bun src/cli.ts generate gemma "a haiku about metal shaders" # raw one-shot generation
@@ -299,7 +322,10 @@ listing the candidates — just make it more specific.
299
322
  headers, KV bytes/token from the config (sliding-window layers capped,
300
323
  MoE active-expert bytes for decode), calibrated prefill transient, and
301
324
  the machine's wired-memory ceiling. Predictions are recorded next to
302
- measured peaks in the eval DB.
325
+ measured peaks in the eval DB. The direct Colibri GLM-5.2 path uses its exact
326
+ streamed plan instead: full artifact-on-disk size is separated from bounded
327
+ resident weights, main/MTP expert slabs, KV, and reserves, and measured warm
328
+ decode is separated from the direct oracle and the 2 tok/s aspiration.
303
329
 
304
330
  Every verb, with flags: [docs/reference/cli.md](./docs/reference/cli.md);
305
331
  on the site: [CLI reference](https://mlx-bun.dev/reference/cli/).
@@ -315,8 +341,10 @@ agent CLIs like pi/OpenClaw via their provider config.
315
341
  `temperature`, `top_p`, `top_k`, `max_tokens`, `seed`,
316
342
  `repetition_penalty`, `stop` (string or array, matched on decoded
317
343
  text with streaming hold-back), `reasoning_effort` (thinking on/off for
318
- Qwen3.5 / MiniCPM5 — `none` disables, any level enables), and an `hlg`
319
- tone-curve sampling override;
344
+ Qwen3.5/3.8 / MiniCPM5 — `none` disables, any level enables; on Qwen3.8
345
+ the level also sets reasoning depth: `low`/`medium`/`xhigh`), a Qwen3.8
346
+ `chat_template_kwargs.preserve_thinking` toggle (keep think blocks from
347
+ history; default on), and an `hlg` tone-curve sampling override;
320
348
  omitted sampling fields default to the model's own
321
349
  `generation_config.json` recipe; usage includes `cached_tokens`.
322
350
  Full schemas in
@@ -328,13 +356,17 @@ agent CLIs like pi/OpenClaw via their provider config.
328
356
  (Gemma 4 `<|tool_call>` sentinel tokens; MiniCPM5 / Qwen3.5
329
357
  `<function name=…>` XML with schema-aware argument decoding);
330
358
  `role: "tool"` round-trips, including multi-turn agent loops.
359
+ The built-in `web_fetch` tool accepts public HTTP(S) destinations only,
360
+ revalidates DNS and every redirect, and streams into a 1 MiB response cap.
331
361
  - **Structured output** — `response_format` (JSON mode / JSON schema),
332
362
  plus the vLLM/oMLX aliases `guided_grammar`, `guided_regex`,
333
363
  `guided_choice`, and `structured_outputs`, enforced by
334
364
  grammar-constrained decoding (xgrammar) on chat and raw completions,
335
365
  serial and batched lanes alike; a grammar that fails to compile
336
- degrades to prompt injection (oMLX parity) instead of an error
337
- (`MLX_BUN_GRAMMAR=0` disables grammar-constrained decoding server-wide).
366
+ degrades to a string-valued constraint-specific prompt injection
367
+ (oMLX parity) instead of an error
368
+ (`MLX_BUN_GRAMMAR=0` disables mask compilation server-wide and routes
369
+ requested constraints through that same warning-bearing degrade path).
338
370
  - **Vision** — `image_url` content parts (data: URLs or http/s), on
339
371
  models with the vision sidecar. PNG, JPEG, HEIC, AVIF, WebP, TIFF,
340
372
  GIF, BMP via native OS codecs. Remote fetches are SSRF-guarded by
@@ -384,9 +416,12 @@ agent CLIs like pi/OpenClaw via their provider config.
384
416
  targets, not small fast models. Serial lane only — with `--batch N` a
385
417
  mounted draft routes every request serial, like mlx_lm.server.
386
418
  - **Memory admission control** — `--memory-budget <GB>` refuses to load
387
- a model that can't serve within the budget and rejects requests whose
388
- `prompt + max_tokens` exceed the budget's max safe context with a 400
389
- (`type: "memory_admission"`) *before* generating. The GPU
419
+ a model that can't serve within the budget. Generic budgeted serving rejects
420
+ requests whose `prompt + max_tokens` exceed the safe context with a 400
421
+ (`type: "memory_admission"`) *before* generating. GLM-5.2 has a fixed,
422
+ pre-planned context instead: broad client `max_tokens` values are capped to
423
+ the remaining context, and only a prompt that leaves no generation slot is
424
+ rejected. The GPU
390
425
  out-of-memory crash it prevents is uncatchable by design — rejection
391
426
  up front is the only defense. Ceiling visible at `GET /stats`.
392
427
  - **Anthropic Messages API** (`POST /v1/messages`, on by default) —
@@ -424,13 +459,12 @@ in [docs/reference/embedding.md](./docs/reference/embedding.md).
424
459
 
425
460
  ```ts
426
461
  import {
427
- createModel, // dispatches to Gemma4 / MiniCPM5 / Qwen3.5
428
- Weights, loadModelConfig, loadTokenizer, ChatTemplate, generate,
462
+ openModel, // artifact-aware, incl. bounded streamed GLM-5.2
463
+ loadTokenizer, ChatTemplate, generate,
429
464
  } from "mlx-bun"; // or "./src/index" in a clone
430
465
 
431
466
  const dir = "/path/to/hf/snapshot";
432
- const config = await loadModelConfig(dir);
433
- const model = createModel(await Weights.open(dir), config); // RuntimeModel
467
+ const model = await openModel(dir); // RuntimeModel
434
468
  const tok = await loadTokenizer(dir);
435
469
  const template = await ChatTemplate.load(dir);
436
470
 
@@ -541,7 +575,7 @@ Pre-alpha, moving fast. See [PLAN.md](./PLAN.md) for phases, exit
541
575
  criteria, measured numbers, and the findings log.
542
576
 
543
577
  **Complete** — load path; bit-exact model port (MiniCPM5, Qwen3.5-4B,
544
- e4b per-layer-input, 12B dense, 26B MoE); sampling + serving (tools, vision,
578
+ Qwen3.8-27B, e4b per-layer-input, 12B dense, 26B MoE); sampling + serving (tools, vision,
545
579
  prompt cache); registry / fit / KV persistence; quantized +
546
580
  mixed-precision KV serving (rotating-cache KV-quant, Phase 9) with fused
547
581
  quantized prefill (Phase 10); LoRA hot-swap with per-request selection;
@@ -556,9 +590,11 @@ head-to-head benchmark harness; the decode-gap root-cause fix
556
590
  (commit 4625fe5); the embeddable single-binary build (signed +
557
591
  notarized — Homebrew, direct-download, and npm/bunx).
558
592
 
559
- **In progress** — `Qwen3.6-27B` bring-up (Phase 14f): same architecture
560
- as the verified 4B (untied + larger geometry); parity and serving polish
561
- remain. MTP speculation and Qwen3-VL vision deferred.
593
+ **In progress** — `Qwen3.8-27B` full support (Phase 14 retarget): text
594
+ parity is bit-exact and thinking controls (`reasoning_effort` depths,
595
+ `preserve_thinking`) + tool calling are wired; native MTP speculation
596
+ (the Qwen-trained head as a `--draft-model`), vision, and video input
597
+ are in bring-up.
562
598
 
563
599
  **Experimental** — opt-in, default-off, still being hardened: transparent
564
600
  expert offload for MoE models (`serve --expert-offload`, Phase 20:
@@ -21,6 +21,7 @@ the upstream algorithm and is a derivative work of the original.
21
21
  | [mlx-vlm](https://github.com/Blaizzy/mlx-vlm) (BSD-3-Clause) — Gemma-4 unified `VisionEmbedder`, `MultimodalEmbedder`, image preprocessing (as vendored in mlx-optiq) | BSD-3-Clause | `src/vision/embedder.ts`, `src/vision/preprocess.ts` |
22
22
  | mlx-optiq (MIT) — vision sidecar wiring, fused quantized SDPA orchestration | MIT | `src/vision/`, quantized-KV paths in `src/model/gemma4.ts` |
23
23
  | [Pillow](https://github.com/python-pillow/Pillow) (MIT-CMU / HPND) — `ImagingResample` bicubic convolution algorithm | HPND | `resizeBicubic` in `src/vision/preprocess.ts` (algorithm port) |
24
+ | [Colibri](https://github.com/JustVugg/colibri) (pinned development oracle `44e489b196c9b7876b3d37a0570ebf1c6f90f54c`) — direct-container layout, expert-residency/I/O policy, GLM-5.2 execution and Metal-kernel reference | Apache-2.0 | Native GLM-5.2 implementation under `src/model/glm52-*`, `src/expert-*`, and `src/native/expert_io.c`; rewritten for Bun + MLX, with direct Colibri retained only as an external oracle |
24
25
 
25
26
  ## Runtime npm dependencies
26
27
 
@@ -40,3 +41,11 @@ Model weights (e.g. `mlx-community/gemma-4-12B-it-OptiQ-4bit`) are not
40
41
  part of this repository and are governed by their own licenses and use
41
42
  policies (e.g. Google's Gemma Terms of Use). Check the model card on
42
43
  Hugging Face before redistribution.
44
+
45
+ The validated GLM-5.2 direct-container artifact,
46
+ [`mateogrgic/GLM-5.2-colibri-int4-with-int8-mtp`](https://huggingface.co/mateogrgic/GLM-5.2-colibri-int4-with-int8-mtp),
47
+ declares MIT and identifies itself as a Colibri conversion/derivative of
48
+ [`zai-org/GLM-5.2-FP8`](https://huggingface.co/zai-org/GLM-5.2-FP8), with
49
+ lineage through `jlnsrk/GLM-5.2-colibri-int4` and added int8 MTP weights. The
50
+ artifact is downloaded separately into the Hugging Face cache and is not part
51
+ of the mlx-bun distribution.