mlx-bun 0.2.0 → 0.4.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.
Files changed (433) hide show
  1. package/README.md +71 -588
  2. package/docs/README.md +94 -0
  3. package/docs/{design → archive/investigations}/audio-input-plan.md +4 -4
  4. package/docs/{design → archive/investigations}/diffusion-gemma-port.md +3 -3
  5. package/docs/{design → archive/investigations}/faithful-l1-consolidation.md +4 -4
  6. package/docs/{design → archive/investigations}/minicpm5-decode-megakernel.md +11 -11
  7. package/docs/archive/investigations/openjarvis-fit.md +198 -0
  8. package/docs/{design → archive/investigations}/optimization_plan.md +1 -1
  9. package/docs/{design → archive/investigations}/pre-colibri-stabilization.md +5 -5
  10. package/docs/archive/investigations/qwen38-27b-campaign-log.md +1092 -0
  11. package/docs/{design → archive/investigations}/the-dreaming-handoff.md +2 -2
  12. package/docs/archive/planning/release-notes-v0.3.0.md +35 -0
  13. package/docs/design/batching.md +1841 -0
  14. package/docs/design/decode-speed-program.md +2346 -169
  15. package/docs/design/dreaming-nightly-pipeline.md +675 -282
  16. package/docs/design/generic-model-support.md +655 -334
  17. package/docs/design/kv-cache.md +824 -0
  18. package/docs/design/orpo-training.md +673 -1239
  19. package/docs/design/speculative-decoding.md +1990 -0
  20. package/docs/design/turboquant.md +2212 -0
  21. package/docs/design/unified-engine-frontier-plan.md +1833 -727
  22. package/docs/design/web-chat-redesign.md +666 -1083
  23. package/docs/planning/PRODUCT_ROADMAP.md +50 -1
  24. package/docs/planning/release-notes-v0.4.0.md +45 -0
  25. package/docs/planning/video-series.md +2 -2
  26. package/docs/reference/benchmarks.md +3613 -0
  27. package/docs/reference/cli.md +434 -160
  28. package/docs/reference/distribution.md +328 -182
  29. package/docs/reference/environment.md +398 -0
  30. package/docs/reference/glossary.md +39 -0
  31. package/docs/reference/library-api.md +566 -168
  32. package/docs/reference/memory.md +227 -64
  33. package/docs/reference/models.md +113 -6
  34. package/docs/reference/server-api.md +944 -429
  35. package/docs/reference/server-config.md +740 -338
  36. package/docs/reference/training.md +393 -254
  37. package/docs/reference/troubleshooting.md +158 -0
  38. package/package.json +9 -4
  39. package/src/audio/decode.ts +2 -2
  40. package/src/audio/features.ts +2 -2
  41. package/src/backends/mlx/assistant-target.ts +46 -0
  42. package/src/backends/mlx/autoregressive-draft-rows.ts +120 -0
  43. package/src/backends/mlx/autoregressive.ts +108 -0
  44. package/src/backends/mlx/batch-group.ts +1790 -0
  45. package/src/backends/mlx/cache-attachment.ts +67 -0
  46. package/src/backends/mlx/cache-layout.ts +31 -0
  47. package/src/backends/mlx/checkpoint-state.ts +53 -0
  48. package/src/backends/mlx/continuation-persistence.ts +106 -0
  49. package/src/backends/mlx/continuation-request.ts +43 -0
  50. package/src/backends/mlx/continuation.ts +77 -0
  51. package/src/backends/mlx/diffusion.ts +39 -0
  52. package/src/backends/mlx/draft-target.ts +32 -0
  53. package/src/backends/mlx/evaluation.ts +105 -0
  54. package/src/backends/mlx/fill-append.ts +45 -0
  55. package/src/backends/mlx/full-kv-row-append.ts +32 -0
  56. package/src/backends/mlx/full-kv-row-donor.ts +54 -0
  57. package/src/backends/mlx/full-transitioning-kv-rows.ts +65 -0
  58. package/src/backends/mlx/gateway-binding.ts +130 -0
  59. package/src/backends/mlx/graph.ts +38 -0
  60. package/src/backends/mlx/kv-codec.ts +9 -0
  61. package/src/backends/mlx/kv-maintenance.ts +133 -0
  62. package/src/backends/mlx/kv-tensor-rows.ts +212 -0
  63. package/src/backends/mlx/memory-client.ts +189 -0
  64. package/src/backends/mlx/methods.ts +90 -0
  65. package/src/backends/mlx/model-prompt.ts +164 -0
  66. package/src/backends/mlx/model-serving.ts +79 -0
  67. package/src/backends/mlx/prefill-cohort.ts +89 -0
  68. package/src/backends/mlx/prefill-rows.ts +200 -0
  69. package/src/backends/mlx/prefill.ts +33 -0
  70. package/src/backends/mlx/projected-context-rows.ts +72 -0
  71. package/src/backends/mlx/request-policy.ts +20 -0
  72. package/src/backends/mlx/request-state-policy.ts +41 -0
  73. package/src/backends/mlx/rollback.ts +89 -0
  74. package/src/backends/mlx/row-sampling.ts +49 -0
  75. package/src/backends/mlx/serial-executor.ts +242 -0
  76. package/src/backends/mlx/speculative-group.ts +359 -0
  77. package/src/backends/mlx/speculative-round.ts +161 -0
  78. package/src/backends/mlx/speculative.ts +114 -0
  79. package/src/backends/mlx/state-rows.ts +104 -0
  80. package/src/backends/mlx/state-views.ts +46 -0
  81. package/src/backends/mlx/target-layout-capability.ts +35 -0
  82. package/src/backends/mlx/text-engine.ts +73 -0
  83. package/src/backends/mlx/transitioning-kv-rows.ts +165 -0
  84. package/src/cli.ts +66 -58
  85. package/src/client.ts +66 -0
  86. package/src/config.ts +21 -4
  87. package/src/contracts/completion.ts +16 -0
  88. package/src/contracts/execution.ts +60 -0
  89. package/src/contracts/generation.ts +103 -0
  90. package/src/contracts/host.ts +7 -0
  91. package/src/contracts/jobs.ts +66 -0
  92. package/src/contracts/pi-provider.ts +30 -0
  93. package/src/contracts/pi.ts +259 -0
  94. package/src/contracts/prefix-cache.ts +23 -0
  95. package/src/contracts/resources.ts +25 -0
  96. package/src/contracts/sampling.ts +23 -0
  97. package/src/contracts/scheduling.ts +45 -0
  98. package/src/contracts/tsconfig.json +14 -0
  99. package/src/diffusion/diffusion-generate.ts +218 -153
  100. package/src/embed.ts +1 -1
  101. package/src/engine/admission.ts +59 -0
  102. package/src/engine/cancellation.ts +38 -0
  103. package/src/engine/engine.ts +56 -0
  104. package/src/engine/execution-coordinator.ts +70 -0
  105. package/src/engine/execution-plan.ts +53 -0
  106. package/src/engine/resources.ts +53 -0
  107. package/src/engine/scheduler.ts +72 -0
  108. package/src/engine/session.ts +247 -0
  109. package/src/eval/README.md +44 -1
  110. package/src/eval/kl.ts +236 -3
  111. package/src/eval/reference-logits.ts +207 -0
  112. package/src/eval/runner.ts +8 -96
  113. package/src/fill/echo-index.ts +188 -0
  114. package/src/fill/fill-session.ts +452 -0
  115. package/src/fill/proposal.ts +68 -0
  116. package/src/fill/schema-rows.ts +506 -0
  117. package/src/fill/tool-boundary.ts +103 -0
  118. package/src/fit.ts +30 -16
  119. package/src/generate.ts +709 -417
  120. package/src/grammar.ts +12 -7
  121. package/src/harness-pi.ts +14 -33
  122. package/src/hub-rest.ts +4 -4
  123. package/src/index.ts +7 -0
  124. package/src/inference/denoising.ts +17 -0
  125. package/src/inference/draft-acceptance.ts +41 -0
  126. package/src/inference/draft-output.ts +49 -0
  127. package/src/inference/graph.ts +33 -0
  128. package/src/inference/prefill.ts +39 -0
  129. package/src/inference/rollback.ts +7 -0
  130. package/src/jobs/db.ts +4 -0
  131. package/src/jobs/index.ts +2 -0
  132. package/src/jobs/job-entry.ts +12 -12
  133. package/src/jobs/runner.ts +98 -13
  134. package/src/jobs/task-client.ts +19 -0
  135. package/src/jobs/types.ts +2 -58
  136. package/src/kv-scheme.ts +70 -12
  137. package/src/kv-store.ts +177 -63
  138. package/src/lab/README.md +18 -0
  139. package/src/{assets → lab/curve}/curve-designer.html +2 -2
  140. package/src/{curve-sampler.ts → lab/curve/curve-sampler.ts} +2 -2
  141. package/src/{expert-trace.ts → lab/expert-trace/expert-trace.ts} +5 -5
  142. package/src/lab/paged-kv/paged-kv-rows.ts +83 -0
  143. package/src/{model → lab/paged-kv}/paged-kv.ts +32 -15
  144. package/src/library.ts +40 -0
  145. package/src/lora.ts +18 -0
  146. package/src/media-fetch.ts +1 -1
  147. package/src/memory/article.ts +1 -1
  148. package/src/memory/chunk.ts +1 -1
  149. package/src/memory/model.ts +30 -169
  150. package/src/memory/prompts.ts +1 -1
  151. package/src/memory/rest.ts +1 -1
  152. package/src/memory/schedule.ts +1 -1
  153. package/src/memory/stages.ts +4 -1
  154. package/src/memory/vault.ts +1 -3
  155. package/src/mlx/array.ts +11 -11
  156. package/src/mlx/compile.ts +12 -2
  157. package/src/mlx/ffi.ts +58 -11
  158. package/src/mlx/materialize.ts +23 -0
  159. package/src/mlx/metal-kernel.ts +10 -11
  160. package/src/mlx/ops.ts +33 -13
  161. package/src/mlx/quantized-rows.ts +36 -0
  162. package/src/mlx/token-bitmask.ts +52 -0
  163. package/src/mlx/turboquant-kv-decode.ts +82 -0
  164. package/src/mlx/turboquant-kv-inverse.ts +122 -0
  165. package/src/mlx/turboquant-ops.ts +33 -3
  166. package/src/mlx/turboquant-tables.ts +2 -2
  167. package/src/model/artifact-identity.ts +73 -0
  168. package/src/model/batched-kv.ts +235 -0
  169. package/src/model/batched-mask.ts +20 -6
  170. package/src/model/batched-quant.ts +9 -3
  171. package/src/model/batched-quantized-kv.ts +144 -0
  172. package/src/model/batched-rotating-quant.ts +78 -17
  173. package/src/model/batched-rotating-state.ts +76 -0
  174. package/src/model/batched-rotating.ts +65 -23
  175. package/src/model/batched-row-storage.ts +52 -0
  176. package/src/model/batched-ssm.ts +52 -0
  177. package/src/model/batched-turboquant-kv.ts +93 -0
  178. package/src/model/compiled-decode.ts +8 -2
  179. package/src/model/decoded-kv-donor.ts +12 -0
  180. package/src/model/delayed-quantized-kv.ts +72 -0
  181. package/src/model/delayed-rotating-quantized-kv.ts +93 -0
  182. package/src/model/delayed-turboquant-kv.ts +55 -0
  183. package/src/model/diffusion-gemma.ts +8 -8
  184. package/src/model/factory.ts +76 -33
  185. package/src/model/fingerprint.ts +1 -1
  186. package/src/model/flash-attention.ts +3 -3
  187. package/src/model/full-prefill-padding.ts +56 -0
  188. package/src/model/full-prefill-row.ts +105 -0
  189. package/src/model/gemma4-base.ts +179 -80
  190. package/src/model/gemma4.ts +40 -32
  191. package/src/model/generated/gemma4-12b.ts +6 -3
  192. package/src/model/generated/gemma4-26b.ts +6 -3
  193. package/src/model/generated/gemma4-e4b.ts +6 -3
  194. package/src/model/glm52-cache.ts +80 -4
  195. package/src/model/glm52-dsa.ts +13 -9
  196. package/src/model/glm52-memory.ts +1 -1
  197. package/src/model/glm52-mla.ts +12 -6
  198. package/src/model/glm52.ts +19 -40
  199. package/src/model/implementation.ts +69 -0
  200. package/src/model/kv-attention-view.ts +67 -0
  201. package/src/model/minicpm5.ts +17 -15
  202. package/src/model/profile.ts +12 -2
  203. package/src/model/qwen-append.ts +12 -0
  204. package/src/model/qwen-conv.ts +52 -0
  205. package/src/model/qwen3-delta-state.ts +74 -0
  206. package/src/model/qwen3-delta.ts +59 -36
  207. package/src/model/qwen3_5-checkpoint.ts +164 -0
  208. package/src/model/qwen3_5.ts +202 -78
  209. package/src/model/rotating-kv-donor.ts +35 -0
  210. package/src/model/rotating-kv-layout.ts +262 -0
  211. package/src/model/rotating-row-transaction.ts +35 -0
  212. package/src/model/speculative-rotating-kv.ts +101 -0
  213. package/src/model/ssm-prefill-padding.ts +39 -0
  214. package/src/model/support.ts +1 -1
  215. package/src/model/trellis-balanced-scatter.ts +51 -0
  216. package/src/model/trellis-linear.ts +672 -0
  217. package/src/model/trellis-shared-m.ts +151 -0
  218. package/src/model/trellis-shared-scatter.ts +144 -0
  219. package/src/model/trellis-splitk-prefill.ts +158 -0
  220. package/src/model/trellis-tiled-prefill.ts +136 -0
  221. package/src/model/trellis-vector-expand.ts +62 -0
  222. package/src/model/trellis-wide-prefill.ts +94 -0
  223. package/src/model/turboquant-codec.ts +83 -0
  224. package/src/model/universal/dense.ts +15 -14
  225. package/src/model/universal/modules.ts +8 -1
  226. package/src/native-pack.ts +6 -5
  227. package/src/pi-provider.ts +6 -64
  228. package/src/pi-web.ts +8 -315
  229. package/src/preflight.ts +31 -15
  230. package/src/prompt-cache.ts +110 -69
  231. package/src/quantize/allocator.ts +1 -1
  232. package/src/quantize/config-writer.ts +10 -3
  233. package/src/quantize/rotate.ts +4 -4
  234. package/src/quantize/trellis.ts +586 -0
  235. package/src/responses.ts +28 -1
  236. package/src/runtime-config.ts +18 -4
  237. package/src/sampler.ts +40 -29
  238. package/src/serve/batch-scheduler.ts +8 -1671
  239. package/src/serve/chat-request.ts +391 -0
  240. package/src/serve/chat-stage.ts +195 -0
  241. package/src/serve/checkpoint-identity.ts +64 -0
  242. package/src/serve/completion-executor.ts +15 -7
  243. package/src/serve/discovery-routes.ts +12 -13
  244. package/src/serve/generation-gateway.ts +183 -213
  245. package/src/serve/http.ts +159 -0
  246. package/src/serve/inference-request.ts +79 -0
  247. package/src/serve/isolate.ts +297 -105
  248. package/src/serve/lab-routes.ts +3 -0
  249. package/src/serve/lane-registry.ts +2 -1
  250. package/src/serve/model-admin-routes.ts +7 -5
  251. package/src/serve/model-binding.ts +43 -0
  252. package/src/serve/model-host.ts +511 -0
  253. package/src/serve/openai-wire.ts +103 -0
  254. package/src/serve/parent-application.ts +56 -0
  255. package/src/serve/pipeline.ts +33 -0
  256. package/src/serve/preparation.ts +33 -0
  257. package/src/serve/request-plan.ts +23 -18
  258. package/src/serve/request-prep.ts +344 -0
  259. package/src/serve/response-lease.ts +24 -0
  260. package/src/serve/responses-client.ts +69 -0
  261. package/src/serve/session-completion-engine.ts +110 -0
  262. package/src/serve/session-search.ts +1 -1
  263. package/src/serve/static-routes.ts +5 -5
  264. package/src/serve/text-completion-stage.ts +104 -0
  265. package/src/serve/token-streams.ts +519 -0
  266. package/src/server.ts +335 -2711
  267. package/src/spec/assistant-rows.ts +92 -0
  268. package/src/spec/assistant-source.ts +31 -55
  269. package/src/spec/cache-identity.ts +22 -0
  270. package/src/spec/deepspec-rows.ts +29 -0
  271. package/src/spec/deepspec-source.ts +16 -14
  272. package/src/spec/dflash-source.ts +36 -12
  273. package/src/spec/drafter.ts +153 -142
  274. package/src/spec/dspark/ab-stats.ts +3 -3
  275. package/src/spec/dspark/calibration.ts +2 -2
  276. package/src/spec/dspark/deepspec-module.ts +97 -122
  277. package/src/spec/dspark/generate-dflash.ts +2 -2
  278. package/src/spec/dspark/generate.ts +2 -2
  279. package/src/spec/dspark/loader.ts +1 -1
  280. package/src/spec/dspark/module-dflash.ts +129 -172
  281. package/src/spec/dspark/module.ts +3 -3
  282. package/src/spec/dspark/quantize-drafter.ts +1 -1
  283. package/src/spec/generate.ts +1 -1
  284. package/src/spec/glm52-mtp-graph.ts +29 -0
  285. package/src/spec/glm52-mtp-rows.ts +132 -0
  286. package/src/spec/glm52-mtp-source.ts +54 -137
  287. package/src/spec/glm52-mtp-state.ts +33 -0
  288. package/src/spec/ngram-source.ts +93 -21
  289. package/src/spec/projected-draft-rows.ts +73 -0
  290. package/src/spec/qwen-mtp-module.ts +171 -0
  291. package/src/spec/qwen-mtp-rows.ts +219 -0
  292. package/src/spec/qwen-mtp-source.ts +147 -195
  293. package/src/spec/qwen-mtp-state.ts +30 -0
  294. package/src/spec/serve-loop.ts +201 -201
  295. package/src/spec/source.ts +110 -13
  296. package/src/spec/two-model-rows.ts +61 -0
  297. package/src/spec/two-model.ts +44 -102
  298. package/src/ssd-cache.ts +99 -19
  299. package/src/ssd-durability.ts +36 -20
  300. package/src/tool-call.ts +51 -14
  301. package/src/train/flash-cce.ts +2 -2
  302. package/src/train/forward.ts +6 -0
  303. package/src/train/loss.ts +1 -1
  304. package/src/train/prefix-shared.ts +5 -1
  305. package/src/train/segmented.ts +5 -3
  306. package/src/train/trainer.ts +6 -6
  307. package/src/vision/prompt.ts +1 -1
  308. package/src/vision/qwen3vl-tower.ts +52 -10
  309. package/src/web/app.html +1 -1
  310. package/src/web/app.js +62 -60
  311. package/src/web/src/adapters-panel.ts +3 -3
  312. package/src/web/src/assistant.ts +2 -36
  313. package/src/web/src/chat.ts +4 -4
  314. package/src/web/src/composer.ts +4 -4
  315. package/src/web/src/hub.ts +1 -1
  316. package/src/web/src/markdown.ts +0 -0
  317. package/src/web/src/memory-panel.ts +1 -1
  318. package/src/web/src/model-picker.ts +1 -1
  319. package/src/web/src/palette.ts +1 -1
  320. package/src/web/src/protocol.ts +3 -39
  321. package/src/web/src/sessions.ts +1 -1
  322. package/src/web/src/ui-catalog.ts +4 -18
  323. package/src/web-assets.ts +47 -0
  324. package/src/weights.ts +55 -9
  325. package/docs/archive/investigations/curve-runs/bisector-route.json +0 -98
  326. package/docs/archive/investigations/curve-runs/bisector-trace.json +0 -1393
  327. package/docs/archive/investigations/curve-runs/curve-terrain.json +0 -1179
  328. package/docs/archive/investigations/curve-runs/curve-terrain.svg +0 -42
  329. package/docs/archive/investigations/hlg-ab.html +0 -34
  330. package/docs/archive/investigations/hlg-explorer.html +0 -238
  331. package/docs/archive/investigations/hlg-figs/cliff.svg +0 -1
  332. package/docs/archive/investigations/hlg-figs/cross.svg +0 -1
  333. package/docs/archive/investigations/hlg-figs/edges.svg +0 -1
  334. package/docs/archive/investigations/hlg-figs/k20-grids.svg +0 -1
  335. package/docs/archive/investigations/hlg-figs/k20-peaks.svg +0 -1
  336. package/docs/archive/investigations/hlg-figs/lw-curve.svg +0 -1
  337. package/docs/archive/investigations/hlg-figs/terrain.svg +0 -1
  338. package/docs/archive/investigations/hlg-report.html +0 -262
  339. package/docs/archive/investigations/hlg-runs/hlg-ab.json +0 -149
  340. package/docs/archive/investigations/hlg-runs/hlg-blind-prompts.md +0 -87
  341. package/docs/archive/investigations/hlg-runs/hlg-blind.json +0 -107
  342. package/docs/archive/investigations/hlg-runs/hlg-cliff.json +0 -197
  343. package/docs/archive/investigations/hlg-runs/hlg-cross.json +0 -505
  344. package/docs/archive/investigations/hlg-runs/hlg-edge.json +0 -388
  345. package/docs/archive/investigations/hlg-runs/hlg-eval1.json +0 -25
  346. package/docs/archive/investigations/hlg-runs/hlg-frontier.json +0 -86
  347. package/docs/archive/investigations/hlg-runs/hlg-grid.json +0 -242
  348. package/docs/archive/investigations/hlg-runs/hlg-grid2.json +0 -343
  349. package/docs/archive/investigations/hlg-runs/hlg-lw-coarse.json +0 -110
  350. package/docs/archive/investigations/hlg-runs/hlg-map.json +0 -383
  351. package/docs/archive/investigations/hlg-runs/run0-original.log +0 -159
  352. package/docs/archive/investigations/hlg-runs/runA-recommended.log +0 -131
  353. package/docs/archive/investigations/hlg-runs/runAA-cliff-cpm5.log +0 -26
  354. package/docs/archive/investigations/hlg-runs/runAB-grid2-e4b.log +0 -18
  355. package/docs/archive/investigations/hlg-runs/runAC-peak-e4b-partial.log +0 -25
  356. package/docs/archive/investigations/hlg-runs/runAD-ab-samples.log +0 -8
  357. package/docs/archive/investigations/hlg-runs/runAE-edge-e4b.log +0 -51
  358. package/docs/archive/investigations/hlg-runs/runAF-logit-calibration.log +0 -10
  359. package/docs/archive/investigations/hlg-runs/runAG-eval-config2.log +0 -16
  360. package/docs/archive/investigations/hlg-runs/runB-gain-variants.log +0 -192
  361. package/docs/archive/investigations/hlg-runs/runC-pivots.log +0 -162
  362. package/docs/archive/investigations/hlg-runs/runD-oetf.log +0 -132
  363. package/docs/archive/investigations/hlg-runs/runE-eotf.log +0 -162
  364. package/docs/archive/investigations/hlg-runs/runF-shaper-working.log +0 -86
  365. package/docs/archive/investigations/hlg-runs/runG-shaper-sweep.log +0 -101
  366. package/docs/archive/investigations/hlg-runs/runH-wsweep.log +0 -176
  367. package/docs/archive/investigations/hlg-runs/runI-asweep.log +0 -176
  368. package/docs/archive/investigations/hlg-runs/runJ-knobmap.log +0 -49
  369. package/docs/archive/investigations/hlg-runs/runK-frontier.log +0 -19
  370. package/docs/archive/investigations/hlg-runs/runL-widemap.log +0 -65
  371. package/docs/archive/investigations/hlg-runs/runM-frontier-emb.log +0 -15
  372. package/docs/archive/investigations/hlg-runs/runN-verify.log +0 -116
  373. package/docs/archive/investigations/hlg-runs/runO-frontier-seed5000.log +0 -15
  374. package/docs/archive/investigations/hlg-runs/runP-grid-AxSm.log +0 -15
  375. package/docs/archive/investigations/hlg-runs/runQ-grid-tgW.log +0 -15
  376. package/docs/archive/investigations/hlg-runs/runR-blind-transcript.log +0 -79
  377. package/docs/archive/investigations/hlg-runs/runS-cross-coherence.log +0 -33
  378. package/docs/archive/investigations/hlg-runs/runT-cross-cpm5.log +0 -33
  379. package/docs/archive/investigations/hlg-runs/runU-cross-12b.log +0 -33
  380. package/docs/archive/investigations/hlg-runs/runV-lw-e4b.log +0 -22
  381. package/docs/archive/investigations/hlg-runs/runW-lw-12b.log +0 -22
  382. package/docs/archive/investigations/hlg-runs/runX-lw-cpm5.log +0 -22
  383. package/docs/archive/investigations/hlg-runs/runY-cliff-e4b.log +0 -26
  384. package/docs/archive/investigations/hlg-runs/runZ-cliff-12b.log +0 -26
  385. package/docs/archive/mlx-bun-lab-report.html +0 -275
  386. package/docs/archive/wwdc-mlx-bun.html +0 -848
  387. package/docs/design/adapters-end-to-end.md +0 -205
  388. package/docs/design/batching-perf-path.md +0 -255
  389. package/docs/design/batching-v2-plan.md +0 -529
  390. package/docs/design/bucketing-stage.md +0 -197
  391. package/docs/design/compat-cli-surface-design.md +0 -230
  392. package/docs/design/docs-reorg-plan.md +0 -165
  393. package/docs/design/dspark-serving-program.md +0 -371
  394. package/docs/design/dspark-speculative-decoding.md +0 -318
  395. package/docs/design/grammar-spec-batching-integration.md +0 -301
  396. package/docs/design/memory-inference-path.md +0 -422
  397. package/docs/design/memory-synthesis.md +0 -287
  398. package/docs/design/memory-system.md +0 -237
  399. package/docs/design/mlx-lm-serving-execution-seam.md +0 -81
  400. package/docs/design/mlx-lm-tool-parity-plan.md +0 -545
  401. package/docs/design/omlx-adoption-map.md +0 -98
  402. package/docs/design/orpo-dynamic-lambda.md +0 -220
  403. package/docs/design/orpo-future-enhancements.md +0 -340
  404. package/docs/design/paged-kv-cache.md +0 -214
  405. package/docs/design/parallel-slots.md +0 -567
  406. package/docs/design/parity-tier-dag.md +0 -161
  407. package/docs/design/repo-cleanup-plan.md +0 -231
  408. package/docs/design/runtime-isolation.md +0 -263
  409. package/docs/design/segmented-backward-training.md +0 -543
  410. package/docs/design/spec-decode-larger-targets.md +0 -229
  411. package/docs/design/ssd-kv-cold-tier.md +0 -415
  412. package/docs/design/structured-output.md +0 -484
  413. package/docs/design/tauri-desktop-app.md +0 -127
  414. package/docs/design/the-dreaming-master-plan.md +0 -445
  415. package/docs/design/turboquant-kv.md +0 -235
  416. package/docs/design/turboquant-weights.md +0 -467
  417. package/docs/design/w4a16-compute-precision-spike.md +0 -232
  418. package/docs/design/web-chat-beat-matrix.md +0 -315
  419. package/docs/design/write-pipeline-entity.md +0 -468
  420. package/docs/planning/IDEAS.md +0 -69
  421. package/docs/reference/embedding.md +0 -197
  422. package/docs/reference/features-matrix.md +0 -101
  423. package/docs/reference/orpo-quickstart.md +0 -135
  424. package/src/flags.ts +0 -11
  425. /package/docs/{design → archive/investigations}/colibri-glm52-port.md +0 -0
  426. /package/docs/{planning → archive/planning}/chunk-task-roadmap.md +0 -0
  427. /package/docs/{planning → archive/planning}/curve-sampler-research-plan.md +0 -0
  428. /package/docs/{planning → archive/planning}/memory-docs-and-dag-plan.md +0 -0
  429. /package/docs/{planning → archive/planning}/pi-integration-review.md +0 -0
  430. /package/docs/{planning → archive/planning}/release-notes-v0.2.0.md +0 -0
  431. /package/src/{memory-plan.ts → admission-plan.ts} +0 -0
  432. /package/{docs/archive/investigations → src/serve/assets}/curve-terrain.html +0 -0
  433. /package/{docs/dag → src/serve/assets}/training-inference-map.html +0 -0
@@ -1,119 +1,222 @@
1
1
  # CLI reference
2
2
 
3
- Every mlx-bun verb. Commands are shown as `mlx-bun <verb>`; from a clone the
4
- identical command is `bun src/cli.ts <verb>`. `mlx-bun help <verb>` (or
5
- `mlx-bun <verb> --help`) prints the full flag list for any command.
6
-
7
- Model arguments are **substring queries** against the registry (`e4b`, `26B`,
8
- `12B-it`); a query matching more than one model errors out and lists the
9
- candidates — just make it more specific.
10
-
11
- Bare `mlx-bun` with no verb runs `serve` — the appliance path: first run
12
- downloads a starter model, serves it, and opens the chat UI.
13
-
14
- > All verbs below ship in current releases; the release notes in
15
- > `docs/planning/` record when each verb first appeared.
16
-
17
- ## Serving & chat
3
+ Every mlx-bun verb, from `src/cli.ts`. Commands are shown as
4
+ `mlx-bun <verb>`; from a clone the identical command is
5
+ `bun src/cli.ts <verb>`. `mlx-bun help <verb>` (or `mlx-bun <verb> --help`)
6
+ prints the full flag list for any command; `mlx-bun --version` (also `-v` or
7
+ `mlx-bun version`) prints the version.
8
+
9
+ **Model arguments are substring queries** against the registry (`e4b`,
10
+ `12B`, `qwen`, a repo substring); a query that matches more than one model
11
+ errors and lists the candidates. A directory containing `config.json` is
12
+ loaded directly wherever a model is accepted (`serve`, `pi`, `benchmark`,
13
+ `embed`, `fuse`, `convert`, `perplexity`).
14
+
15
+ **Bare `mlx-bun`** (no verb, or only options such as `mlx-bun --port 9000`)
16
+ runs `serve`. Explicit verbs and `--help`/`--version` still win.
17
+
18
+ **Unknown flags are ignored**, not rejected — `mlx-bun serve --kv-bits 4`
19
+ starts a server as if the flag were absent. The exceptions are `fuse` and
20
+ `convert`, which refuse the mlx-lm flags they don't implement (listed under
21
+ each verb).
22
+
23
+ ## Verb index
24
+
25
+ | Verb | Does | mlx-lm counterpart |
26
+ |---|---|---|
27
+ | `serve` | OpenAI/Anthropic-compatible server + web app | `mlx_lm.server` |
28
+ | `pi` | built-in coding agent on a local model | — (`mlx_lm.chat` is the nearest) |
29
+ | `harness pi` | connect your own pi install to the local server | — |
30
+ | `generate` (`gen`) | one-shot generation, no server | `mlx_lm.generate` |
31
+ | `embed` | text embeddings, no server | — |
32
+ | `get` | download a model (resumable, verified) | `mlx_lm.manage` (partial) |
33
+ | `scan` | re-index the Hugging Face cache | `mlx_lm.manage --scan` |
34
+ | `ls` | list downloaded models | `mlx_lm.manage --scan` |
35
+ | `gc` | reclaim superseded snapshots + dead blobs | `mlx_lm.manage --delete` (different unit) |
36
+ | `fit` | will it fit? memory + speed assessment | — (`optiq latency`) |
37
+ | `train` | LoRA fine-tune (SFT / DPO / ORPO) | `mlx_lm.lora --train` |
38
+ | `train-watch` | live dashboard for a training run | — |
39
+ | `fuse` | merge an adapter into the base weights | `mlx_lm.fuse` |
40
+ | `convert` | quantize an HF model into a local MLX snapshot | `mlx_lm.convert` (+ `mlx_lm.dynamic_quant`, `optiq convert`) |
41
+ | `upload` | push a model directory to the Hub | `mlx_lm.upload` |
42
+ | `perplexity` | perplexity over a local dataset | `mlx_lm.perplexity` |
43
+ | `memory` (`setup`) | the assistant's personal wiki | — |
44
+ | `benchmark` (`bench`) | decode/prefill speed of our stack | `mlx_lm.benchmark` |
45
+ | `evals` | recorded benchmark runs | — |
46
+ | `help` | overview or per-verb help | — |
47
+
48
+ ## Serving & agents
18
49
 
19
50
  ### `serve` — run the server
20
51
 
21
- Start the OpenAI/Anthropic-compatible server plus the browser web app (chat,
22
- status, and model tools).
52
+ Start the OpenAI/Anthropic-compatible server plus the browser web app.
23
53
 
24
54
  ```sh
25
- mlx-bun serve # default model, http://localhost:8080
26
- mlx-bun serve e4b # pick a model by substring
27
- mlx-bun serve gemma --memory-budget 18 # ...with admission control (GB)
28
- mlx-bun serve e4b --no-open # don't open the browser chat UI
29
- mlx-bun serve GLM-5.2 --context-length 4096 # bounded Colibri runtime, native MTP
55
+ mlx-bun serve # default model
56
+ mlx-bun serve e4b # pick a model by substring
57
+ mlx-bun serve --model ./fused_model # explicit path (mlx_lm.server spelling)
58
+ mlx-bun serve e4b --no-open # don't open the chat UI
59
+ mlx-bun serve GLM-5.2 --context-length 4096
30
60
  ```
31
61
 
32
- Common flags (full list in [server-config.md](server-config.md)):
33
-
34
- | Flag | Effect |
62
+ `serve` takes the model as a positional, `--query <q>`, or `--model <path|query>`
63
+ (`--model` wins). The flag set below is **shared with `mlx-bun pi`**. Defaults,
64
+ semantics, and which combinations compose live in
65
+ **[server-config.md](server-config.md)** — this page only names them.
66
+
67
+ Library requests support delayed uniform or per-layer affine conversion with
68
+ qualified shared drafting providers, including rotating caches. CLI affine
69
+ quantization starts at zero.
70
+
71
+ The unreleased shared executor supports qualified Qwen MTP and start-zero
72
+ TurboQuant at one or several active rows; `--batch 1` still selects the
73
+ legacy serial control. No new CLI flag is required for the shared interfaces.
74
+ Full-attention and rotating targets, including Llama, MiniCPM and Gemma, use shared bf16, uniform KV4/KV8, per-layer affine KV or TurboQuant
75
+ prompt lookup and standalone drafting, including generated RAM/SSD state.
76
+ Gemma assistant drafting also shares these target layouts and caches its last true target
77
+ hidden alongside target KV through the same RAM/SSD interfaces.
78
+ DeepSpec and DSpark use the same executor and persist their projected context through those
79
+ interfaces. DeepSpec accepts bf16 or affine-quantized weights; DSpark retains
80
+ its Markov/RNN head and checkpoint confidence policy.
81
+
82
+ Shared Qwen MTP retains completed decode state through the existing
83
+ `--prompt-cache` and `--ssd-cache` settings.
84
+
85
+ | Group | Flags |
35
86
  |---|---|
36
- | `--host <addr>` | Interface to bind (default `127.0.0.1`, loopback only; `0.0.0.0` to expose) |
37
- | `--port <n>` | Listen port (default 8080) |
38
- | `--memory-budget <GB>` | Admission ceiling for requests (bills the active `--kv-quant` scheme; clamps `max_tokens`, 400s only prompts that leave no room — never refuses to start) |
39
- | `--kv-budget <GB>` | Aggregate KV budget across concurrent batch rows: over-budget joiners queue until rows finish; a request over the budget alone is rejected (off unless set) |
40
- | `--prompt-cache <GB>` | RAM prefix-KV cache, byte-capped LRU (default 8; `0` disables). Non-consuming prefix sharing: a hit clones instead of consuming the donor entry |
41
- | `--isolate` | Run the inference engine as a crash-isolated child process on a unix socket; this process becomes a pure reverse-proxy (instant under GPU load, auto-respawns on engine crash) — default off ([runtime-isolation.md](../design/runtime-isolation.md)) |
42
- | `--model-pool <n>` | With `--isolate`: cap on resident per-model engine children (default 1); over the cap the LRU engine drains its cache to the SSD tier and exits, respawning on demand |
43
- | `--ssd-cache <dir>` | SSD cold tier under the prompt cache: idle/evicted prefix-KV spills to disk and restores on reattach, surviving restarts (default off — [ssd-kv-cold-tier.md](../design/ssd-kv-cold-tier.md)) |
44
- | `--ssd-cache-max <GB>` | SSD tier byte cap, oldest-mtime evicted first (default 32; `--ssd-cache` only) |
45
- | `--ssd-cache-verify` | Verify every tensor hash on restore, not just the header (integrity paranoia; roughly doubles restore reads; `--ssd-cache` only) |
46
- | `--ssd-demote-idle <sec>` | Idle prompt-cache entries spill to the SSD tier and free GPU memory after this long (default 300 with `--ssd-cache`; `0` disables) |
47
- | `--kv-quant config\|off\|4\|8\|turbo[:k<bits>v<bits>]` | KV cache quantization: per-layer `kv_config.json`, bf16, uniform bits, or TurboQuant (rotation-based, default `k8v3` — [turboquant-kv.md](../design/turboquant-kv.md); full-attention layers only, solo-only/serial) (default `off` — quantized KV trades 5–20% decode speed for memory headroom, so it's opt-in) |
48
- | `--paged-kv` | OPTIONAL vLLM-style paged KV cache (block pool + gather before the stock SDPA; env `MLX_BUN_PAGED_KV=1`) — bit-exact with the plain path, default off. v1: serial only (pins `--batch 1` unless `--batch` is given; refuses `--batch N>1`, `--kv-quant`, `--draft-model`), Gemma4-family, bf16; bypasses the prompt cache and runs uncompiled decode. Expect a small decode cost at batch=1 — v1 ships the abstraction for batched/CoW follow-ups ([paged-kv-cache.md](../design/paged-kv-cache.md)) |
49
- | `--paged-kv-block-size <n>` | Tokens per KV block (default 256 = the plain cache's growth step; `--paged-kv` only) |
50
- | `--adapter <dir>` | Mount a LoRA adapter at startup (`--adapter-path` accepted as the mlx_lm.server alias) |
51
- | `--draft-model <path\|query>` | Speculative decoding: a drafter proposes, the main model verifies — exact results, faster decode when drafts land. The artifact's kind is auto-detected: a full same-tokenizer model (mlx_lm.server parity), a Gemma `-assistant` KV-borrowing drafter, a DSpark checkpoint trained here, or one of DeepSeek's released DSpark drafters (DeepSpec `Gemma4DSparkModel`, e.g. `dspark_gemma4_12b_block7`). Serial lane only: with `--batch N` a mounted draft routes every request serial |
52
- | `--draft-kind <kind>` | Override draft-artifact detection: `two-model` \| `assistant` \| `dspark` \| `deepspec` \| `mtp` \| `ngram` (default: auto). `mtp` is a NATIVE multi-token-prediction head split from the target's own release (e.g. `mlx-community/Qwen3.8-27B-MTP-bf16`; auto-detected from a `*_mtp` `model_type`) — it binds the target's embeddings/lm-head and taps its pre-final-norm hiddens, and the serve loop rolls the target's recurrent DeltaNet caches back across rejected drafts via bit-exact snapshot/replay. `--draft-kind mtp` WITHOUT `--draft-model` resolves the companion from the artifact's own `mtp/` subfolder (single-repo bundles, e.g. the TQ releases) and refuses with a clear error when the model bundles none. `ngram` is MODEL-FREE prompt lookup — no `--draft-model` (mounting one alongside it is refused): drafts are copied from the request's own prompt+generation whenever its trailing tokens have occurred earlier in that stream, verified by the target like any other draft, so results stay exact at any temperature. Zero weights, zero memory; best on agentic/RAG/code-edit traffic that re-emits spans already in context (prior art: prompt-lookup decoding / vLLM's `ngram` proposer) |
53
- | `--num-draft-tokens <n>` | Drafts per verify round (default 3; `ngram` defaults to 10 — drafting is free; a DSpark draft pins to its trained block width) |
54
- | `--ngram-max <k>` / `--ngram-min <k>` | Prompt-lookup match-window bounds, `--draft-kind ngram` only: the longest/shortest trailing k-gram searched (defaults 3 / 1, the reference values) |
55
- | `--mtp on\|off` | GLM-5.2 checkpoint-native MTP (default on). Native MTP uses the exact serial verify lane; `off` enables ordinary continuous batching (batched per-row MTP is post-release) |
56
- | `--context-length <n>` | GLM-5.2 context reserved by the header-only resource equation (default 4096) |
57
- | `--batch <n>` | Continuous-scheduler concurrency cap, mlx-lm parity at the same B (default 8; a lone admitted request uses the gated B=1 fast path, while `--batch 1` pins the preserved strict serial executor) |
58
- | `--temperature` / `--top-p` / `--top-k` / `--max-tokens` | Server-wide sampling defaults (per-request fields still win; GLM-5.2 defaults to the planned 128 generated tokens) |
59
- | `--l1` / `--l2` | Parity tier alias: bit-exact to mlx-lm / bit-exact to mlx-optiq. **No tier = `--l1`** (the default since 2026-07-05 — output-changing levers are opt-in until they beat the L1 baseline in a paired A/B). Each expands to per-fork flags (`--compiled-decode`, `--compiled-activations`, `--fused-sdpa`, `--kv-quant`); a fork flag overrides one. `--l3` was removed 2026-07-05 and now errors (the Lab replaces it — [unified-engine-frontier-plan.md](../design/unified-engine-frontier-plan.md)). See [server-config.md](server-config.md#fidelity-tiers-and-the-decode-route---l1----l2). |
60
- | `--allow-private-media` | Let `image_url`/`audio_url` parts fetch from private/loopback/link-local hosts (blocked by default — SSRF guard; the 10 s timeout and 64 MB cap on remote media apply either way) |
61
- | `--no-open` | Don't auto-open the chat UI |
87
+ | Network | `--host`, `--port`, `--no-open`, `--allow-private-media` |
88
+ | Memory & caches | `--memory-budget`, `--kv-budget`, `--prompt-cache`, `--ssd-cache`, `--ssd-cache-max`, `--ssd-cache-verify`, `--ssd-demote-idle`, `--generation-checkpoint` |
89
+ | Process model | `--isolate`, `--model-pool`, `--unix` (internal — the engine half of `--isolate`) |
90
+ | Scheduling | `--batch` (`--decode-concurrency` accepted as the mlx_lm.server alias) |
91
+ | KV cache | `--kv-quant`, `--paged-kv`, `--paged-kv-block-size` |
92
+ | Adapters (compatible sets can batch) | `--adapter` (`--adapter-path` alias) |
93
+ | Speculative decoding (Qwen methods and full-attention/rotating lookup/standalone and Gemma assistant/DeepSpec/DSpark drafting share execution) | `--draft-model`, `--draft-kind`, `--num-draft-tokens`, `--ngram-max`, `--ngram-min` |
94
+ | GLM-5.2 | `--mtp`, `--context-length` |
95
+ | Sampling defaults | `--temperature` (`--temp` alias), `--top-p`, `--top-k`, `--max-tokens`, `--thinking`, `--hlg-sampling`, `--hlg-width`, `--hlg-shoulder`, `--hlg-toe`, `--hlg-pivot-offset` |
96
+ | Parity tier | `--l1`, `--l2` (`--l3` errors — removed) |
97
+ | Kill switches | `--compiled-decode`, `--compiled-activations`, `--fused-sdpa`, `--force-wire`, `--expert-offload` |
98
+
99
+ Serving treats memory estimates as advisory by default and attempts the request.
100
+ `--memory-budget` opts into estimated admission limits; `--kv-budget` opts
101
+ into aggregate KV limits. `--max-tokens` supplies an explicit output cap.
62
102
 
63
103
  Endpoints: `/v1/chat/completions`, `/v1/completions`, `/v1/messages`,
64
- `/v1/responses`, `/v1/models`, `/v1/adapters`, `/health`, `/stats`, `/fit`,
65
- `/library`, `/downloads` — web app at `/` (lands on chat); `/chat`, `/status`,
66
- `/quantize`, `/finetune`, `/dataset` deep-link its views. Full
67
- schemas in [server-api.md](server-api.md).
104
+ `/v1/responses`, `/v1/embeddings`, `/v1/models`, `/v1/adapters`, `/health`,
105
+ `/stats`, `/fit`, `/library`, `/downloads`; the web app at `/` (`/chat`,
106
+ `/status`, `/quantize`, `/finetune`, `/dataset` deep-link its views). Schemas
107
+ in [server-api.md](server-api.md).
68
108
 
69
109
  ### `pi` — built-in coding agent
70
110
 
71
111
  Run the pi coding agent's terminal UI in-process against a local model —
72
- nothing to install. Reuses a healthy running server, otherwise starts one for
73
- the session.
112
+ pi is bundled, nothing to install. Reuses a healthy server on the chosen
113
+ port; otherwise starts one that lives exactly as long as the session.
74
114
 
75
115
  ```sh
76
- mlx-bun pi # interactive agent session
77
- mlx-bun pi -p "explain this repo" # one-shot: print the reply and exit
116
+ mlx-bun pi # interactive session
117
+ mlx-bun pi fix the failing test # pre-fill the first turn
118
+ mlx-bun pi -p "explain this repo" # one-shot: print the reply and exit
119
+ mlx-bun pi -p --json "summarize README" # one-shot with the full event stream
120
+ mlx-bun pi --mode rpc # JSONL RPC over stdio
121
+ mlx-bun pi -q qwen --port 8090 # model + server flags for the session server
122
+ git diff | mlx-bun pi -p "review this" # piped stdin makes it one-shot too
78
123
  ```
79
124
 
125
+ | Flag | Meaning |
126
+ |---|---|
127
+ | `-q`, `--query <q>` | model to serve when starting a session server |
128
+ | `-p`, `--print [msg]` | one-shot print mode (also reads piped stdin) |
129
+ | `--json` | with `-p`: emit the full event stream as JSON |
130
+ | `--mode json\|rpc\|text` | `json` = print + JSON, `rpc` = JSONL RPC over stdio, `text` = print |
131
+ | `--verbose` | verbose agent logging |
132
+ | every `serve` flag | applies to the session server; ignored (with a note) when reusing a running one |
133
+
134
+ Other pi flags are dropped with a note — the full pi surface (`--continue`,
135
+ `--resume`, extensions, themes) lives in your own pi via `harness pi`.
136
+ `mlx-bun help pi` is our help; `mlx-bun pi --help` prints it only when it is
137
+ the sole argument.
138
+
80
139
  ### `harness pi` — connect your own pi
81
140
 
82
- For people who already use
83
- [pi](https://www.npmjs.com/package/@earendil-works/pi-coding-agent): installs a small,
84
- reversible discovery extension that registers the local server as a pi
85
- provider.
141
+ For people who already run [pi](https://www.npmjs.com/package/@earendil-works/pi-coding-agent):
142
+ writes one reversible extension, `~/.pi/agent/extensions/mlx-bun-provider.ts`,
143
+ that registers `mlx-bun` as a pi provider. Models are discovered live from
144
+ `/v1/models` at pi startup (the list baked at install time is the fallback
145
+ when the server is down), exposed under the stable id `mlx-bun/local`. It
146
+ never touches your existing pi config.
86
147
 
87
148
  ```sh
88
- mlx-bun harness pi # then: pi --provider mlx-bun
89
- mlx-bun harness pi --remove # disconnect
149
+ mlx-bun harness pi # install; requires pi on PATH
150
+ mlx-bun harness pi --base-url http://127.0.0.1:8090/v1
151
+ mlx-bun harness pi --remove # delete the extension
152
+ pi --provider mlx-bun # then run pi as usual
153
+ pi --models "mlx-bun/*" # or scope cycling
90
154
  ```
91
155
 
156
+ #### LoRA adapters from pi: the adapter extension
157
+
158
+ `scripts/packaging/pi-extensions/mlx-bun-adapter.ts` ships with the repo and
159
+ adds an `/adapter` command to pi. Install by copying (or symlinking) it into
160
+ `~/.pi/agent/extensions/`, then `/reload` inside pi:
161
+
162
+ ```sh
163
+ cp scripts/packaging/pi-extensions/mlx-bun-adapter.ts ~/.pi/agent/extensions/
164
+ MLX_BUN_URL=http://127.0.0.1:8080 pi --provider mlx-bun
165
+ ```
166
+
167
+ | In pi | Effect |
168
+ |---|---|
169
+ | `/adapter` or `/adapter list` | list adapters on disk (`/v1/adapters/available`), which are loaded, and the active one |
170
+ | `/adapter <id>` | mount it if needed (`POST /v1/adapters`) and inject `adapter: <id>` into every request |
171
+ | `/adapter off` | back to the base model (no field sent) |
172
+
173
+ The extension reads the server URL from `MLX_BUN_URL` (its built-in fallback
174
+ is port 8090, so set it to match your server). Default is no adapter; the
175
+ mechanism is pi's `before_provider_request` hook, the same one the web chat's
176
+ adapter selector uses. Serving-side detail: [server-api.md](server-api.md#adapters-lora-hot-swap)
177
+ and [docs/design/web-chat-redesign.md](../design/web-chat-redesign.md).
178
+
92
179
  ### `generate` (alias `gen`) — one-shot generation
93
180
 
94
- Load the model, generate, print, exit — no server. Renders through the chat
95
- template by default; `--raw` feeds the prompt verbatim. Sampling and
96
- decode-path levers mirror `serve` (`--temperature`, `--seed`, `--l1/--l2`,
97
- `--kv-quant`, …).
181
+ Load the model, generate, print, exit. The prompt is rendered through the
182
+ chat template unless `--raw`.
98
183
 
99
184
  ```sh
100
- mlx-bun generate gemma "a haiku about metal shaders"
185
+ mlx-bun generate e4b "a haiku about metal shaders"
101
186
  mlx-bun gen e4b --prompt "…" --max-tokens 512 --seed 42
102
- mlx-bun generate GLM-5.2 --prompt "Explain DSA" --max-tokens 128
187
+ mlx-bun generate qwen --raw --prompt "def fib(n):" --temperature 0
103
188
  ```
104
189
 
190
+ | Flag | Meaning |
191
+ |---|---|
192
+ | `[query]` / `--query <q>` | model (auto-picks when omitted) |
193
+ | `--prompt "…"` | the prompt (or pass it as the positional after the model) |
194
+ | `--raw` | skip the chat template |
195
+ | `--max-tokens <n>` | completion cap |
196
+ | `--temperature <n>` (`--temp` alias), `--top-p`, `--top-k`, `--seed` | sampling |
197
+ | `--l1` / `--l2`, `--kv-quant`, `--fused-sdpa`, `--compiled-decode`, `--compiled-activations` | decode route, same meaning as for `serve` |
198
+
105
199
  ### `embed` — text embeddings
106
200
 
107
- One-shot embeddings from a local Qwen3-Embedding model (last-token pooled,
108
- L2-normalized — bit-exact vs mlx-lm). One JSON vector per input line.
201
+ Embeddings from a local Qwen3-Embedding model, no server. One JSON vector
202
+ per input line.
109
203
 
110
204
  ```sh
111
205
  mlx-bun embed --text "hello world"
112
- echo -e "line one\nline two" | mlx-bun embed --json
206
+ mlx-bun embed Qwen3-Embedding "hello world"
207
+ printf 'line one\nline two\n' | mlx-bun embed --json
208
+ mlx-bun embed --instruct "Retrieve passages that answer the question" --text "what is a KV cache?"
113
209
  ```
114
210
 
115
- For a server endpoint, `mlx-bun serve <embedding-model>` then
116
- `POST /v1/embeddings`.
211
+ | Flag | Meaning |
212
+ |---|---|
213
+ | `[query]` / `--query <q>` | embedding model; omitted = the first downloaded embedding model (errors with a `get` suggestion when none) |
214
+ | `--text "…"` | text to embed (omit to read one text per stdin line) |
215
+ | `--instruct "…"` | Qwen3-Embedding query instruction; omit for plain document embeddings |
216
+ | `--json` | one OpenAI-style `{object:"list",data:[…]}` object instead of bare arrays |
217
+
218
+ Server equivalent: `mlx-bun serve <embedding-model>` then
219
+ [`POST /v1/embeddings`](server-api.md#post-v1embeddings-openai-embeddings-api).
117
220
 
118
221
  ## Models & disk
119
222
 
@@ -121,26 +224,26 @@ Full guide: [models.md](models.md).
121
224
 
122
225
  ### `get` — download a model
123
226
 
124
- Resumable, checksum-verified download into the standard Hugging Face cache
125
- (plain HTTPS, no Xet — no 0% stalls). Before payload transfer, the downloader
126
- credits complete blobs and partial prefixes, then requires enough free space
127
- for the exact remainder plus a fixed 1 GiB reserve.
227
+ Resumable (Range requests against partial blobs), sha256-verified download
228
+ into the standard Hugging Face cache over plain HTTPS (no Xet). Complete
229
+ blobs and partial prefixes are credited before transfer, and the volume must
230
+ fit the remainder plus a 1 GiB reserve. Uses `HF_TOKEN` / `hf auth login`
231
+ credentials when present.
128
232
 
129
233
  ```sh
130
234
  mlx-bun get mlx-community/gemma-4-12B-it-OptiQ-4bit
131
- mlx-bun get 12B # no "/" = registry query; re-gets/refreshes the match
132
- mlx-bun get mateogrgic/GLM-5.2-colibri-int4-with-int8-mtp \
133
- --revision 3cc8db99b1b13fc79325d987ba3c1c430766b3b8
235
+ mlx-bun get 12B # no "/" = registry query; re-gets/refreshes the match
236
+ mlx-bun get mlx-community/MiniCPM5-1B-OptiQ-4bit --revision main
134
237
  ```
135
238
 
136
- The GLM artifact is roughly 357 GiB; select `HF_HUB_CACHE` on a sufficiently
137
- large fast volume before starting. Rerunning the same command resumes verified
138
- `.incomplete` prefixes. See the [32 GB GLM quickstart](models.md#glm-52-on-a-32-gb-mac).
239
+ `--revision <rev>` selects a git revision. When upstream has pushed a new
240
+ revision the previous snapshot stays on disk — `get` says so and `gc`
241
+ reclaims it. GLM-5.2 specifics: [models.md](models.md#glm-52-on-a-32-gb-mac).
139
242
 
140
243
  ### `scan` — index your cache
141
244
 
142
- Re-index the HF cache into the registry (config + safetensors headers only,
143
- never tensor bytes) so `ls`, `serve`, and `fit` can find models by substring.
245
+ Re-index the HF cache into the registry (config + safetensors headers, never
246
+ tensor bytes) so `ls`, `serve`, and `fit` resolve models by substring.
144
247
 
145
248
  ```sh
146
249
  mlx-bun scan
@@ -148,105 +251,139 @@ mlx-bun scan
148
251
 
149
252
  ### `ls` — list models
150
253
 
254
+ One row per repo (canonical revision, `refs/main`); superseded snapshots are
255
+ hidden.
256
+
151
257
  ```sh
152
- mlx-bun ls # size, params, quant, capabilities
153
- mlx-bun ls --vision --max-size 10GB # filter
154
- mlx-bun ls --all-revisions # one row per cached snapshot
258
+ mlx-bun ls # size, params, quant, license, capabilities
259
+ mlx-bun ls gemma # filter by substring
260
+ mlx-bun ls --vision --max-size 10GB # vision-capable, under 10 GB
261
+ mlx-bun ls --all-revisions # one row per cached snapshot (canonical marked *)
155
262
  ```
156
263
 
157
264
  ### `gc` — reclaim disk
158
265
 
159
- Delete superseded snapshots and the blobs only they reference. Prints the plan
160
- by default; `--yes` actually deletes. Same planner (`src/registry.ts`
161
- `planGc`/`executeGc`) also backs `GET /api/gc/plan` / `POST /api/gc/execute`
162
- on a running `serve` — see [server-api.md](server-api.md#get-apigcplan--post-apigcexecute).
266
+ Delete superseded snapshots and the blobs only they reference. Prints the
267
+ plan by default.
163
268
 
164
269
  ```sh
165
- mlx-bun gc # dry-run: what would be reclaimed
166
- mlx-bun gc --yes # delete
270
+ mlx-bun gc # dry run: what would be reclaimed
271
+ mlx-bun gc --yes # delete
272
+ mlx-bun gc --yes --force # also prune snapshots holding files the canonical revision lacks
167
273
  ```
168
274
 
275
+ `--dry-run` never deletes even with `--yes`. The same planner backs
276
+ [`GET /api/gc/plan` / `POST /api/gc/execute`](server-api.md#get-apigcplan--post-apigcexecute).
277
+
169
278
  ### `fit` — memory contract
170
279
 
171
- Deterministic memory assessment: does it fit, what's the max context, predicted
172
- tok/s. Weights bytes from safetensors headers, KV bytes/token from the config,
173
- calibrated prefill transient, wired-memory ceiling. `--kv-quant` mirrors serve's
174
- flag: it bills the quantized cache at its true bytes/element, so the reported
175
- window matches what serving with the same flag admits (a 4-bit cache holds
176
- ~3.5× the context of bf16 in the same budget).
280
+ Deterministic memory assessment: does it fit, max safe context, predicted
281
+ tok/s — from safetensors headers, the config's KV bytes/token, a calibrated
282
+ prefill transient, and the wired-memory ceiling.
177
283
 
178
284
  ```sh
179
- mlx-bun fit gemma --ctx 32768 # for this machine
285
+ mlx-bun fit gemma --ctx 32768 # this machine
180
286
  mlx-bun fit gemma --ctx 8192 --skus # across the Apple Silicon lineup
181
- mlx-bun fit qwen --kv-quant 4 # window with a 4-bit-quantized KV cache
287
+ mlx-bun fit qwen --kv-quant 4 # bill a 4-bit-quantized KV cache
288
+ mlx-bun fit GLM-5.2 # streamed-artifact plan (resident weights, expert slabs, KV, reserves)
182
289
  ```
183
290
 
184
- The direct Colibri GLM-5.2 artifact is handled by its streamed-runtime
185
- contract, not by the generic resident-weights estimator. `fit GLM-5.2`
186
- defaults to the supported 4,096-token / 128-generation-token plan and reports
187
- the artifact's disk footprint separately from resident weights, the main and
188
- MTP expert slabs, KV, reserves, and the 25 GiB process ceiling. Its throughput
189
- line is the measured warm quality-preserving result; the direct Colibri oracle
190
- and the 2 tok/s aspiration are labeled separately. `--skus` explains that the
191
- generic resident-model matrix does not apply to this streamed artifact.
192
-
193
- ```sh
194
- mlx-bun fit GLM-5.2
195
- mlx-bun fit GLM-5.2 --ctx 4096
196
- ```
291
+ | Flag | Meaning |
292
+ |---|---|
293
+ | `--ctx <tokens>` | context size to assess |
294
+ | `--kv-quant 4\|8\|config\|off` | bill the KV cache at the quantized bytes/element (`config` needs a model that ships `kv_config.json`; `turbo` is not accepted here) |
295
+ | `--skus` | also print the Apple silicon SKU matrix (not applicable to the streamed GLM-5.2 artifact) |
197
296
 
198
297
  ## Training & model creation
199
298
 
200
299
  Full reference: [training.md](training.md); guided walkthrough:
201
- [orpo-quickstart.md](orpo-quickstart.md).
300
+ [docs/reference/training.md](./training.md).
202
301
 
203
302
  ### `train` — LoRA fine-tune
204
303
 
205
- SFT / DPO / ORPO on your data, with the full memory stack (flash-CCE head,
206
- prefix-sharing, segmented backward) on by default. Saves a mountable adapter.
304
+ SFT / DPO / ORPO on `<dir>/train.jsonl` (+ optional `valid.jsonl`). Rows are
305
+ `{prompt, chosen, rejected}` for dpo/orpo or `{messages|text}` for sft. Runs
306
+ in the foreground and saves a mountable adapter.
207
307
 
208
308
  ```sh
209
- mlx-bun train e4b --data ./prefs # ORPO (default) on {prompt,chosen,rejected}
210
- mlx-bun train e4b --data ./prefs --method sft # SFT on {messages|text}
211
- mlx-bun train e4b --data ./prefs --dry-run # inspect the plan, don't train
309
+ mlx-bun train e4b --data ./prefs # ORPO (default)
310
+ mlx-bun train e4b --data ./prefs --method sft
311
+ mlx-bun train e4b --data ./prefs --dry-run # inspect data + resolved plan, don't train
312
+ mlx-bun train cpm5 --data ./prefs --iters 400 --save-every 50 --adapter ~/adapters/cpm5-orpo
313
+ nohup mlx-bun train e4b --data ./prefs & # long runs: detach from your shell
212
314
  ```
213
315
 
316
+ | Flag | Meaning |
317
+ |---|---|
318
+ | `<model>` / `--query <q>` | model to fine-tune (auto-picks when omitted) |
319
+ | `--data <dir>` | dataset dir (required) |
320
+ | `--method sft\|dpo\|orpo` | objective |
321
+ | `--adapter <dir>` | output adapter dir (default under `~/.cache/mlx-bun/mlx-bun-finetunes/`) |
322
+ | `--iters`, `--lr`, `--rank`, `--scale`, `--seq`, `--batch`, `--grad-accum`, `--grad-clip`, `--seed`, `--val-size` | loop hyperparameters (method-dependent defaults: `mlx-bun help train`) |
323
+ | `--lambda <f>`, `--sft-scope full\|response` | ORPO odds-ratio weight and chosen-NLL scope |
324
+ | `--seg <n>`, `--no-segment` | segmented backward (layers per segment / off) |
325
+ | `--no-flash`, `--no-prefix` | disable the flash-CCE head / prefix-sharing |
326
+ | `--save-every <n>`, `--resume <dir>` | checkpoint cadence / warm-start LoRA weights |
327
+ | `--dry-run` | print the plan, don't train |
328
+
214
329
  ### `train-watch` — live training dashboard
215
330
 
216
- Tails an adapter dir's `metrics.jsonl` and renders live loss / speed / memory.
331
+ Tails `<adapter-dir>/metrics.jsonl` (written by `train` and the web
332
+ fine-tune tile) and renders live loss / speed / memory.
217
333
 
218
334
  ```sh
219
335
  mlx-bun train-watch ~/.cache/mlx-bun/mlx-bun-finetunes/orpo-e4b
336
+ mlx-bun train-watch --adapter ~/adapters/cpm5-orpo
220
337
  ```
221
338
 
222
339
  ### `fuse` — merge an adapter into the base
223
340
 
224
- Folds LoRA deltas into the base weights and writes a standalone snapshot; a
225
- quantized base keeps its exact quantization layout. Flag names match
226
- `mlx_lm.fuse`.
341
+ Folds LoRA deltas into the base weights and writes a standalone snapshot
342
+ (weights + config + tokenizer); a quantized base keeps its per-module
343
+ quantization layout. Flag names follow `mlx_lm.fuse`.
227
344
 
228
345
  ```sh
229
346
  mlx-bun fuse e4b --adapter ./adapters --save-path ./fused_model
347
+ mlx-bun fuse --model ./base-snapshot --adapter-path ./adapters
230
348
  mlx-bun serve ./fused_model
231
349
  ```
232
350
 
351
+ | Flag | Meaning |
352
+ |---|---|
353
+ | `<model>` / `--model` | base model (query or snapshot path) |
354
+ | `--adapter <dir>` (`--adapter-path` alias) | adapter directory (`adapters.safetensors` + `adapter_config.json`); default `adapters` |
355
+ | `--save-path <dir>` | output directory; default `fused_model` |
356
+
357
+ Refused with an error (mlx_lm.fuse flags not implemented): `--de-quantize`,
358
+ `--dequantize`, `--export-gguf`, `--gguf-path`, `--upload-repo`.
359
+
233
360
  ### `convert` — quantize a model
234
361
 
235
- Quantize an HF model (local path, downloaded model, or repo id) into a local
236
- MLX snapshot — uniform 4/8-bit, or mixed-precision via `--target-bpw`
237
- (sensitivity sweep + per-layer bit knapsack). `--upload-repo` pushes the result.
362
+ Quantize an HF model (local path, downloaded model, or repo id — an
363
+ un-downloaded repo is fetched first) into a local MLX snapshot: uniform
364
+ affine 4/8-bit, or mixed precision via `--target-bpw` (sensitivity sweep +
365
+ per-layer bit knapsack). Same engine as the web `/api/quantize`.
238
366
 
239
367
  ```sh
240
- mlx-bun convert Qwen/Qwen3-4B -q # uniform 4-bit
241
- mlx-bun convert Qwen/Qwen3-4B --target-bpw 4.5 # mixed precision
242
- mlx-bun convert ./qwen3.5-bf16 -q --rotate-weights # fold then quantize
368
+ mlx-bun convert Qwen/Qwen3-4B -q # uniform 4-bit → ./mlx_model
369
+ mlx-bun convert --hf-path Qwen/Qwen3-4B -q --q-bits 8 --mlx-path ./qwen3-8bit
370
+ mlx-bun convert Qwen/Qwen3-4B --target-bpw 4.5 # mixed precision (implies -q)
371
+ mlx-bun convert ./qwen3.5-bf16 -q --rotate-weights # fold the TurboQuant rotation, then quantize
372
+ mlx-bun convert Qwen/Qwen3-4B -q --upload-repo you/qwen3-4b-4bit
243
373
  ```
244
374
 
245
- `--rotate-weights` makes the offline rotation part of the same conversion
246
- pipeline and records its recipe in `optiq_metadata.json`. The adapter is
247
- selected from the model/tensor schema (Llama, Qwen3.5 trunk, or Qwen MTP);
248
- `--rotation-seed` defaults to `42`. Folding requires full-precision source
249
- weights and an MTP companion must use the same seed as its trunk.
375
+ | Flag | Meaning |
376
+ |---|---|
377
+ | `--hf-path <src>` (`--model` or the bare positional) | source model |
378
+ | `--mlx-path <dir>` | output directory; must not already exist (mlx_lm.convert behavior) |
379
+ | `-q`, `--quantize`, `--q-bits 4\|8`, `--q-group-size 32\|64` | uniform affine quantization |
380
+ | `--target-bpw <f>`, `--candidate-bits <list>`, `--calibration-mix optiq\|<jsonl>`, `--n-calibration <n>` | mixed precision (writes per-module bits into `config.json`) |
381
+ | `--rotate-weights`, `--rotation-seed <n>` | fold the offline TurboQuant rotation first (auto-detects Llama / Qwen3.5 trunk / Qwen MTP; an MTP companion must use its trunk's seed); recipe recorded in `optiq_metadata.json` |
382
+ | `--upload-repo <id>` | push the result afterwards (token checked before any work starts) |
383
+
384
+ Refused with an error: `--dtype`, `-d`/`--dequantize`, `--quant-predicate`,
385
+ `--q-mode` other than `affine`, and plain non-quantizing conversion (pass `-q`
386
+ or `--target-bpw`).
250
387
 
251
388
  ### `upload` — push to the Hugging Face Hub
252
389
 
@@ -255,57 +392,194 @@ git-LFS batch protocol, commits. Flag names match `mlx_lm.upload`.
255
392
 
256
393
  ```sh
257
394
  mlx-bun upload --path ./fused_model --upload-repo you/my-model
395
+ mlx-bun upload --path ./mlx_model --upload-repo you/my-model --private
258
396
  ```
259
397
 
398
+ Needs a WRITE token from `~/.mlx-bun/hf.json` (web UI Settings), `$HF_TOKEN`,
399
+ or `~/.cache/huggingface/token` (`hf auth login`); errors before uploading
400
+ anything when none is found. `--private` is an mlx-bun extension.
401
+
260
402
  ### `perplexity` — evaluate on your data
261
403
 
262
- `mlx_lm.perplexity` methodology exactly, over a **local** `.jsonl`/`.txt` file.
404
+ `mlx_lm.perplexity` methodology exactly (seeded sample order, concatenate,
405
+ non-overlapping rows, f32 CE at every position, delta-method standard
406
+ error) over a **local** `.jsonl` (`{"text": …}` rows) or `.txt` file — never
407
+ an HF dataset download.
263
408
 
264
409
  ```sh
265
410
  mlx-bun perplexity e4b --data-path ./corpus.jsonl
411
+ mlx-bun perplexity ./fused_model --data-path ./corpus.txt --sequence-length 1024 --num-samples -1 --batch-size 4 --seed 7
266
412
  ```
267
413
 
414
+ Flags: `<model>` (`--model` / `--query` accepted), `--data-path <file>`
415
+ (required), `--sequence-length <n>`, `--num-samples <n>` (`-1` = all),
416
+ `--batch-size <n>`, `--seed <n>`.
417
+
268
418
  ## Memory
269
419
 
270
- ### `memory` — the personal wiki
420
+ ### `memory` (alias `setup`) — the personal wiki
271
421
 
272
- A local, durable memory for the assistant: a git-tracked Markdown wiki at
273
- `~/.mlx-bun/wiki` that loads into every `mlx-bun pi` / `mlx-bun serve` session.
274
- Full guide: [memory.md](memory.md).
422
+ A local, git-tracked Markdown wiki at `~/.mlx-bun/wiki` that loads into
423
+ every `mlx-bun pi` / `mlx-bun serve` session. Full guide:
424
+ [memory.md](memory.md). `mlx-bun memory` with no subcommand runs `status`.
275
425
 
276
426
  ```sh
277
- mlx-bun memory init # create the wiki (idempotent); import + schedule
278
- mlx-bun memory status # path, article count, git + schedule state
279
- mlx-bun memory open [article] # open in Obsidian (falls back to Finder)
280
- mlx-bun memory search <query> # search articles from the terminal
281
- mlx-bun memory synthesize # conversations → cross-linked articles, all local
282
- mlx-bun memory schedule --at 03:00
427
+ mlx-bun memory init # create the wiki (idempotent); offers import + nightly job
428
+ mlx-bun memory status # path, article count, git + schedule state
429
+ mlx-bun memory open # open the vault in Obsidian (falls back to Finder)
430
+ mlx-bun memory open Archie_Project # open one article
431
+ mlx-bun memory list # article titles + read-only Reference docs
432
+ mlx-bun memory search kv cache # search from the terminal
433
+ mlx-bun memory read Archie_Project # print an article (stem)
434
+ mlx-bun memory toc Archie_Project # headings + anchors
435
+ mlx-bun memory section Archie_Project decisions # one section by anchor
436
+ mlx-bun memory links Archie_Project # outbound + inbound wikilinks
437
+ mlx-bun memory synthesize # conversations → articles, the full local DAG
438
+ mlx-bun memory synthesize --dry-run # plan only, never writes the vault
439
+ mlx-bun memory segment --limit 20 # one stage worker (also: extract, route, synthesize-stage)
440
+ mlx-bun memory extract --convs a1b2,c3d4 # restrict a stage to specific conversations
441
+ mlx-bun memory link --limit 50 # deterministic cross-linking pass (no model)
442
+ mlx-bun memory schedule --at 03:00 # install the nightly launchd job
443
+ mlx-bun memory unschedule # remove it
283
444
  ```
284
445
 
285
- `setup` is an alias for `memory`.
446
+ | Subcommand | Aliases | Meaning |
447
+ |---|---|---|
448
+ | `init` | `setup` | create the wiki; offers to import an existing vault and install the nightly job (TTY prompts; non-interactive shells take the defaults) |
449
+ | `status` | | path, counts, git + schedule state |
450
+ | `open [article]` | `browse` | open the vault or one article |
451
+ | `list` | | article titles + `Reference/` docs |
452
+ | `search <query>` | | ranked article hits with sample lines |
453
+ | `read <article>` | | print an article |
454
+ | `toc <article>` | | headings + anchors |
455
+ | `section <article> <anchor>` | | print one section |
456
+ | `links <article>` | | resolved outbound + inbound wikilinks |
457
+ | `synthesize` | `pipeline`, `all` | run the full synthesis DAG; `--dry-run` plans without writing. `--since` and `--model` are parsed but the pipeline does not consume them yet (`src/memory/pipeline.ts` marks `model` reserved) |
458
+ | `segment` · `extract` · `route` · `synthesize-stage` | `stage-synthesize` | run one decomposed, resumable stage worker (`--limit <n>` except `route`; `--convs a,b`) |
459
+ | `link` | | inline-link first mentions + rebuild `## See also` (`--limit <n>`; no model) |
460
+ | `schedule` | | install the nightly launchd job (`--at HH:MM`) |
461
+ | `unschedule` | | remove it |
462
+
463
+ An unknown subcommand prints the help and exits non-zero, so launchd jobs
464
+ and scripts can detect typos.
286
465
 
287
466
  ## Measurement
288
467
 
289
468
  ### `benchmark` (alias `bench`) — measure our stack
290
469
 
291
- Runs mlx-bun by itself on this machine and records to the eval DB.
470
+ Runs mlx-bun by itself (greedy decode, in-process) and records the median
471
+ to the eval DB.
292
472
 
293
473
  ```sh
294
474
  mlx-bun bench e4b --tokens 256 --runs 3
475
+ mlx-bun bench --model ./fused_model --prompt-tokens 4096 --kv-quant turbo:k8v3
476
+ ```
477
+
478
+ | Flag | Meaning |
479
+ |---|---|
480
+ | `[query]` / `--query` / `--model <path\|query>` | model (auto-picks when omitted) |
481
+ | `--tokens <n>` | tokens decoded per run |
482
+ | `--runs <n>` | runs (median reported) |
483
+ | `--prompt-tokens <n>` | pad the prompt to about n tokens (long-context decode) |
484
+ | `--kv-quant config\|off\|4\|8\|turbo[:k<bits>v<bits>]` | KV scheme for the run |
485
+ | `--compiled-decode`, `--compiled-activations`, `--fused-sdpa` | kill switches; A/B by running twice |
486
+
487
+ For **quotable, cross-stack** numbers use the preflight-gated harness from
488
+ the repo — it spawns the real CLI at its real defaults next to the mlx-lm
489
+ and optiq reference servers and writes a dated report:
490
+
491
+ ```sh
492
+ bun scripts/bench-serve.ts all
493
+ bun scripts/bench-serve.ts all --models cpm5,e4b --arms mlx-bun,mlx-lm --out report.md
494
+ bun scripts/bench-serve.ts all --models qwen27b --arms mlx-bun-serial,mlx-bun --logprobs --top-logprobs 3
495
+ # Same KV settings on both executors
496
+ bun scripts/bench-serve.ts all --models qwen27b --arms mlx-bun-serial,mlx-bun --kv-quant 4
497
+ # Same adapter settings on both execution arms:
498
+ bun scripts/bench-serve.ts all --models e4b --arms mlx-bun-serial,mlx-bun --adapter fixtures/adapters/upper
295
499
  ```
296
500
 
297
- For quotable **cross-stack** numbers use `./benchmark.sh` from the repo — it
298
- preflight-gates on an idle machine and runs the mlx-lm/optiq comparison legs,
299
- writing `benchmarks-h2h-<date>.md`.
501
+ Curated results: [benchmarks.md](benchmarks.md).
300
502
 
301
503
  ### `evals` — recorded runs
302
504
 
303
505
  ```sh
304
- mlx-bun evals # table: when, model, KV mode, tok/s, TTFT, peak, commit
506
+ mlx-bun evals # table: when, stack, model, bench, KV, prefill, decode, TTFT, peak, commit
507
+ mlx-bun evals --limit 50
305
508
  mlx-bun evals --raw # JSON lines for scripts/jq
509
+ mlx-bun evals --clear # archive the DB to a timestamped backup and start fresh
306
510
  ```
307
511
 
308
- ## Everything else
309
-
310
- - `help [verb]` — overview, or per-verb help (same as `<verb> --help`).
311
- - `--version` / `-v` — print the version.
512
+ ## mlx-lm compatibility
513
+
514
+ mlx-bun borrows mlx-lm's verb and flag vocabulary so scripts drop in with a
515
+ rename of the executable: `mlx_lm.<verb> …` becomes `mlx-bun <verb> …`.
516
+ There is no `mlx-bun.<verb>` dotted alias (the package installs one binary,
517
+ `mlx-bun`). Surface parity is not architecture parity: a verb run against an
518
+ unsupported architecture errors clearly rather than guessing.
519
+
520
+ ### What maps to what
521
+
522
+ | mlx-lm | mlx-bun | Accepted mlx-lm spellings | Not accepted |
523
+ |---|---|---|---|
524
+ | `mlx_lm.server` | `serve` | `--model`, `--host`, `--port`, `--adapter-path`, `--temp`, `--top-p`, `--top-k`, `--max-tokens`, `--draft-model`, `--num-draft-tokens`, `--decode-concurrency` (semantics differ — [server-config.md](server-config.md)) | `--prompt-cache-size`/`--prompt-cache-bytes` (use `--prompt-cache`), `--min-p`, `--chat-template`, `--chat-template-args`, `--use-default-chat-template`, `--trust-remote-code`, `--log-level`, `--allowed-origins`, `--pipeline`, `--prefill-step-size`, `--prompt-concurrency` — silently ignored |
525
+ | `mlx_lm.generate` | `generate` | `--prompt`, `--max-tokens`, `--temp`, `--top-p`, `--top-k`, `--seed` | `--kv-bits`/`--kv-group-size`/`--quantized-kv-start` (use `--kv-quant`), `--min-p`, `--xtc-*`, `--prompt-cache-file`, `--max-kv-size`, `--adapter-path`, `--draft-model`, `--system-prompt`, `--ignore-chat-template` (use `--raw`), `--verbose` — silently ignored |
526
+ | `mlx_lm.chat` | `pi` / the web chat | — | no terminal REPL verb; `pi` is the agent, `serve` opens the chat UI |
527
+ | `mlx_lm.convert` | `convert` | `--hf-path`, `--mlx-path`, `-q`/`--quantize`, `--q-bits`, `--q-group-size`, `--q-mode affine`, `--upload-repo` | `--dtype`, `-d`/`--dequantize`, `--quant-predicate`, non-affine `--q-mode`, plain non-quantizing conversion — **refused** |
528
+ | `mlx_lm.fuse` | `fuse` | `--model`, `--adapter-path`, `--save-path` | `--de-quantize`, `--export-gguf`, `--gguf-path`, `--upload-repo` — **refused** |
529
+ | `mlx_lm.lora --train` | `train` | `--data`, `--iters`, `--seed` (same names); otherwise own names (`--method`, `--adapter`, `--lr`, `--rank`, `--seq`, `--batch`, `--grad-accum`, `--save-every`, `--resume`) | `--train`/`--test`, `--config` (YAML), `--fine-tune-type`, `--adapter-path`, `--learning-rate`, `--max-seq-length`, `--batch-size`, `--num-layers`, `--mask-prompt`, `--optimizer` — silently ignored |
530
+ | `mlx_lm.upload` | `upload` | `--path`, `--upload-repo` (+ `--private`) | — |
531
+ | `mlx_lm.perplexity` | `perplexity` | `--model`, `--sequence-length`, `--num-samples`, `--batch-size`, `--seed`; `--data-path` is a local file | HF dataset ids |
532
+ | `mlx_lm.benchmark` | `benchmark` | `--model` | `-p`/`--prompt-tokens` short form, `-g`/`--generation-tokens`, `-b`/`--batch-size`, `-n`/`--num-trials` (ours: `--prompt-tokens`, `--tokens`, `--runs`; one stream) |
533
+ | `mlx_lm.manage` | `get` / `scan` / `ls` / `gc` | — | `--scan`/`--delete`/`--pattern` flag forms; `gc` deletes superseded snapshots, not whole repos |
534
+ | `mlx_lm.dynamic_quant` | `convert --target-bpw` | — | the `dynamic_quant` verb name |
535
+
536
+ mlx-optiq's CLI (`optiq convert` / `serve` / `lora` / `benchmark` / `eval` /
537
+ `latency` / `kv-cache` / `lab`) maps onto the same verbs where the concept
538
+ exists: `optiq convert` → `convert --target-bpw`; `optiq serve --kv-config`
539
+ → `serve --kv-quant config` (the `--l2` preset); `optiq latency` → `fit`;
540
+ `optiq lab` → the web app served by `serve`. `optiq eval` and `optiq
541
+ kv-cache` have no verb (below).
542
+
543
+ ### mlx-lm entry points: covered / not covered
544
+
545
+ Against the console scripts the pinned oracle ships
546
+ (`mlx_lm-*.dist-info/entry_points.txt` in the oracle venv). The scoping
547
+ behind each "not covered" row is in
548
+ [docs/reference/cli.md](./cli.md).
549
+
550
+ | Entry point | Status | Where |
551
+ |---|---|---|
552
+ | `mlx_lm.server` | covered | `serve` (incl. `--draft-model` speculative decoding) |
553
+ | `mlx_lm.generate` | covered | `generate` |
554
+ | `mlx_lm.chat` | covered differently | `pi` (agent TUI) + web chat; no plain REPL |
555
+ | `mlx_lm.convert` | covered | `convert` (quantizing paths only) |
556
+ | `mlx_lm.dynamic_quant` | covered | `convert --target-bpw` (sensitivity scan + per-layer bits) |
557
+ | `mlx_lm.lora` | covered (train) | `train`; the `--test` evaluation mode is not covered |
558
+ | `mlx_lm.fuse` | covered | `fuse` (no dequantize / GGUF / upload) |
559
+ | `mlx_lm.upload` | covered | `upload` |
560
+ | `mlx_lm.perplexity` | covered | `perplexity` (local files only) |
561
+ | `mlx_lm.benchmark` | covered | `benchmark` (own flag names; `evals` views the DB) |
562
+ | `mlx_lm.manage` | covered | `get` / `scan` / `ls` / `gc` |
563
+ | `mlx_lm.cache_prompt` | not covered | no on-disk prompt-cache files; the server's prompt cache (+ `--ssd-cache`) is the equivalent for served traffic |
564
+ | `mlx_lm.evaluate` | not covered | no lm-evaluation-harness backend; `benchmark`/`evals`/`perplexity` are the native measurement, and the `/v1` API accepts external harnesses |
565
+ | `mlx_lm.awq` | not covered | activation-aware weight quantization |
566
+ | `mlx_lm.dwq` | not covered | distilled weight quantization |
567
+ | `mlx_lm.gptq` | not covered | Hessian-conditioned rounding |
568
+ | `mlx_lm.share` | not covered | distributed cache share |
569
+ | `mlx_lm` (umbrella `mlx_lm <verb>`) | covered | `mlx-bun <verb>` is the same shape |
570
+
571
+ Native verbs with no mlx-lm counterpart — `pi`, `harness pi`, `embed`,
572
+ `fit`, `train-watch`, `memory`, `evals` — are the surface that makes mlx-bun
573
+ more than a drop-in.
574
+
575
+
576
+ `--kv-quant turbo` composes with grouped lookup, standalone, Gemma assistant,
577
+ DeepSpec and DSpark drafting on supported targets. Sliding layers stay bf16.
578
+ See [batching design](../design/batching.md) for composition evidence and limits.
579
+
580
+ Paged KV retains the configured `--batch` size. Gemma4 bf16 requests use the shared executor and bypass the prompt cache; quantized KV and draft combinations remain unavailable. See [server configuration](server-config.md).
581
+
582
+ `--generation-checkpoint N` requires `--ssd-cache` and queues owned snapshots
583
+ for eligible ordinary requests. Shared continuation supports eligible Qwen, Llama, MiniCPM and Gemma4 requests with or without adapters, excluding media, grammar, fill, paging, logprobs or speculation.
584
+ Repeat the identical request to replay and resume; flush before shutdown for
585
+ eventual queued snapshots to become durable.