mlx-bun 0.0.13 → 0.2.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 +31 -21
- package/bin/mlx-bun.mjs +1 -1
- package/docs/{design → archive}/hlg-sampling.md +3 -3
- package/docs/{investigations → archive/investigations}/hlg-sampling-investigation.md +1 -1
- package/docs/archive/investigations/pareto-specialized-runtime-findings.md +92 -0
- package/docs/{planning → archive/planning}/chat-ui-vision.md +1 -1
- package/docs/{planning → archive/planning}/release-notes-v0.0.9.md +1 -1
- package/docs/{planning → archive/planning}/website-readme-pass-plan.md +1 -1
- package/docs/design/colibri-glm52-port.md +1 -1
- package/docs/design/compat-cli-surface-design.md +1 -1
- package/docs/design/decode-speed-program.md +1 -1
- package/docs/design/docs-reorg-plan.md +1 -1
- package/docs/design/dspark-serving-program.md +1 -1
- package/docs/design/dspark-speculative-decoding.md +53 -3
- package/docs/design/grammar-spec-batching-integration.md +1 -1
- package/docs/design/mlx-lm-serving-execution-seam.md +81 -0
- package/docs/design/orpo-dynamic-lambda.md +1 -1
- package/docs/design/orpo-future-enhancements.md +1 -1
- package/docs/design/orpo-training.md +2 -2
- package/docs/design/parity-tier-dag.md +1 -1
- package/docs/design/repo-cleanup-plan.md +46 -4
- package/docs/design/segmented-backward-training.md +2 -2
- package/docs/design/ssd-kv-cold-tier.md +127 -0
- package/docs/design/turboquant-weights.md +467 -0
- package/docs/design/w4a16-compute-precision-spike.md +1 -1
- package/docs/design/web-chat-redesign.md +5 -5
- package/docs/planning/chunk-task-roadmap.md +1 -1
- package/docs/planning/curve-sampler-research-plan.md +4 -4
- package/docs/planning/memory-docs-and-dag-plan.md +1 -1
- package/docs/planning/release-notes-v0.2.0.md +49 -0
- package/docs/planning/video-series.md +421 -0
- package/docs/reference/cli.md +15 -4
- package/docs/reference/distribution.md +1 -0
- package/docs/reference/features-matrix.md +3 -2
- package/docs/reference/library-api.md +41 -1
- package/docs/reference/models.md +33 -0
- package/docs/reference/server-api.md +69 -14
- package/docs/reference/server-config.md +57 -33
- package/package.json +2 -2
- package/src/anthropic.ts +92 -3
- package/src/cli.ts +131 -36
- package/src/eval/kl.ts +27 -20
- package/src/eval/runner.ts +23 -4
- package/src/eval/tasks/bfcl.ts +2 -1
- package/src/eval/tasks/gsm8k.ts +2 -1
- package/src/eval/tasks/hashhop.ts +2 -1
- package/src/eval/tasks/humaneval.ts +5 -4
- package/src/eval/tasks/ifeval.ts +2 -1
- package/src/eval/tasks/mmlu.ts +2 -1
- package/src/expert-io.ts +3 -1
- package/src/expert-offload.ts +3 -1
- package/src/expert-trace.ts +3 -1
- package/src/fit.ts +24 -43
- package/src/flags.ts +7 -9
- package/src/generate.ts +107 -92
- package/src/grammar.ts +2 -1
- package/src/harness-pi.ts +1 -1
- package/src/index.ts +20 -0
- package/src/jobs/job-entry.ts +3 -2
- package/src/kv-scheme.ts +199 -0
- package/src/kv-store.ts +370 -205
- package/src/media-fetch.ts +19 -3
- package/src/memory/model.ts +2 -1
- package/src/memory/vault.ts +2 -1
- package/src/memory-plan.ts +18 -0
- package/src/mlx/ffi.ts +8 -11
- package/src/mlx/ops.ts +31 -6
- package/src/model/batched-mask.ts +1 -1
- package/src/model/batched-quant.ts +1 -1
- package/src/model/batched-rotating-quant.ts +43 -97
- package/src/model/batched-rotating-state.ts +73 -0
- package/src/model/batched-rotating.ts +56 -105
- package/src/model/batched-row-storage.ts +127 -0
- package/src/model/compiled-decode.ts +3 -2
- package/src/model/factory.ts +44 -49
- package/src/model/gemma4-base.ts +163 -10
- package/src/model/generated/gemma4-12b.ts +50 -146
- package/src/model/generated/gemma4-26b.ts +32 -92
- package/src/model/generated/gemma4-e4b.ts +26 -74
- package/src/model/glm52-cache.ts +19 -9
- package/src/model/glm52-memory.ts +28 -1
- package/src/model/minicpm5.ts +2 -1
- package/src/model/profile.ts +433 -0
- package/src/model/qwen3-delta.ts +98 -2
- package/src/model/qwen3-mrope.ts +252 -0
- package/src/model/qwen3_5.ts +217 -25
- package/src/native/frame_extract.swift +140 -0
- package/src/native-pack.ts +13 -6
- package/src/pi-web.ts +6 -5
- package/src/prompt-cache.ts +2 -2
- package/src/quantize/atomic-output.ts +38 -0
- package/src/quantize/calibration.ts +2 -1
- package/src/quantize/config-writer.ts +6 -0
- package/src/quantize/index.ts +28 -1
- package/src/quantize/job.ts +11 -0
- package/src/quantize/quantizer.ts +265 -100
- package/src/quantize/rotate.ts +603 -0
- package/src/quantize/safetensors-writer.ts +79 -1
- package/src/quantize/sensitivity.ts +41 -59
- package/src/quantize/weight-transform.ts +292 -0
- package/src/responses.ts +102 -2
- package/src/runtime-config.ts +67 -0
- package/src/sampler.ts +272 -0
- package/src/serve/admin-routes.ts +184 -0
- package/src/serve/aux-routes.ts +132 -0
- package/src/serve/batch-scheduler.ts +200 -87
- package/src/serve/completion-executor.ts +346 -0
- package/src/serve/completion-sink.ts +157 -0
- package/src/serve/discovery-routes.ts +205 -0
- package/src/serve/generation-gateway.ts +116 -109
- package/src/serve/kv-budget.ts +14 -0
- package/src/serve/lab-routes.ts +338 -0
- package/src/serve/model-admin-routes.ts +153 -0
- package/src/serve/prompt-response-trace.ts +147 -0
- package/src/serve/request-plan.ts +158 -0
- package/src/serve/static-routes.ts +101 -0
- package/src/server.ts +704 -1400
- package/src/spec/dflash-source.ts +2 -1
- package/src/spec/dspark/module-dflash.ts +1 -1
- package/src/spec/glm52-mtp-source.ts +8 -0
- package/src/spec/qwen-mtp-source.ts +431 -0
- package/src/spec/serve-loop.ts +36 -68
- package/src/ssd-cache.ts +17 -14
- package/src/ssd-durability.ts +195 -0
- package/src/train/flash-cce.ts +12 -11
- package/src/train/forward.ts +32 -1
- package/src/train/loss.ts +2 -1
- package/src/train/segmented.ts +4 -3
- package/src/train/trainer.ts +3 -2
- package/src/vision/preprocess.ts +1 -1
- package/src/vision/prompt.ts +47 -1
- package/src/vision/qwen3vl-preprocess.ts +409 -0
- package/src/vision/qwen3vl-prompt.ts +196 -0
- package/src/vision/qwen3vl-tower.ts +513 -0
- package/src/vision/video-frames.ts +148 -0
- package/src/web/app.js +10 -3
- package/src/web/src/chat.ts +12 -5
- package/src/weights.ts +81 -26
- /package/docs/{investigations → archive/investigations}/chunk-finetune-experiment.md +0 -0
- /package/docs/{investigations → archive/investigations}/colibri-oracle-pin.md +0 -0
- /package/docs/{investigations → archive/investigations}/curve-bisector-routing.md +0 -0
- /package/docs/{investigations → archive/investigations}/curve-runs/bisector-route.json +0 -0
- /package/docs/{investigations → archive/investigations}/curve-runs/bisector-trace.json +0 -0
- /package/docs/{investigations → archive/investigations}/curve-runs/curve-terrain.json +0 -0
- /package/docs/{investigations → archive/investigations}/curve-runs/curve-terrain.svg +0 -0
- /package/docs/{investigations → archive/investigations}/curve-terrain.html +0 -0
- /package/docs/{investigations → archive/investigations}/decode-roofline-lookagain.md +0 -0
- /package/docs/{investigations → archive/investigations}/dspark-handoff.md +0 -0
- /package/docs/{investigations → archive/investigations}/expert-offload-single-user-moe.md +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-ab.html +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-explorer.html +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-figs/cliff.svg +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-figs/cross.svg +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-figs/edges.svg +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-figs/k20-grids.svg +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-figs/k20-peaks.svg +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-figs/lw-curve.svg +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-figs/terrain.svg +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-report.html +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/hlg-ab.json +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/hlg-blind-prompts.md +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/hlg-blind.json +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/hlg-cliff.json +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/hlg-cross.json +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/hlg-edge.json +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/hlg-eval1.json +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/hlg-frontier.json +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/hlg-grid.json +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/hlg-grid2.json +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/hlg-lw-coarse.json +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/hlg-map.json +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/run0-original.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runA-recommended.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runAA-cliff-cpm5.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runAB-grid2-e4b.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runAC-peak-e4b-partial.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runAD-ab-samples.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runAE-edge-e4b.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runAF-logit-calibration.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runAG-eval-config2.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runB-gain-variants.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runC-pivots.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runD-oetf.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runE-eotf.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runF-shaper-working.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runG-shaper-sweep.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runH-wsweep.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runI-asweep.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runJ-knobmap.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runK-frontier.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runL-widemap.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runM-frontier-emb.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runN-verify.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runO-frontier-seed5000.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runP-grid-AxSm.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runQ-grid-tgW.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runR-blind-transcript.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runS-cross-coherence.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runT-cross-cpm5.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runU-cross-12b.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runV-lw-e4b.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runW-lw-12b.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runX-lw-cpm5.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runY-cliff-e4b.log +0 -0
- /package/docs/{investigations → archive/investigations}/hlg-runs/runZ-cliff-12b.log +0 -0
- /package/docs/{investigations → archive/investigations}/indexshare-performance-spike.md +0 -0
- /package/docs/{investigations → archive/investigations}/kernel-perf-review-2026-07.md +0 -0
- /package/docs/{investigations → archive/investigations}/lab-build-journal.md +0 -0
- /package/docs/{investigations → archive/investigations}/openwiki-evaluation.md +0 -0
- /package/docs/{investigations → archive/investigations}/orpo-base-uf-experiment-and-directions.md +0 -0
- /package/docs/{investigations → archive/investigations}/orpo-flash-cce-pin-leak.md +0 -0
- /package/docs/{investigations → archive/investigations}/orpo-uf-testing-handoff.md +0 -0
- /package/docs/{investigations → archive/investigations}/pi-builtin-investigation.md +0 -0
- /package/docs/{investigations → archive/investigations}/segmented-backward-handoff.md +0 -0
- /package/docs/{investigations → archive/investigations}/starter-model-port-handoff.md +0 -0
- /package/docs/{investigations → archive/investigations}/steel-flash-cce-handoff.md +0 -0
- /package/docs/{investigations → archive/investigations}/trainer-validation-experiment.md +0 -0
- /package/docs/{planning → archive/planning}/chat-ui-vision-memory-first.md +0 -0
- /package/docs/{planning → archive/planning}/journal.md +0 -0
- /package/docs/{planning → archive/planning}/release-notes-v0.0.10.md +0 -0
- /package/docs/{planning → archive/planning}/release-notes-v0.0.11.md +0 -0
- /package/docs/{planning → archive/planning}/release-notes-v0.0.12.md +0 -0
- /package/docs/{planning → archive/planning}/release-notes-v0.0.13.md +0 -0
- /package/docs/{planning → archive/planning}/web-ui-pass-plan.md +0 -0
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ runtime, so the only thing the first run fetches is the model.
|
|
|
83
83
|
|
|
84
84
|
### bunx (no install)
|
|
85
85
|
|
|
86
|
-
Already have [Bun](https://bun.sh) ≥ 1.
|
|
86
|
+
Already have [Bun](https://bun.sh) ≥ 1.4.0? Run it straight from npm,
|
|
87
87
|
nothing to install:
|
|
88
88
|
|
|
89
89
|
```sh
|
|
@@ -97,7 +97,7 @@ mlx-bun` under Node exits with a
|
|
|
97
97
|
|
|
98
98
|
### From source
|
|
99
99
|
|
|
100
|
-
Needs [Bun](https://bun.sh) ≥ 1.
|
|
100
|
+
Needs [Bun](https://bun.sh) ≥ 1.4.0 — no Python, no native library to
|
|
101
101
|
install by hand:
|
|
102
102
|
|
|
103
103
|
```sh
|
|
@@ -212,12 +212,12 @@ runtime that serves them:
|
|
|
212
212
|
[quickstart](./docs/reference/orpo-quickstart.md)).
|
|
213
213
|
- **The curve designer** — HLG tone-curve sampling with an interactive
|
|
214
214
|
designer in the server UI at `/curves`
|
|
215
|
-
([design](./docs/
|
|
215
|
+
([design](./docs/archive/hlg-sampling.md)).
|
|
216
216
|
- **Speculative decoding research (DSpark)** — a KV-injection drafter
|
|
217
217
|
([design](./docs/design/dspark-speculative-decoding.md)).
|
|
218
218
|
- The full research trail — including dead ends — is tracked in
|
|
219
219
|
[docs/design/](./docs/design/) and
|
|
220
|
-
[docs/investigations/](./docs/investigations/).
|
|
220
|
+
[docs/archive/investigations/](./docs/archive/investigations/).
|
|
221
221
|
|
|
222
222
|
On the site: [The lab](https://mlx-bun.dev/about/lab/).
|
|
223
223
|
|
|
@@ -234,7 +234,7 @@ the Qwen 3.x family, and the direct-container GLM-5.2 path:
|
|
|
234
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 |
|
|
235
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 |
|
|
236
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`) |
|
|
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`) | image + video | Current-gen Qwen; bf16-KV bit-exact parity (vs mlx-lm); thinking with `reasoning_effort` (xhigh/medium/low) + `preserve_thinking` + tool calling; native MTP head mounts as a `--draft-model` (lossless-by-verify, recurrent-cache rollback built in); **image AND video input serve** (`image_url` / `video_url` content parts — dedicated vision tower + mRoPE; video decodes via macOS-native AVFoundation, 2 fps ≤768 frames) |
|
|
238
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 |
|
|
239
239
|
|
|
240
240
|
Not sure what fits your machine? `bun src/cli.ts fit <model> --ctx 8192`
|
|
@@ -381,7 +381,9 @@ agent CLIs like pi/OpenClaw via their provider config.
|
|
|
381
381
|
- **Prompt caching** — a byte-capped LRU KV cache reuses the longest
|
|
382
382
|
common token prefix across requests (multi-turn conversations
|
|
383
383
|
re-prefill only the new turn) — automatic, no client changes.
|
|
384
|
-
Entries are adapter-specific when LoRA adapters are in play.
|
|
384
|
+
Entries are adapter-specific when LoRA adapters are in play. With
|
|
385
|
+
`--ssd-cache`, pending snapshots are flushed durably on `SIGINT`/`SIGTERM`;
|
|
386
|
+
`POST /admin/cache/flush` exposes the same boundary for automation.
|
|
385
387
|
- **LoRA hot-swap** — mount adapters at runtime (`POST /v1/adapters`)
|
|
386
388
|
and discover on-disk ones (`GET /v1/adapters/available`), select per
|
|
387
389
|
request with the `adapter` body field (`"id"`, stacked `"a+b"`, or
|
|
@@ -416,12 +418,11 @@ agent CLIs like pi/OpenClaw via their provider config.
|
|
|
416
418
|
targets, not small fast models. Serial lane only — with `--batch N` a
|
|
417
419
|
mounted draft routes every request serial, like mlx_lm.server.
|
|
418
420
|
- **Memory admission control** — `--memory-budget <GB>` refuses to load
|
|
419
|
-
a model that can't serve within the budget.
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
rejected. The GPU
|
|
421
|
+
a model that can't serve within the budget. For requests, `max_tokens`
|
|
422
|
+
is a ceiling, not a promise: a broad client value is capped to the room
|
|
423
|
+
remaining under the safe context, and only a prompt that leaves no
|
|
424
|
+
generation slot at all is rejected with a 400
|
|
425
|
+
(`type: "memory_admission"`) *before* generating. The GPU
|
|
425
426
|
out-of-memory crash it prevents is uncatchable by design — rejection
|
|
426
427
|
up front is the only defense. Ceiling visible at `GET /stats`.
|
|
427
428
|
- **Anthropic Messages API** (`POST /v1/messages`, on by default) —
|
|
@@ -478,6 +479,13 @@ for await (const t of gen) process.stdout.write(tok.decode([t.token], true));
|
|
|
478
479
|
console.log(gen.stats); // prompt/decode tok/s, cached tokens, ...
|
|
479
480
|
```
|
|
480
481
|
|
|
482
|
+
`openModel()` first resolves a declared model profile: exact immutable artifact
|
|
483
|
+
profiles outrank dedicated family paths, which outrank the generic fallback.
|
|
484
|
+
Profiles select the loader/model graph/generation loop and carry their fidelity
|
|
485
|
+
contract; they never rewrite explicit or default-resolved KV, MTP, adapter,
|
|
486
|
+
grammar, or sampling choices. `loadContext()` exposes the resolved declaration
|
|
487
|
+
as `ctx.profile`, and direct library users can call `resolveModelProfile()`.
|
|
488
|
+
|
|
481
489
|
KV caches can be persisted to disk (page-aligned files that reload as
|
|
482
490
|
zero-copy GPU-safe mmaps — see `src/kv-store.ts`) so a standard agent
|
|
483
491
|
preamble prefills once, ever.
|
|
@@ -566,7 +574,7 @@ On the site: [Correctness](https://mlx-bun.dev/about/correctness/) and
|
|
|
566
574
|
- **Slow decode on a model near your RAM ceiling** — close memory-heavy
|
|
567
575
|
apps; a model that doesn't fit the wired-memory budget pages weights
|
|
568
576
|
every token (check with `fit`).
|
|
569
|
-
- **Bun version** — requires ≥ 1.
|
|
577
|
+
- **Bun version** — requires ≥ 1.4.0 (`bun upgrade`); pinned for
|
|
570
578
|
`Bun.Image` and verified FFI behavior.
|
|
571
579
|
|
|
572
580
|
## Status
|
|
@@ -591,18 +599,20 @@ head-to-head benchmark harness; the decode-gap root-cause fix
|
|
|
591
599
|
notarized — Homebrew, direct-download, and npm/bunx).
|
|
592
600
|
|
|
593
601
|
**In progress** — `Qwen3.8-27B` full support (Phase 14 retarget): text
|
|
594
|
-
parity is bit-exact
|
|
595
|
-
`preserve_thinking`) + tool calling are wired
|
|
596
|
-
(the Qwen-trained head as a `--draft-model`)
|
|
597
|
-
are in
|
|
602
|
+
parity is bit-exact, thinking controls (`reasoning_effort` depths,
|
|
603
|
+
`preserve_thinking`) + tool calling are wired, and native MTP speculation
|
|
604
|
+
(the Qwen-trained head as a `--draft-model`) mounts through the serve
|
|
605
|
+
loop's recurrent-cache rollback contract; vision and video input are in
|
|
606
|
+
bring-up.
|
|
598
607
|
|
|
599
608
|
**Experimental** — opt-in, default-off, still being hardened: transparent
|
|
600
609
|
expert offload for MoE models (`serve --expert-offload`, Phase 20:
|
|
601
610
|
page-aligned mmap-backed experts, bit-exact — 26B-A4B 17.1→4.2 GB
|
|
602
|
-
resident, decode unregressed);
|
|
603
|
-
since 2026-07-05 —
|
|
604
|
-
|
|
605
|
-
|
|
611
|
+
resident, decode unregressed); continuous serving (`--batch N`, default 8
|
|
612
|
+
since 2026-07-05 — the scheduler's B=1 fast path uses serial-class caches and
|
|
613
|
+
the parity-gated single-row graph, while the cap permits B=N under real
|
|
614
|
+
concurrency such as coding sub-agents; `--batch 1` pins the preserved strict
|
|
615
|
+
serial executor; Phase 18: bf16 decode at mlx-lm B=N parity,
|
|
606
616
|
B=2 bit-parity verified for MiniCPM5/12B/e4b/26B; sampler extras,
|
|
607
617
|
repetition penalty, and grammar-constrained requests batch; Qwen3.5's
|
|
608
618
|
SSM caches batch, as do plain full-attention Tier-0 archs (e.g. Llama) —
|
package/bin/mlx-bun.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// (a guard inside cli.ts would never run under Node — its static imports
|
|
5
5
|
// hoist and fail on the bun: scheme first).
|
|
6
6
|
|
|
7
|
-
const MIN_BUN = "1.
|
|
7
|
+
const MIN_BUN = "1.4.0"; // fixed macOS arm64 FFI stack layout (see README)
|
|
8
8
|
|
|
9
9
|
if (typeof Bun === "undefined") {
|
|
10
10
|
console.error(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# HLG sampling — a piecewise tone curve on the logits
|
|
2
2
|
|
|
3
|
-
Status: **implemented, found neutral, superseded by Curve Designer** — `applyHlg` shipped in `src/sampler.ts`; investigation found HLG a wash vs plain temperature; the Curve Designer (`src/curve-sampler.ts`) is its v2 replacement. See [docs/investigations/hlg-sampling-investigation.md](
|
|
3
|
+
Status: **implemented, found neutral, superseded by Curve Designer** — `applyHlg` shipped in `src/sampler.ts`; investigation found HLG a wash vs plain temperature; the Curve Designer (`src/curve-sampler.ts`) is its v2 replacement. See [docs/archive/investigations/hlg-sampling-investigation.md](investigations/hlg-sampling-investigation.md) for findings. This doc remains as the design rationale.
|
|
4
4
|
Owner: sampling layer (`src/sampler.ts`)
|
|
5
5
|
Default: **off** (`--hlg-sampling off` = today's temperature sampler, untouched)
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@ Default: **off** (`--hlg-sampling off` = today's temperature sampler, untouched)
|
|
|
12
12
|
|
|
13
13
|
## Outcome / Retrospective
|
|
14
14
|
|
|
15
|
-
HLG was implemented through **Piece 2** (pure curve + neutrality tests + serial wiring, `applyHlg` live in `src/sampler.ts`). Evaluation found it **neutral vs plain temperature** — no measurable gain in diversity or quality at matched output entropy. As a result, HLG is **superseded by the Curve Designer** (`src/curve-sampler.ts`), which generalizes the same region-shaping idea with an editable control-point interface and cleaner UX. Full empirical findings are in [docs/investigations/hlg-sampling-investigation.md](
|
|
15
|
+
HLG was implemented through **Piece 2** (pure curve + neutrality tests + serial wiring, `applyHlg` live in `src/sampler.ts`). Evaluation found it **neutral vs plain temperature** — no measurable gain in diversity or quality at matched output entropy. As a result, HLG is **superseded by the Curve Designer** (`src/curve-sampler.ts`), which generalizes the same region-shaping idea with an editable control-point interface and cleaner UX. Full empirical findings are in [docs/archive/investigations/hlg-sampling-investigation.md](investigations/hlg-sampling-investigation.md).
|
|
16
16
|
|
|
17
17
|
The sections below (Goal through Correctness) remain as design rationale. Pieces 3–6 of Phasing and the Open Questions were never executed; see the [Phasing](#phasing-the-piece-n-increments) and [Open Questions](#open-questions--risks) sections for historical context.
|
|
18
18
|
|
|
@@ -347,4 +347,4 @@ for it. That a transfer function is standard practice in another domain says
|
|
|
347
347
|
nothing about whether it helps token sampling — that is decided only by
|
|
348
348
|
measurement (the KL characterization, the capability guardrail, and the
|
|
349
349
|
diversity lens in [Correctness](#correctness--evaluation)). The full empirical
|
|
350
|
-
write-up is in [docs/investigations/hlg-sampling-investigation.md](
|
|
350
|
+
write-up is in [docs/archive/investigations/hlg-sampling-investigation.md](investigations/hlg-sampling-investigation.md).
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*2026-06-14. Question: can the structure of a piecewise nonlinear transfer
|
|
4
4
|
function (HLG, the HDR transfer function) be transplanted onto a logit
|
|
5
5
|
distribution as a sampling method, and if so, where do you place its pivot
|
|
6
|
-
(middle grey)? Design contract: [docs/
|
|
6
|
+
(middle grey)? Design contract: [docs/archive/hlg-sampling.md](../design/hlg-sampling.md).
|
|
7
7
|
Code: `src/sampler.ts` (`applyHlg`, `makeSampler`). Harness:
|
|
8
8
|
`scripts/hlg-compare.ts`. Model under test: `gemma-4-e4b-it-OptiQ-4bit` on the
|
|
9
9
|
M4 Pro.*
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Pareto-specialized runtime findings
|
|
2
|
+
|
|
3
|
+
## Question
|
|
4
|
+
|
|
5
|
+
Which parts of mlx-bun should converge on shared infrastructure, and which parts should remain deliberately specialized so cleanup does not turn the runtime into a lowest-common-denominator model host?
|
|
6
|
+
|
|
7
|
+
This note compares three mature specialization clusters: the Colibri/GLM-5.2 runtime, the Qwen3.8 27B TurboQuant and MTP work, and ORPO training. The evidence says the same thing in all three places: share lifecycle and composition policy, but keep artifact layout and numerical work close to the model or method that owns them.
|
|
8
|
+
|
|
9
|
+
## Shared control-plane infrastructure
|
|
10
|
+
|
|
11
|
+
The shared layer decides what runs, owns resources, and records what happened. It does not rewrite the selected computation.
|
|
12
|
+
|
|
13
|
+
- **Model construction.** `openModel()` recognizes the direct Colibri artifact before ordinary safetensors loading. `createModel()` prefers dedicated and fingerprint-generated model classes before the universal fallback, and explicitly says the generic path must not shadow a dedicated port. This is shared dispatch with specialized implementations, not one universal graph. [Factory dispatch](../../../src/model/factory.ts#L30-L150)
|
|
14
|
+
- **Concurrency and request composition.** The target is one concurrency-driven engine. One active request uses the B=1 pipelined or compiled fast path; concurrent requests use the general step up to `--batch N`. B=1 is an internal specialization, not a permanent public lane. Features are stackable layers, and scheduling must not replace the selected KV scheme, adapter, draft method, grammar, or sampler. [Unified engine decision](../../design/unified-engine-frontier-plan.md#L333-L403) [Composition matrix](../../design/unified-engine-frontier-plan.md#L405-L424)
|
|
15
|
+
- **Cache lifecycle and capability.** `Cache` owns update, masks, state, rollback, accounting, and disposal. `BatchableCache` adds row merge, extraction, filtering, and byte projection. The scheduler can depend on those capabilities without knowing whether a row contains ordinary KV, recurrent state, TurboQuant tensors, or compressed GLM state. [Cache interface](../../../src/model/gemma4-base.ts#L264-L303) [Batchable cache interface](../../../src/model/gemma4-base.ts#L347-L357)
|
|
16
|
+
- **Resolved KV policy.** `KvScheme` preserves bf16, uniform affine, per-layer affine, and TurboQuant as distinct immutable schemes. It centralizes names, accounting, and current batch capability checks without pretending the schemes have identical storage or kernels. [KV scheme](../../../src/kv-scheme.ts#L84-L169)
|
|
17
|
+
- **Draft lifecycle.** `DraftProvider` owns server-lifetime machinery and opens a request-scoped `DraftSource`. The source interface carries prompt mode, target taps, draft, commit, rollback-related cache state, and disposal. Assistant, DSpark, Qwen MTP, and native GLM MTP can share speculative orchestration while retaining different state transitions. [Draft source](../../../src/spec/source.ts#L31-L101) [Draft provider](../../../src/spec/source.ts#L103-L118)
|
|
18
|
+
- **Expert residency policy.** The budget equation, stable expert union, lease state, backend contract, telemetry, and pressure correction are reusable. GLM supplies artifact geometry and byte segments to that policy. [Residency planning and union](../../../src/expert-residency.ts#L17-L155) [Residency backend](../../../src/expert-residency.ts#L157-L170)
|
|
19
|
+
- **Offline transform orchestration.** `WeightTransform` separates name/config planning from lazy tensor application. Llama, the Qwen3.5 trunk, and Qwen MTP are real adapters over the same conversion seam. [Weight transform interface](../../../src/quantize/weight-transform.ts#L40-L51) [Qwen transform adapters](../../../src/quantize/weight-transform.ts#L244-L268)
|
|
20
|
+
- **Training orchestration.** `TrainConfig` names independent techniques such as segmented backward, fused or flash CCE, prefix sharing, regularization, and ORPO semantics. `orpoLoop()` composes the selected techniques and chooses the model-specific backward implementation. [Training configuration](../../../src/train/trainer.ts#L42-L150) [ORPO composition](../../../src/train/trainer.ts#L821-L948)
|
|
21
|
+
|
|
22
|
+
## Deliberately specialized data-plane code
|
|
23
|
+
|
|
24
|
+
### Colibri and GLM-5.2
|
|
25
|
+
|
|
26
|
+
GLM-5.2 is not a descriptor-table variation of a dense transformer. Its graph has MLA, DSA, shared plus routed MoE, native MTP, and compressed cache state. Its public artifact also has a dedicated container and streamed expert layout. The design therefore calls for a dedicated `Glm52Model`, direct artifact support, and a one-read routed-expert kernel rather than repacking into generic projection-major tensors. [Dedicated graph and artifact contract](../../design/colibri-glm52-port.md#L323-L357)
|
|
27
|
+
|
|
28
|
+
The memory contract is also model and artifact specific. A header-only preflight reads the container, derives expert slot layouts, counts DSA and MTP state, and refuses startup when the exact resident weights, expert slabs, compressed KV, verification transients, allocator reserve, Bun reserve, and safety margin exceed the process limit. [GLM geometry and preflight](../../../src/model/glm52-memory.ts#L340-L500) The runtime then maps Colibri segments into generic residency leases, but retains GLM-specific slot layouts, MTP slabs, signed-int8 requirements, and routed-SwiGLU executors. [GLM residency binding](../../../src/model/glm52-residency.ts#L138-L230) [GLM executor construction](../../../src/model/glm52-residency.ts#L300-L459)
|
|
29
|
+
|
|
30
|
+
That split is intentional. Bun owns residency policy and observability; the native helper owns aligned slabs, `pread`, wiring, and completion fences; the GLM model owns tensor semantics and kernels. [Ownership map](../../design/colibri-glm52-port.md#L580-L600)
|
|
31
|
+
|
|
32
|
+
### Qwen3.8 27B, TurboQuant, and MTP
|
|
33
|
+
|
|
34
|
+
Qwen3.5/3.8 keeps a dedicated graph because gated DeltaNet recurrence, full attention, MRoPE, output gates, and recurrent speculative rollback are numerical behavior, not configuration decoration. [Qwen graph](../../../src/model/qwen3_5.ts#L128-L322) [Qwen model interface](../../../src/model/qwen3_5.ts#L512-L673)
|
|
35
|
+
|
|
36
|
+
Qwen MTP preserves its own artifact and state machine behind `DraftProvider` and `DraftSource`. The provider rejects a non-Qwen target or a hidden-size mismatch. The request source uses tapped pre-final-norm target state, maintains its own KV, samples through the target sampler, and rebuilds accepted rows from verified target hiddens. Those rules must not move into generic speculative orchestration. [Qwen MTP provider](../../../src/spec/qwen-mtp-source.ts#L193-L235) [Qwen MTP state machine](../../../src/spec/qwen-mtp-source.ts#L237-L430)
|
|
37
|
+
|
|
38
|
+
TurboQuant KV demonstrates the right form of specialization. `TurboQuantKVCache` implements the shared `Cache` lifecycle, while keeping packed indices, scales, zero points, FWHT-domain values, supported head dimensions, and conversion rules inside the class. [TurboQuant cache](../../../src/model/gemma4-base.ts#L1539-L1800) The weight pipeline follows the same rule. `WeightTransform` is shared, but the Qwen corridor map preserves the output gate, recurrent internals, vision-to-residual seam, untied 27B head, and companion MTP basis. [Qwen transform seam](../../design/turboquant-weights.md#L80-L87) [Qwen corridor map](../../design/turboquant-weights.md#L125-L174)
|
|
39
|
+
|
|
40
|
+
### ORPO training
|
|
41
|
+
|
|
42
|
+
ORPO benefits from composition, not one generic backward. The trainer combines prefix sharing, segmented recomputation, fused or flash CCE, LoRA regularization, and objective semantics. The data plane remains specialized where the model topology demands it. Gemma4 segmented ORPO threads per-layer inputs and cross-segment donor KV cotangents; MiniCPM5 uses a simpler segment graph. [Composed ORPO paths](../../design/orpo-training.md#L178-L218) [Gemma4 segmented backward](../../../src/train/segmented.ts#L1137-L1471)
|
|
43
|
+
|
|
44
|
+
Flash CCE is a shared quantized-head interface with specialized Metal kernels and explicit shape guards. Its implementation selects Steel, simdgroup, or scalar kernels from actual hidden, vocabulary, group, and tile geometry, and exposes exact-gradient escape hatches. Flattening this into a generic matrix-loss helper would lose the memory and watchdog constraints that justify it. [Flash CCE head](../../../src/train/flash-cce.ts#L42-L64) [Forward dispatch](../../../src/train/flash-cce.ts#L1033-L1132) [Backward dispatch](../../../src/train/flash-cce.ts#L1134-L1234)
|
|
45
|
+
|
|
46
|
+
Dynamic lambda is not implemented. Its design belongs in the ORPO control plane: validation metrics update a live lambda source in `orpoLoop()`, while every monolithic and segmented loss reads the same value. It should not create another family of backward classes. [Dynamic-lambda status and signals](../../design/orpo-dynamic-lambda.md#L1-L27) [Proposed wiring](../../design/orpo-dynamic-lambda.md#L163-L180)
|
|
47
|
+
|
|
48
|
+
## Interfaces that already preserve specialization
|
|
49
|
+
|
|
50
|
+
| Interface | Shared invariant | Specialization retained behind it |
|
|
51
|
+
|---|---|---|
|
|
52
|
+
| `RuntimeModel` plus factory dispatch | Construction and serving can hold one model type | Dedicated GLM, Qwen, Gemma, diffusion, MoE, and generated graphs |
|
|
53
|
+
| `Cache` / `BatchableCache` | Lifecycle, rollback, row operations, byte projection | Plain, rotating, quantized, TurboQuant, SSM, MLA, and DSA storage |
|
|
54
|
+
| `KvScheme` | One resolved KV choice and stable identity | Per-scheme accounting, conversion, persistence, and kernels |
|
|
55
|
+
| `DraftProvider` / `DraftSource` | Request lifecycle, target taps, draft and commit | Assistant, DSpark, Qwen MTP, and GLM MTP state machines |
|
|
56
|
+
| `ExpertResidencyBackend` | Lease and I/O lifecycle | Colibri container offsets, slot packing, expert kernels, and prediction policy inputs |
|
|
57
|
+
| `WeightTransform` | Plan first, apply lazily, record identity | Family-specific exact fold corridors and companion artifacts |
|
|
58
|
+
| ORPO trainer configuration | One run composes selected techniques | Model-specific masks, donor topology, VJPs, and Metal kernels |
|
|
59
|
+
|
|
60
|
+
## Declared profile seam (S2, 2026-08-21)
|
|
61
|
+
|
|
62
|
+
Model construction now resolves one `ResolvedModelProfile` before opening
|
|
63
|
+
weights. An exact artifact declaration binds an immutable external fingerprint,
|
|
64
|
+
config fingerprint, fidelity contract, required engine capabilities, and a
|
|
65
|
+
loader/graph/loop composition. Exact Qwen3.8 OptiQ and GLM-5.2 Colibri revisions
|
|
66
|
+
are pinned; other supported artifacts retain dedicated family resolution and
|
|
67
|
+
then the universal dense fallback.
|
|
68
|
+
|
|
69
|
+
The factory consumes the resolved composition, and the serving context retains
|
|
70
|
+
it for library callers. A matched exact declaration with a config or capability
|
|
71
|
+
mismatch refuses rather than taking another route. The profile seam does not
|
|
72
|
+
own request methods: MTP, KV schemes, adapters, grammar, and sampling remain
|
|
73
|
+
independently resolved inputs to completion execution. This keeps the control
|
|
74
|
+
plane declarative without turning a model profile into a feature preset.
|
|
75
|
+
|
|
76
|
+
These interfaces preserve specialization because they describe lifecycle or capability, not tensor algebra. They also have multiple real implementations. That is the useful test for whether an abstraction belongs.
|
|
77
|
+
|
|
78
|
+
## Rules for steady-state cleanup
|
|
79
|
+
|
|
80
|
+
1. **Unify control, not math.** Centralize admission, concurrency, cancellation, ownership, accounting, persistence, telemetry, and technique composition. Keep tensor layout, recurrence, cache encoding, model topology, and kernel selection with their owning model, artifact, or method.
|
|
81
|
+
2. **Keep one concurrency-driven engine.** B=1 and B>1 are internal step specializations in one engine. `--batch N` is a concurrency cap. Observed placement may be reported, but serial versus batch must not become a permanent public mode or feature-selection interface. Current feature-specific serial routing is capability debt.
|
|
82
|
+
3. **Never weaken a resolved composition to fit a path.** If batching lacks TurboQuant, MTP, adapters, grammar, or another selected method, close that capability gap or reject the unsupported composition. Do not silently substitute bf16 KV, disable drafting, or change sampling.
|
|
83
|
+
4. **Prefer capability interfaces over family checks.** Scheduling should ask caches whether they can merge or project bytes and draft sources what target state they require. Factory dispatch is the proper place for model identity checks.
|
|
84
|
+
5. **Let dedicated ports outrank generic fallbacks.** The universal model path is valuable for ordinary architectures. It must not absorb GLM MLA/DSA, Qwen recurrence, artifact-specific MTP, or another optimized graph merely to reduce class count.
|
|
85
|
+
6. **Treat artifacts as executable contracts.** Validate manifests, tensor families, layouts, quantization metadata, companion seeds, and memory equations before allocation. Keep artifact-specific loaders and transforms when repacking would add copies, lose reproducibility, or change arithmetic.
|
|
86
|
+
7. **Generalize only after the invariant is visible in two implementations.** Extract lifecycle and capability seams such as `DraftSource` or `WeightTransform`. Do not extract a common tensor algorithm from code that only looks similar but has different masks, state, accumulation order, or oracle.
|
|
87
|
+
8. **Compose optimizations at the orchestrator, then test the cross-product.** ORPO proves that prefix sharing, flash CCE, segmented backward, and regularization can stack while model-specific backward code remains intact. Serving needs the same discipline for model graph, KV scheme, MTP, adapters, grammar, sampling, and concurrency.
|
|
88
|
+
9. **Bind every specialized path to its own oracle and measured purpose.** A specialized module earns its place through parity, memory, quality, or throughput gates on the artifact and hardware it targets. If the benefit disappears, delete the specialization instead of preserving it as architecture folklore.
|
|
89
|
+
|
|
90
|
+
## Strongest conclusion
|
|
91
|
+
|
|
92
|
+
The steady state is not a generic engine with scattered exceptions. It is a shared control plane that carries authoritative compositions through one concurrency-driven engine, plus specialized data planes selected by model, artifact, and numerical method. That structure preserves the project's Pareto advantage: common serving and training behavior where sameness is real, and unapologetically specific code where the result depends on it.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# The mlx-bun chat surface: a vision
|
|
2
2
|
|
|
3
|
-
*Draft vision, product/design lead pass — 2026-07-06. Bold stance: reimagine the chat surface from scratch. Companion to the market research and current-state audit that produced it; see `docs/planning/web-ui-pass-plan.md` for the tactical bug list and `docs/design/adapters-end-to-end.md` / `docs/design/memory-system.md` for the backend contracts this vision assumes.*
|
|
3
|
+
*Draft vision, product/design lead pass — 2026-07-06. Bold stance: reimagine the chat surface from scratch. Companion to the market research and current-state audit that produced it; see `docs/archive/planning/web-ui-pass-plan.md` for the tactical bug list and `docs/design/adapters-end-to-end.md` / `docs/design/memory-system.md` for the backend contracts this vision assumes.*
|
|
4
4
|
|
|
5
5
|
## The feeling
|
|
6
6
|
|
|
@@ -117,6 +117,6 @@ overturning a load-bearing performance assumption.
|
|
|
117
117
|
"failures" were M4-Pro fixtures; all code exonerated — mlx-lm reproduces
|
|
118
118
|
mlx-bun token-for-token per machine); CI gate (typecheck + model-free tests).
|
|
119
119
|
- **Research (the lab):** decode-roofline re-measurement overturned the "at
|
|
120
|
-
the floor" assumption (docs/investigations/decode-roofline-lookagain.md);
|
|
120
|
+
the floor" assumption (docs/archive/investigations/decode-roofline-lookagain.md);
|
|
121
121
|
curve-sampler distinctness theorem + witness numbers + preregistered
|
|
122
122
|
protocol (docs/planning/curve-sampler-research-plan.md).
|
|
@@ -20,7 +20,7 @@ Two coherent options:
|
|
|
20
20
|
|
|
21
21
|
- **(A) Recommended: cut v0.0.9, then deploy the site.** All docs become
|
|
22
22
|
true simultaneously; nothing below needs version annotations. The
|
|
23
|
-
release-notes draft already exists (`docs/planning/release-notes-v0.0.9.md`).
|
|
23
|
+
release-notes draft already exists (`docs/archive/planning/release-notes-v0.0.9.md`).
|
|
24
24
|
- **(B)** If v0.0.9 is not imminent: hold site deploys, and treat every
|
|
25
25
|
item marked *v0.0.9* below as blocked. (Reverting docs to 8090 is churn
|
|
26
26
|
for nothing — don't.)
|
|
@@ -692,7 +692,7 @@ batch.
|
|
|
692
692
|
|
|
693
693
|
G0 inventory note (2026-07-21): the exact pin, artifact/layout contract, and
|
|
694
694
|
manual checklist are recorded in
|
|
695
|
-
[`../investigations/colibri-oracle-pin.md`](../investigations/colibri-oracle-pin.md).
|
|
695
|
+
[`../archive/investigations/colibri-oracle-pin.md`](../archive/investigations/colibri-oracle-pin.md).
|
|
696
696
|
Because the pinned Makefile writes ignored build artifacts and even creates a
|
|
697
697
|
configuration stamp while parsing, model-free oracle targets must run from a
|
|
698
698
|
temporary `git archive` extraction, not in the read-only checkout. The pinned
|
|
@@ -85,7 +85,7 @@ mlx-lm" half.
|
|
|
85
85
|
|
|
86
86
|
### pi — the built-in agentic coding CLI
|
|
87
87
|
|
|
88
|
-
(Phase 16; full plan in **docs/investigations/pi-builtin-investigation.md**.) pi is an
|
|
88
|
+
(Phase 16; full plan in **docs/archive/investigations/pi-builtin-investigation.md**.) pi is an
|
|
89
89
|
MIT, Bun-native (`bun build --compile`) coding agent — the "CLI
|
|
90
90
|
experience inside our package" that neither Python package has. Two
|
|
91
91
|
commands, one for each audience:
|
|
@@ -66,7 +66,7 @@ grammar composition, and `usage.speculation` telemetry ALL landed
|
|
|
66
66
|
serve wiring: 27B/12B retarget (regen+train, Josh's shell), data scale
|
|
67
67
|
(thousands of on-distribution generations vs 160), draft-loop
|
|
68
68
|
tightening. At τ≈3 on the 27B agent workload: **~15 → ~35–45 tok/s**
|
|
69
|
-
(docs/investigations/dspark-handoff.md). Slots in as `DflashSource`,
|
|
69
|
+
(docs/archive/investigations/dspark-handoff.md). Slots in as `DflashSource`,
|
|
70
70
|
no-oracle/KL-gated (a Lab item).
|
|
71
71
|
|
|
72
72
|
### 2. mlx bump — narrow 26B / spec-decode wins, NOT a general decode lever [main-only, from-source]
|
|
@@ -140,7 +140,7 @@ files, not benchmark output. Leave entirely alone.
|
|
|
140
140
|
| 5 | Add `STATUS.md` (or a pinned top section in PLAN.md) holding only live handoff: current state + next action + blockers. Move PLAN.md's `NEXT UP` / `NEXT SESSION PICKUP` / `SESSION SWEEP` blocks into it. | Separates transient "do this next" from 2,475 lines of durable phase history; gives agents one entry point. |
|
|
141
141
|
| 6 | Create `docs/planning/` and move `PRODUCT_ROADMAP.md`, `IDEAS.md`, `ResearchTopics.md`, `journal.md` under it. Leave only README + PLAN.md (+ STATUS.md) at root. Add a ~6-line "doc map" to README. | Root is currently a 6-file planning thicket; extends the taxonomy that already works in `docs/`. |
|
|
142
142
|
| 7 | Pick one home for the optimization plan: fold `docs/design/optimization_plan.md` into PLAN.md Phase A–E, or have PLAN.md link out to it as canonical. | Two homes for the same plan = drift. |
|
|
143
|
-
| 8 | Resolve the archive overlap: `archive/pi-builtin-investigation.html` duplicates [docs/investigations/pi-builtin-investigation.md](../investigations/pi-builtin-investigation.md). Decide whether `archive/` (tracked; 2 HTML files: `mlx-bun-lab-report.html` + `wwdc-mlx-bun.html`) should be tracked at all, or moved to an ignored location. Keep the `.md`, drop the duplicate. | Stops committing heavyweight generated HTML; one source per investigation. |
|
|
143
|
+
| 8 | Resolve the archive overlap: `archive/pi-builtin-investigation.html` duplicates [docs/archive/investigations/pi-builtin-investigation.md](../archive/investigations/pi-builtin-investigation.md). Decide whether `archive/` (tracked; 2 HTML files: `mlx-bun-lab-report.html` + `wwdc-mlx-bun.html`) should be tracked at all, or moved to an ignored location. Keep the `.md`, drop the duplicate. | Stops committing heavyweight generated HTML; one source per investigation. |
|
|
144
144
|
|
|
145
145
|
## P2 — Polish (optional)
|
|
146
146
|
|
|
@@ -4,7 +4,7 @@ Status: **PLANNED** (2026-07-07). Trigger for Josh's pickup: TurboQuant merge
|
|
|
4
4
|
but only Phase 5 actually depends on it; Phases 0–4 are start-anytime.
|
|
5
5
|
Owner: decode / spec. Predecessors: PR #19 (DSpark paper code-complete +
|
|
6
6
|
serve-integrated + DeepSpec oracle), the first-live-run findings in
|
|
7
|
-
[dspark-handoff.md](../investigations/dspark-handoff.md) "FIRST LIVE RUN".
|
|
7
|
+
[dspark-handoff.md](../archive/investigations/dspark-handoff.md) "FIRST LIVE RUN".
|
|
8
8
|
|
|
9
9
|
## The problem, in numbers (2026-07-07 first live run, loaded machine)
|
|
10
10
|
|
|
@@ -247,6 +247,56 @@ regenerated by the target, 10 epochs, batch 512, lr 6e-4, position decay
|
|
|
247
247
|
exp(−pos/4), ~38 TB cached hiddens — i.e. our "thousands of generations" data
|
|
248
248
|
estimate was directionally right and their scale is far beyond a laptop run.
|
|
249
249
|
|
|
250
|
+
## 27B program (2026-08-19): the TQ quant unlocks the real target
|
|
251
|
+
|
|
252
|
+
The turboquant-weights campaign shipped rot-sens48 Qwen3.8-27B at 17 GB
|
|
253
|
+
(docs/design/turboquant-weights.md) — and it changes both DSpark blockers
|
|
254
|
+
this doc recorded:
|
|
255
|
+
|
|
256
|
+
- **Target speed:** measured ~11.8 tok/s decode. This is the slow-target
|
|
257
|
+
regime where the doc's own analysis says τ≈3 nets 2–3× (≈25–35 tok/s) —
|
|
258
|
+
"the ideal target and the real motivation," now actually runnable.
|
|
259
|
+
- **Training feasibility:** "27B memory-infeasible to train on 24 GB" (open
|
|
260
|
+
items below) assumed the bf16 trunk (54 GB). With the quantized trunk
|
|
261
|
+
FROZEN (inference-only: hidden taps + teacher logits) and only the small
|
|
262
|
+
drafter (~5 layers) holding grads/optimizer state in bf16, 27B-target
|
|
263
|
+
drafter training fits a 32 GB machine. The premise is dead; the line in
|
|
264
|
+
the gated item is superseded by this section.
|
|
265
|
+
- **Rollback risk retired:** the stock Qwen-MTP spec path already serves
|
|
266
|
+
this model losslessly (68% per-token acceptance), so verify/rollback
|
|
267
|
+
across the 48 DeltaNet recurrent-state layers is proven engine behavior,
|
|
268
|
+
not new work.
|
|
269
|
+
|
|
270
|
+
Two tracks, cheap-first:
|
|
271
|
+
|
|
272
|
+
- **Track A — confidence-scheduled verification on the stock MTP head (no
|
|
273
|
+
drafter training).** Dynamic per-step block length instead of fixed
|
|
274
|
+
`--num-draft-tokens`: v0 confidence = the draft's own token probability
|
|
275
|
+
(no trained head), mapped through STS calibration
|
|
276
|
+
(`scripts/dspark-calibrate.ts` pattern) to expected acceptance; the
|
|
277
|
+
scheduler stops drafting when marginal expected-accept drops below the
|
|
278
|
+
verify amortization point. Calibration needs thousands of
|
|
279
|
+
(confidence, accepted?) pairs from served traffic — hours, not weeks.
|
|
280
|
+
Gate: paired A/B decode tok/s vs fixed-γ MTP on the same prompts;
|
|
281
|
+
lossless by construction (verify unchanged).
|
|
282
|
+
- **Track B — true DSpark drafter for the 27B (multi-token single-pass).**
|
|
283
|
+
The faithful v2 (KV injection, Markov head) retargeted: `hiddenTap` added
|
|
284
|
+
to `qwen3_5.ts` forwardLayers (gemma4 has it; parity-safe no-op when
|
|
285
|
+
off), tap-layer selection for the 64-layer trunk (bias toward the 16
|
|
286
|
+
full-attention layers + post-finalNorm), data generated by TEACHER-FORCED
|
|
287
|
+
passes over corpus text with the frozen quantized trunk (every position
|
|
288
|
+
of a forward yields a sample — data scale is forward-passes over tokens,
|
|
289
|
+
not generate calls). Open idea: distill from / initialize against the
|
|
290
|
+
shipped MTP head to shortcut the acceptance floor. Gate: generalizing
|
|
291
|
+
per-position acceptance must beat the MTP head's 0.68 or Track B loses to
|
|
292
|
+
Track A + MTP and gets dropped.
|
|
293
|
+
|
|
294
|
+
Sequencing: after the benchmark campaign closes (GPU is owned by the
|
|
295
|
+
certification suite). Track A first — it's measurable in a day and its
|
|
296
|
+
calibration data collection is also Track B's baseline instrumentation.
|
|
297
|
+
Adapters/DSpark drafts trained on the TQ artifact are married to its
|
|
298
|
+
rotation basis (fine for our bundle; note on the card if published).
|
|
299
|
+
|
|
250
300
|
## Open items / next
|
|
251
301
|
|
|
252
302
|
- [x] Serve integration (Phase 1) · [x] Alg-1-shaped scheduler (matches the
|
|
@@ -258,11 +308,11 @@ estimate was directionally right and their scale is far beyond a laptop run.
|
|
|
258
308
|
oracle scripts — the no-training path to the 12B speedup (in progress).
|
|
259
309
|
- [ ] **Josh-gated GPU (the payoff):** real data scale (thousands of
|
|
260
310
|
on-distribution generations) + **retarget to 12B** (`--model` +
|
|
261
|
-
`--tap-layers 5,17,29,41,46` (DeepSeek's trained taps); 27B memory-infeasible to train on 24 GB, kept
|
|
311
|
+
`--tap-layers 5,17,29,41,46` (DeepSeek's trained taps); ~~27B memory-infeasible to train on 24 GB~~ (superseded — the 17 GB TQ trunk makes it feasible; see "27B program" above), kept
|
|
262
312
|
dim-generic) + train (`--seq-head` A/B optional) + **calibrate**
|
|
263
313
|
(`scripts/dspark-calibrate.ts`) + live-τ measure. Recipe:
|
|
264
|
-
[docs/investigations/dspark-handoff.md](../investigations/dspark-handoff.md).
|
|
314
|
+
[docs/archive/investigations/dspark-handoff.md](../archive/investigations/dspark-handoff.md).
|
|
265
315
|
- [ ] Verify the Eq 6 / §3.2.1 shapes against the actual paper when the PDF
|
|
266
316
|
is available (both flagged in code).
|
|
267
317
|
|
|
268
|
-
Full session handoff: `docs/investigations/dspark-handoff.md`.
|
|
318
|
+
Full session handoff: `docs/archive/investigations/dspark-handoff.md`.
|
|
@@ -15,7 +15,7 @@ three workstreams so they compose deliberately instead of colliding:
|
|
|
15
15
|
(docs/design/batching-perf-path.md).
|
|
16
16
|
- **Speculative decoding** — research proven (assistant drafter bit-exact
|
|
17
17
|
vs optiq, 12B γ=1 ≈ 1.09× win, docs/design/spec-decode-larger-targets.md;
|
|
18
|
-
DSpark architecture verified, docs/investigations/dspark-handoff.md) but
|
|
18
|
+
DSpark architecture verified, docs/archive/investigations/dspark-handoff.md) but
|
|
19
19
|
**not served**: no `--draft-model`. Build plan already written:
|
|
20
20
|
docs/design/mlx-lm-tool-parity-plan.md §7 (the `DraftSource` interface,
|
|
21
21
|
two-model L1 source, serve loop, admission, prompt-cache composition).
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# mlx-lm serving execution seam
|
|
2
|
+
|
|
3
|
+
## Question
|
|
4
|
+
|
|
5
|
+
What should mlx-bun borrow from the pinned mlx-lm oracle when deepening Completion execution around this flow?
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
prepared prompt -> semantic events -> terminal summary
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This note reads the local mlx-lm 0.31.3 source installed in the reference venv. The comparison uses the serving term defined in `CONTEXT.md`: a **Completion execution** includes output, resource lifetime, usage, and scheduling placement.
|
|
12
|
+
|
|
13
|
+
mlx-lm is the correctness oracle only for behavior and numeric schemes it implements. It is not mlx-bun's architecture oracle or capability ceiling. mlx-bun also implements explicitly selected features such as mixed-precision KV, TurboQuant, and native draft methods. The execution path must preserve those resolved settings exactly.
|
|
14
|
+
|
|
15
|
+
## Implementation status
|
|
16
|
+
|
|
17
|
+
The first consolidation slice landed on 2026-08-21. `prepareCompletion()` performs admission before a streaming response starts and returns an opaque, single-use `PreparedCompletion`. `CompletionExecutor.execute()` then owns placement reporting, `CompletionSink`, logprobs, semantic event delivery, finish reason, usage, and pre-generation cleanup. [`completion-executor.ts:75`](/Users/joshrossi/.codex/worktrees/e408/mlx-bun/src/serve/completion-executor.ts:75) [`completion-executor.ts:219`](/Users/joshrossi/.codex/worktrees/e408/mlx-bun/src/serve/completion-executor.ts:219)
|
|
18
|
+
|
|
19
|
+
Chat and raw-text adapters still declare their semantic components and format their own wire responses. Their streaming and non-streaming branches now call the same executor. `GenerationGateway` still owns placement and model execution. The change does not add or remove flags, alter defaults, or substitute one inference method for another.
|
|
20
|
+
|
|
21
|
+
S3 completed the scheduling declaration at the same seam. A
|
|
22
|
+
`GenerationPlacement` now names `serial` or `continuous`; it no longer calls a
|
|
23
|
+
lone scheduler request "batched." The continuous scheduler chooses its B=1
|
|
24
|
+
fast path or B=N step from active rows. The strict serial executor remains for
|
|
25
|
+
`--batch 1` and for declared compositions the continuous scheduler does not yet
|
|
26
|
+
implement. Existing parity evidence covers both the default scheduler's B=1
|
|
27
|
+
path and strict serial. The recorded scheduler/serial decode ratios are
|
|
28
|
+
0.992–0.996, and a fresh main-vs-branch serial gate after the sampler
|
|
29
|
+
consolidation measured a 1.000 median-best ratio (about 265.0 tok/s on both
|
|
30
|
+
sides, MiniCPM5, two interleaved 256-token repeats).
|
|
31
|
+
|
|
32
|
+
Final acceptance after the GPQA pause exercised the seam through the complete
|
|
33
|
+
two-shard suite and a real two-turn browser conversation. The suite passed
|
|
34
|
+
2,064 tests with zero failures. The browser run verified streaming, tool
|
|
35
|
+
events, context carryover, metrics, and turn recovery. A mainline-only queued
|
|
36
|
+
DOM render race found by that run was fixed at the UI lifecycle boundary; no
|
|
37
|
+
decode-loop work was added. The architecture changes likewise keep accounting
|
|
38
|
+
and capability decisions outside numerical kernels. The fresh serial A/B plus
|
|
39
|
+
the established scheduler B=1 parity and latency evidence are the performance
|
|
40
|
+
gate.
|
|
41
|
+
|
|
42
|
+
## What the oracle actually does
|
|
43
|
+
|
|
44
|
+
The HTTP adapter creates a small `CompletionRequest` that still contains protocol-shaped chat messages or a raw text prompt. It separately builds `GenerationArguments`. Prompt preparation has not happened yet. [`server.py:182`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:182) [`server.py:198`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:198) [`server.py:1368`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1368)
|
|
45
|
+
|
|
46
|
+
`ResponseGenerator.generate()` submits that pair to one worker thread through a queue. The worker applies the chat template, tokenizes, finds cache segments, chooses the initial reasoning state, constructs stop/tool/reasoning transitions, selects a lane, owns cache work, and emits per-token `Response` records. [`server.py:516`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:516) [`server.py:626`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:626) [`server.py:688`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:688) [`server.py:1026`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1026)
|
|
47
|
+
|
|
48
|
+
That organization can be summarized as:
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
HTTP request
|
|
52
|
+
-> CompletionRequest + GenerationArguments
|
|
53
|
+
-> ResponseGenerator queue
|
|
54
|
+
-> tokenize + state machine + lane + cache
|
|
55
|
+
-> token Response { text, token, state, match, logprob, finish_reason }
|
|
56
|
+
-> HTTP handler accumulates semantics and formats the protocol response
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The model loader is separate. `utils.load()` returns the model and a tokenizer wrapper, while tokenizer loading chooses the streaming detokenizer and tool parser. This keeps model construction out of per-request execution. [`utils.py:453`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/utils.py:453) [`tokenizer_utils.py:578`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/tokenizer_utils.py:578)
|
|
60
|
+
|
|
61
|
+
## Comparison by concern
|
|
62
|
+
|
|
63
|
+
| Concern | Oracle organization | Consequence for the mlx-bun seam |
|
|
64
|
+
| --- | --- | --- |
|
|
65
|
+
| Prepared prompt | The worker owns chat templating, tokenization, initial reasoning state, and cache-oriented prompt segmentation. The HTTP adapter does not know those details. [`server.py:530`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:530) [`server.py:565`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:565) | A prepared-prompt value is a sound seam, but it should be richer than token ids. It must carry the generation inputs and owned media or grammar state needed by either lane. Protocol adapters should not assemble `RequestShape` or transfer resources piecemeal. |
|
|
66
|
+
| Semantic events | The state machine classifies tokens as `normal`, `reasoning`, or `tool`. `_process_control_tokens` withholds matched control sequences. The HTTP handler then accumulates reasoning, tool text, visible text, and parses completed tool calls. [`server.py:236`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:236) [`server.py:654`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:654) [`server.py:1442`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1442) | Do not copy this split. mlx-bun's `CompletionSink` already emits content, reasoning, and tool-call events through one interface. [`completion-sink.ts:7`](/Users/joshrossi/.codex/worktrees/e408/mlx-bun/src/serve/completion-sink.ts:7) [`completion-sink.ts:90`](/Users/joshrossi/.codex/worktrees/e408/mlx-bun/src/serve/completion-sink.ts:90) The deepened module should own that semantic work so all protocol adapters consume the same events. |
|
|
67
|
+
| Terminal summary | `generate.stream_generate()` puts timing, token counts, memory, and finish reason on every low-level response, but the server discards most of it. The HTTP handler counts emitted tokens, reads prompt and cache counts from `GenerationContext`, derives tool-call finish, and builds usage. [`generate.py:269`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/generate.py:269) [`generate.py:728`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/generate.py:728) [`server.py:1495`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1495) [`server.py:1517`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1517) | The oracle has no single terminal summary at the server seam. mlx-bun should add one. It should be the sole source of finish reason, prompt/generated/cached counts, final lane, speculation facts, and collected result. |
|
|
68
|
+
| Streaming and non-streaming | Both modes consume the same response iterator and semantic accumulation loop. Streaming flushes deltas and optionally emits a final usage packet; non-streaming sends one accumulated response. [`server.py:1454`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1454) [`server.py:1507`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1507) [`server.py:1529`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1529) | Keep one Completion execution interface. Streaming and non-streaming are protocol adapters over the same semantic events and terminal summary, not separate execution paths. |
|
|
69
|
+
| Scheduling placement | Model loading marks a model batchable only when no draft model exists and every cache supports merge. Per-request placement also excludes a fixed seed. The worker joins the active batch, creates a batch, runs serially, or drains an incompatible batch. [`server.py:370`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:370) [`server.py:685`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:685) [`server.py:731`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:731) [`server.py:801`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:801) [`server.py:831`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:831) | `RequestShape` describes settings already resolved from flags, request fields, model metadata, and defaults. `place()` asks only whether the continuous scheduler implements that exact composition; it never replaces MTP, a KV scheme, or another requested method. The frozen declaration names the `serial` or `continuous` mechanism, and both reporting and `run()` consume it. Active-row count selects B=1 or B=N inside the continuous mechanism. |
|
|
70
|
+
| Cancellation and flow | Cancellation is cooperative. The handler's `finally` sets a flag; serial execution checks it after tokens, while batched execution checks it during prompt and generation work and removes the row. [`server.py:1008`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1008) [`server.py:861`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:861) [`server.py:911`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:911) [`server.py:1551`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1551) The response queue is unbounded, and socket writes block only the HTTP thread, so there is no end-to-end demand signal from the client to generation. [`server.py:444`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:444) [`server.py:1032`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1032) [`server.py:1489`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1489) | Do not regress to the oracle here. mlx-bun's token callback accepts a promise or `false`, and `GenerationGateway.run()` accepts an `AbortSignal`. [`generation-gateway.ts:94`](/Users/joshrossi/.codex/worktrees/e408/mlx-bun/src/serve/generation-gateway.ts:94) [`generation-gateway.ts:354`](/Users/joshrossi/.codex/worktrees/e408/mlx-bun/src/serve/generation-gateway.ts:354) Cancellation and async flow control are part of the interface, not HTTP details. |
|
|
71
|
+
| Cache and resource lifetime | The worker fetches or creates the serial cache, generates, then inserts it. Batched execution fetches before admission, snapshots segment caches, inserts the final cache, and removes cancelled rows. [`server.py:963`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:963) [`server.py:1018`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1018) [`server.py:752`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:752) [`server.py:864`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:864) [`server.py:901`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:901) `LRUPromptCache` hides prefix matching, copying, trimming, and count/byte eviction behind a small interface. [`cache.py:1623`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/models/cache.py:1623) [`cache.py:1674`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/models/cache.py:1674) [`cache.py:1696`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/models/cache.py:1696) | `prepareCompletion()` now disposes owned media and grammar state on admission rejection. `execute()` disposes the same plan on placement or pre-generation failure, then transfers ownership exactly once before `GenerationGateway.run()`. Cache and in-generation disposal remain in the gateway and generation path. [`completion-executor.ts:75`](/Users/joshrossi/.codex/worktrees/e408/mlx-bun/src/serve/completion-executor.ts:75) [`completion-executor.ts:219`](/Users/joshrossi/.codex/worktrees/e408/mlx-bun/src/serve/completion-executor.ts:219) |
|
|
72
|
+
| Errors | Errors before the response iterator exists become a JSON error, although the oracle uses status 404 for that whole class. Errors delivered later through the worker queue are raised by the iterator. The handler guarantees `ctx.stop()` but has no matching mid-stream error packet in this loop. [`server.py:1417`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1417) [`server.py:1424`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1424) [`server.py:1035`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1035) [`server.py:1454`](/Users/joshrossi/Code/mlx-lm/.venv/lib/python3.14/site-packages/mlx_lm/server.py:1454) | Preserve a typed distinction between rejection before execution and failure after events begin. Both must run the same ownership cleanup. Protocol adapters decide how to encode the failure after headers have been sent. |
|
|
73
|
+
|
|
74
|
+
## Strongest conclusions
|
|
75
|
+
|
|
76
|
+
1. **Keep resolved inference settings authoritative.** Serial and continuous execution are scheduling mechanisms for the already-selected composition. Consolidating placement may shrink the HTTP adapter, but it must not turn explicit features or opinionated defaults into inferred choices.
|
|
77
|
+
2. **Do not borrow the oracle's semantic split.** Its worker emits state-tagged token records, then the HTTP handler performs semantic accumulation and tool parsing. mlx-bun already has a better starting point in `CompletionSink`. Move that module behind the Completion execution seam so protocol adapters see semantic events only.
|
|
78
|
+
3. **Keep the terminal summary as the only completion result.** It now settles finish reason, usage, cached-token count, final lane, speculation, logprobs, and collected output once. The four HTTP branches only format that summary. [`completion-executor.ts:103`](/Users/joshrossi/.codex/worktrees/e408/mlx-bun/src/serve/completion-executor.ts:103) [`server.ts:3104`](/Users/joshrossi/.codex/worktrees/e408/mlx-bun/src/server.ts:3104)
|
|
79
|
+
4. **Treat cancellation, async flow control, and ownership as interface requirements.** The oracle's queue makes cancellation and socket pressure indirect. mlx-bun has stronger mechanisms already. The deepening should hide their implementation without weakening their behavior.
|
|
80
|
+
|
|
81
|
+
The deletion test is positive. If this Completion execution module disappeared, scheduling policy, cache participation, semantic parsing, finish rules, usage, and cleanup would spread back across four protocol branches. Concentrating those rules gives callers leverage and gives maintainers locality. Feature selection and fidelity policy remain outside this seam as resolved inputs.
|
|
@@ -158,7 +158,7 @@ than the absolute max-bearable (the edge is fragile).
|
|
|
158
158
|
**Synergy with the diffusion frontier:** all of this is noise-robustness machinery for
|
|
159
159
|
controlling off a noisy process variable — so it transfers *especially* well to a
|
|
160
160
|
diffusion LM, where the likelihood is a stochastic ELBO (even noisier). See
|
|
161
|
-
[orpo-base-uf-experiment-and-directions.md](../investigations/orpo-base-uf-experiment-and-directions.md) §6.7.
|
|
161
|
+
[orpo-base-uf-experiment-and-directions.md](../archive/investigations/orpo-base-uf-experiment-and-directions.md) §6.7.
|
|
162
162
|
|
|
163
163
|
## Wiring
|
|
164
164
|
|
|
@@ -11,7 +11,7 @@ comfortable.
|
|
|
11
11
|
> trainer)** shipped as `orpo_prefix_shared`, composed with the flash head AND the
|
|
12
12
|
> segmented backward for MiniCPM5 **and** e4b. See [training.md](../reference/training.md),
|
|
13
13
|
> [orpo-quickstart.md](../reference/orpo-quickstart.md), and the live record
|
|
14
|
-
> [steel-flash-cce-handoff.md](../investigations/steel-flash-cce-handoff.md). The
|
|
14
|
+
> [steel-flash-cce-handoff.md](../archive/investigations/steel-flash-cce-handoff.md). The
|
|
15
15
|
> remaining sections (§2, §4–§9, the objective variants) are still genuinely future.
|
|
16
16
|
|
|
17
17
|
## Deferred levers — queued, do NOT start mid-run (2026-06-19)
|
|
@@ -19,7 +19,7 @@ runs half the forwards per step.
|
|
|
19
19
|
> The ✅/🔬 entries + optimization log below are the **design/build history**; for the
|
|
20
20
|
> current usage, flags, and numbers see [training.md](../reference/training.md) +
|
|
21
21
|
> [orpo-quickstart.md](../reference/orpo-quickstart.md), and the live engineering record
|
|
22
|
-
> [steel-flash-cce-handoff.md](../investigations/steel-flash-cce-handoff.md).
|
|
22
|
+
> [steel-flash-cce-handoff.md](../archive/investigations/steel-flash-cce-handoff.md).
|
|
23
23
|
|
|
24
24
|
> Oracle note: neither `mlx_lm` nor `optiq` ships ORPO, so — unlike DPO
|
|
25
25
|
> ([`loss.ts`](../../src/train/loss.ts) ported `optiq/lora/dpo.py`) — ORPO is
|
|
@@ -38,7 +38,7 @@ runs half the forwards per step.
|
|
|
38
38
|
> hiddens before judging** (it's plausibly a free speedup to enable). Standing Lab
|
|
39
39
|
> gates (filter-on-real-data, teacher-forced grad fidelity, end-to-end quality)
|
|
40
40
|
> + the host-buffer pin-leak post-mortem:
|
|
41
|
-
> [orpo-flash-cce-pin-leak.md](../investigations/orpo-flash-cce-pin-leak.md).
|
|
41
|
+
> [orpo-flash-cce-pin-leak.md](../archive/investigations/orpo-flash-cce-pin-leak.md).
|
|
42
42
|
|
|
43
43
|
## Implementation status
|
|
44
44
|
|
|
@@ -26,7 +26,7 @@ exists AND it matches bit-exactly; otherwise it bubbles up. Note the subtlety th
|
|
|
26
26
|
map already shows: an *optimization* that still matches the oracle stays low —
|
|
27
27
|
`compiled-decode` is ours but is L1 because it replays the same ops bit-for-bit.
|
|
28
28
|
Only nodes with **no** oracle (flash-CCE) are *forced* into the Lab. (Background +
|
|
29
|
-
post-mortem: [orpo-flash-cce-pin-leak.md](../investigations/orpo-flash-cce-pin-leak.md).)
|
|
29
|
+
post-mortem: [orpo-flash-cce-pin-leak.md](../archive/investigations/orpo-flash-cce-pin-leak.md).)
|
|
30
30
|
|
|
31
31
|
## Two axes: parity gates performance
|
|
32
32
|
|