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,371 +0,0 @@
1
- # DSpark serving program — flip spec wall-clock positive + design the product surface
2
-
3
- Status: **PLANNED** (2026-07-07). Trigger for Josh's pickup: TurboQuant merge —
4
- but only Phase 5 actually depends on it; Phases 0–4 are start-anytime.
5
- Owner: decode / spec. Predecessors: PR #19 (DSpark paper code-complete +
6
- serve-integrated + DeepSpec oracle), the first-live-run findings in
7
- [dspark-handoff.md](../archive/investigations/dspark-handoff.md) "FIRST LIVE RUN".
8
-
9
- ## The problem, in numbers (2026-07-07 first live run, loaded machine)
10
-
11
- `gemma-4-12B-it-OptiQ-4bit` + `deepseek-ai/dspark_gemma4_12b_block7` (γ=7):
12
-
13
- - **τ ≈ 2.8** committed tokens per target forward (2.7× fewer target calls) —
14
- the algorithm WORKS, at 26–33% per-token acceptance (the predicted
15
- OptiQ-4bit-target degradation vs their bf16 training).
16
- - **Wall-clock LOST ~3.4×** (spec 14.6 vs serial 49.8 agg tok/s). The tax is
17
- the drafter itself: 6.9 GB bf16 → ~3 GB of weight reads per draft round
18
- (2 GB untied lm_head + 7 × 134 MB markov_w2 + layers), ~14 host syncs per
19
- round in the transcription-faithful `draftBlock`, tapped verifies falling
20
- back to the unoptimized monolith, and ~14 GB of two-model weights
21
- squeezing the 24 GB box.
22
- - The 20 s bench TTFT was conc-4 queueing on the serial-forced spec lane
23
- (documented routing), not prefill — but per-request slowdown is real.
24
-
25
- **Goal:** spec ≥ 1.3× serial decode on 12B at the best config, clean-machine
26
- paired A/B — then (and only then) design when it's on by default. Every phase
27
- has its own gate; the drafter-quantization thesis
28
- ([[drafter-quantization-thesis]]) makes the risky-looking phase (aggressive
29
- quant) the SAFEST: drafter numerics only move acceptance, never correctness,
30
- so the entire quality gate is one acceptance A/B.
31
-
32
- **THE OBJECTIVE, stated right (Josh, 2026-07-07): 26–33% acceptance with the
33
- bf16 drafter is the WORKABLE BASELINE — τ≈2.8 already pays. The question
34
- quantization must answer is PRESERVATION: do we still get that number at
35
- 4-bit?** The point of quantizing (and of mixed precision specifically) is
36
- never compression for its own sake — it's cutting the drafter's cost 4×
37
- WITHOUT making it terrible at predicting tokens.
38
-
39
- **Sensitivity is MEASURED, never guessed — and THE TOOL ALREADY EXISTS
40
- (Josh): optiq's sensitivity method** (mlx-optiq.com/docs/sensitivity —
41
- per-group simulate-quant → KL vs reference on a curated calibration mix →
42
- greedy knapsack allocation to target BPW, emitted as a quant predicate).
43
- Phase 1e adopts it for the drafter rather than inventing anything; the
44
- drafter's target-hiddens-in forward even makes it cheaper (cached hiddens →
45
- no 12B in the sweep loop). Allocation comes from the measured table;
46
- hypotheses (lm_head argmax-proximal, chain compounding, buffered layers)
47
- are recorded for falsification only. Phase 1.5 (fine-tune) is an OPTIONAL
48
- UPSIDE lever on top of the workable baseline, not a premise that acceptance
49
- is broken.
50
-
51
- **And TurboQuant's role, stated right (Josh): TQ is the better-quant-at-
52
- EQUAL-bits instrument — the preservation tool, not a compression ladder.**
53
- Mechanism: distribute the weight vectors Gaussian, then place the
54
- quantization levels non-uniformly with FINER step sizes around the peak
55
- where the mass lives — affine 4-bit spends half its levels on tails TQ
56
- barely pays for. Expected: TQ-4bit preserves acceptance better than
57
- affine-4bit at the same size; the Phase-5 headline comparison is TQ-4 vs
58
- affine-4 AT EQUAL BPW, with lower-bpw rungs only after that's won.
59
-
60
- ## Phase 0 — baseline + attribution (no code; Josh's shell for GPU runs)
61
-
62
- The scoreboard everything else is measured against. All directional runs
63
- fine on a loaded box; the FINAL pre/post pair must be clean-machine.
64
-
65
- - [ ] **0a. Oracle gate the bf16 port ONCE** (before any optimization, so
66
- later acceptance deltas are attributable to quant/tuning, not port bugs):
67
- torch venv + DeepSpec install (header of
68
- `scripts/oracle-dspark-deepspec.py` documents setup), dump the temp-0
69
- trace (threshold 0 and 0.5 arms), run
70
- `scripts/dspark-deepspec-compare.ts` — target vs their reference on the
71
- **bf16 HF 12B** (`--target` the bf16 snapshot; the OptiQ-4bit arm is
72
- `--acceptance-only`, a measurement not a bit gate). Fixture per
73
- goldens/README.md conventions. Exit: round-for-round PASS, or a filed
74
- divergence with the first-divergent round attached.
75
- - [ ] **0b. γ sweep, conc 1** (no code): serve with `--num-draft-tokens`
76
- ∈ {2, 3, 5, 7} × `bench-feature-matrix.ts --concurrency 1 --cells
77
- serial,spec`. Record per-request tok/s + acceptance + TTFT per γ. Exit: a
78
- table; the best-γ config is the Phase 1 comparison base.
79
- - [ ] **0c. Time attribution**: xctrace (or coarse: MLX_BUN_LANE_DEBUG +
80
- timers around `source.draft` / verify forward / commit in a scratch
81
- branch) on ~20 rounds. Split: draft-block GPU, draft host syncs, verify
82
- forward, tap/commit overhead. Plus the paging check: RSS + `vm_stat`
83
- pageouts during a run (is the 14 GB pairing thrashing?). Exit: a
84
- percentage breakdown — it ORDERS phases 1–3 by measured value, replacing
85
- the estimates below.
86
-
87
- ## Phase 1 — quantize the drafter (uniform 4-bit baseline; NOT TurboQuant yet)
88
-
89
- The expected big lever: 6.9 GB → ~1.8 GB kills bandwidth AND memory pressure.
90
- mlx-native group quantization, no research dependency.
91
-
92
- - [x] **1a. `scripts/dspark-quantize-drafter.ts`** *(DONE 2026-07-07 — thin
93
- driver over the house quantizer: `src/spec/dspark/quantize-drafter.ts`
94
- adds a `quantizePredicate` overlay (confidence_head kept bf16, recorded
95
- as the mlx `false` convention); load smoke = DeepspecDrafter reload +
96
- one quantized fc forward)* — reads a DeepSpec-format
97
- checkpoint dir, writes a quantized sibling (same config.json + arch stamp,
98
- plus the house `quantization: {bits, group_size}` block). Per-tensor
99
- policy:
100
- - QUANTIZE (group-64, 4-bit default, flag-tunable): every 2-D matmul
101
- weight — `layers.*.self_attn.{q,k,o}_proj`, `layers.*.mlp.{gate,up,
102
- down}_proj`, `fc`, `lm_head`, `markov_head.markov_w2`, and
103
- `embed_tokens` + `markov_head.markov_w1` as quantized-gather lookups
104
- (mlx QuantizedEmbedding semantics — mlx-lm quantizes embeddings; ours
105
- must match its gather-dequant numerics).
106
- - KEEP bf16: all norms, `layers.*.layer_scalar`, `confidence_head.proj.*`
107
- (tiny), biases.
108
- - Output verified loadable before exit (load smoke).
109
- - [x] **1b. Quantized forward in `src/spec/dspark/deepspec-module.ts`**
110
- *(DONE 2026-07-07 — MatW/TableW weight representation: `.scales` sibling
111
- detection, quantized_matmul transpose=true for every Linear, mlx
112
- QuantizedEmbedding gather-dequant for embed_tokens/markov_w1; bf16 path
113
- keeps the lazy transpose views untouched; synthetic quantized-checkpoint
114
- describe block added — 8-bit tracks bf16 token-for-token)*:
115
- detect quantization at load (scales/biases sibling keys — the house
116
- detection pattern), route matmuls through `quantized_matmul` and lookups
117
- through the quantized-gather path; bf16 path untouched (both formats load
118
- through the same class — kind detection unchanged). Synthetic-format test
119
- extended with a tiny quantized checkpoint (same file, new describe block).
120
- - [x] **1c. The acceptance A/B harness** *(DONE 2026-07-07 — runner drives
121
- `specServeRun` per arm (target loaded once, drafters sequential); spec
122
- telemetry extended with per-position draftedByPos/acceptedByPos; the
123
- stats/verdict math is model-free in `src/spec/dspark/ab-stats.ts`,
124
- unit-tested in tests/dspark-ab-stats.test.ts; chat-template rendering
125
- pins enable_thinking OFF)* — `scripts/dspark-drafter-ab.ts`:
126
- same target, same prompt set (≥32 prompts, temp 0), drafter A vs drafter
127
- B; reports per-position acceptance, τ, tok/s, and a paired verdict. This
128
- is THE gate for every quantization experiment from here on (Phase 5
129
- reuses it unchanged). Model-free logic unit-tested; the run itself is
130
- GPU/Josh.
131
- - [ ] **1d. Run it**: 4-bit vs bf16 drafter at best-γ from 0b. Exit criteria:
132
- acceptance drop ≤ 3 points absolute AND wall-clock strictly improves;
133
- record both. If 4-bit alone flips spec past serial — say so loudly in the
134
- handoff, that's the headline.
135
- - [ ] **1e. The MEASURED sensitivity map — ADOPT OPTIQ'S METHOD, don't
136
- invent** (mlx-optiq.com/docs/sensitivity; source readable in the oracle
137
- venv's `site-packages/optiq`). Their loop, verbatim: reference logits on
138
- calibration data → simulate-quantize ONE group (quantize→dequantize
139
- round-trip) → KL divergence on the full output distribution → restore →
140
- next (group, bits); then their greedy knapsack (max KL-reduction per
141
- extra bit) allocates to a target BPW. **Applied to the drafter it gets
142
- CHEAPER than optiq's own runs**: the drafter isn't mlx_lm-loadable
143
- (its forward needs target hiddens), so `optiq convert` can't run on it
144
- directly — but that same fact removes the 12B from the loop entirely.
145
- Cache tapped hiddens ONCE over an optiq-style 6-domain calibration mix
146
- (our PATH-B shard format stores exactly this), then the whole sweep is
147
- drafter-forward-only KL: 3B × ~10 groups × candidate bits = minutes.
148
- The knapsack's output config gets ONE end-to-end acceptance A/B (1c
149
- harness) as confirmation — KL is the search signal, acceptance is the
150
- ship gate. Their protected-tensor defaults (lm_head/embed highest bits,
151
- first/last blocks) are noted as the static prior their own exact method
152
- exists to replace — we run the exact method; the drafter is small.
153
-
154
- ## Phase 1.5 — acceptance upside (OPTIONAL; the baseline is already workable)
155
-
156
- 26–33% (τ≈2.8) with the bf16 drafter pays as-is — this phase is the
157
- opportunistic numerator work on top, NOT a precondition: the gap vs their
158
- bf16-target numbers is distribution shift with a known mechanism, and every
159
- point recovered multiplies the cost work. Run it if Phase 1's preserved
160
- acceptance + cost win lands short of the ≥1.3× goal, or whenever the upside
161
- is worth the run.
162
-
163
- - [ ] **1.5a. Adaptation fine-tune on OUR target's hiddens** — their
164
- checkpoint as init (the expensive pretraining is done; this is short
165
- distribution adaptation, not their 10-epoch/38 TB run). The data comes
166
- from OUR stack by construction: tap `[5,17,29,41,46]` hidden dumps from
167
- the OptiQ-4bit 12B over on-distribution generations (the PATH-B regen
168
- tooling extracts exactly this). OPEN DESIGN (resolve first): where the
169
- gradient runs — (a) export our tapped-hidden shards into DeepSpec's
170
- torch trainer format and fine-tune with THEIR code (MIT; least new code,
171
- needs a torch box/venv and a shard-format bridge), vs (b) a training
172
- path for the deepspec module in our stack (autograd through the port —
173
- more work, fully local). Gate: acceptance A/B (1c harness) pre/post
174
- fine-tune on held-out prompts; expected: a large chunk of the
175
- bf16-vs-OptiQ gap closes.
176
- - [ ] **1.5b. Confidence-threshold activation** — at 26% acceptance the
177
- scheduler is finally in its design regime: sweep the raw threshold
178
- (their knob) and/or our calibrated thresholds; objective =
179
- tokens-per-second, not τ (pruning doomed positions trades a little τ
180
- for less wasted draft+verify work). Free: no code, the machinery
181
- shipped in PR #19.
182
- - [ ] **1.5c. Quantify the target-fidelity axis** (measurement, not a
183
- build): acceptance vs target quant — e.g. the same drafter against a
184
- higher-fidelity 12B variant if one fits (mixed/8-bit tap-layer
185
- experiments), to split "drafter needs adapting" from "target hiddens
186
- are too degraded". Informs whether 1.5a alone suffices.
187
-
188
- ## Phase 2 — tighten `draftBlock` (replay the proven tightening)
189
-
190
- `Gemma4DSparkModel.draftBlock` kept the reference's per-position structure
191
- (transcription fidelity): 7 argmax `itemUint32` syncs + 7 confidence
192
- `toFloat32` syncs per round. We already solved this exact shape once
193
- (module-dflash.ts, 2026-07-06 — bit-identity-pinned).
194
-
195
- - [ ] **2a. On-device token chaining**: the sequential Markov loop keeps the
196
- argmax result as a device `[1]` index feeding the next position's
197
- `takeAxis(markov_w1, ·)`; ONE concat + ONE host read after the loop.
198
- (Post-1b the bias matmul is quantized too.)
199
- - [ ] **2b. Confidence: compute NOTHING at threshold ≤ 0** (their default —
200
- today we compute + sync 7 confidences that are then unused); when a
201
- threshold IS set, per-position reads are inherent to the truncation
202
- decision (same reasoning as the dflash loop — document it).
203
- - [ ] **2c. `collectLogits`-style skip** for `baseLogits` if the serve path
204
- still materializes anything it discards (audit `DeepspecSource.draft` —
205
- it disposes `block.baseLogits` unread; make the module skip building it,
206
- mirroring `DflashDraftOpts.collectLogits`).
207
- - [ ] **Gate**: bit-identity — pinned tokens on the deterministic synthetic
208
- checkpoint pre/post rewrite (the tests/dspark-infer-loop.test.ts
209
- pattern), plus real-checkpoint determinism (same prompt twice → same
210
- drafts). Tightening is a pure optimization; any token change is a bug.
211
-
212
- ## Phase 3 — `captureLayer` in the generated gemma forwards
213
-
214
- Tapped spec forwards (prefill + EVERY verify round) currently fall back to
215
- the monolith (the 2026-07-07 guard fix — correct-but-unspecialized). The
216
- verify forward is the spec path's biggest single GPU cost; give it back the
217
- generated fast path. Independent of Phases 1–2; parallelizable.
218
-
219
- - [ ] **3a. `scripts/gen-model.ts`**: emit the tap exactly as the monolith
220
- does — `captureLayer(i, h)` after each layer's residual
221
- (gemma4.ts:970 semantics) + the post-finalNorm sentinel
222
- (index = nLayers, gemma4.ts:989) — and REMOVE `this.hiddenTap !== null`
223
- from the emitted fallback guard.
224
- - [ ] **3b. Regenerate all three** (12b / 26b / e4b; regen commands in each
225
- file's header) — the hand-patched guards are superseded by generator
226
- output.
227
- - [ ] **Gate**: (i) generated-parity suite green (untapped behavior
228
- untouched); (ii) NEW tap-parity check — tapped rows bit-equal
229
- monolith-vs-generated on the same input (model-gated test, e4b);
230
- (iii) spec bench pre/post for the verify-round win.
231
-
232
- ## Phase 4 — serving UX: flags, defaults, composition (the product pass)
233
-
234
- Decisions, made on Phase 0–3 DATA, then implemented. The doctrine rails:
235
- drop-in-replacement (a lone request must never get slower because a flag
236
- exists), dont-delete-optionality (losing configs stay documented
237
- default-off), spec = opt-in until it WINS a clean-machine paired A/B.
238
-
239
- - [ ] **4a. γ default per drafter kind**: the checkpoint's trained γ is the
240
- cap, not necessarily the default — if 0b says γ=3 beats γ=7 at our
241
- acceptance, `numDraftTokens` defaults to the measured-best (per-kind
242
- table in code, overridable), and the handoff documents why.
243
- - [ ] **4b. Quantized-drafter UX**: `mlx-bun get` the bf16 →
244
- `scripts/dspark-quantize-drafter.ts` is a manual step today; decide
245
- whether `serve --draft-model <bf16-dir>` should offer/auto-run the
246
- 4-bit conversion (like the starter-model flow) or just print the
247
- command. Also: registry listing shows drafters distinctly (they are not
248
- servable models — `/v1/models` must NOT list them; verify).
249
- - [ ] **4c. Spec × prompt-cache composition** (parity-plan §7.6 — currently
250
- BYPASSED on the spec path, v1 note in serve-loop.ts): multi-turn agents
251
- re-prefill every turn when a draft is mounted. Scope it here or
252
- explicitly re-defer with the measured cost (12B multi-turn TTFT with
253
- spec on). At minimum: the boundary-snapshot machinery must not regress
254
- when spec is mounted.
255
- - [ ] **4d. Surface audit**: `--draft-kind` (keep), `--num-draft-tokens`
256
- semantics doc, `/stats` shows mounted drafter + kind + γ, `usage.
257
- speculation` already ships. server-config.md gets a "speculative
258
- serving" section consolidating the four kinds + the when-does-it-pay
259
- table (from Phase 0/1 data). features-matrix + cli.md + README rows.
260
- - [ ] **4e. The default decision, written down**: for each (model, drafter)
261
- pair measured, spec default on/off per the clean-machine A/B — recorded
262
- in RESULTS.md "composition" + the features matrix. (Prediction to test:
263
- ON for 12B+quantized drafter, OFF for e4b anything.)
264
-
265
- ## Phase 5 — TurboQuant application (the trigger event)
266
-
267
- Trigger, precisely: **TQ WEIGHT quantization** in the convert tooling — PR
268
- #20 (2026-07-07) landed TurboQuant for KV; the rotation-based weight-side
269
- is the noted follow-up (turboquant-kv.md), and it's what the drafter
270
- needs. The drafter is its lowest-risk first customer — one-number gate,
271
- no KL/eval battery. **TQ's HYPOTHESIS here is PRESERVATION AT EQUAL BITS**
272
- (Gaussian-distributed vectors + finer step sizes around the peak, where
273
- affine spends half its levels on tails) — a hypothesis 5b MEASURES, never
274
- a default: TurboQuant earns its place the same way everything in this
275
- repo does.
276
-
277
- - [ ] **5a.** Extend `dspark-quantize-drafter.ts` with the TurboQuant
278
- scheme.
279
- - [ ] **5b. THE HEADLINE: TQ-4bit vs affine-4bit AT EQUAL BPW** through the
280
- Phase-1c harness — same size, whose acceptance is closer to bf16? If
281
- affine-4 bled in 1d, this is the expected fix; if affine-4 held, TQ's
282
- margin becomes headroom for lower rungs. Only AFTER TQ-4 ≥ affine-4:
283
- the lower-bpw ladder (3.5 / 3.0 / 2.5) → acceptance-per-byte curve,
284
- knee adopted (dont-delete-optionality for the rest).
285
- - [ ] **5b″. TQ IS HOW, SENSITIVITY-AWARE IS WHAT (Josh)** — two orthogonal
286
- axes, never mixed: TQ vs affine is a METHOD question (decided by 5b's
287
- equal-bpw measurement — a method that wins at equal bits wins for every
288
- tensor, so there is no reason to mix METHODS within an artifact);
289
- sensitivity is the bit ALLOCATION question (the 1e knapsack, whatever
290
- the method — candidate set {method-2, method-3, method-4, method-8} per
291
- group, measured KL cost each, greedy to target BPW). IF 5b confirms TQ,
292
- the artifact is TQ-uniform at knapsack-allocated bits; if it doesn't,
293
- affine-uniform at knapsack-allocated bits — either way the OUTCOME of
294
- the measurement, not a premise. Nothing here is "on by default";
295
- defaults are Phase 4e/6 decisions made on clean-machine numbers.
296
- - [ ] **5b′. PER-TENSOR MIXED PRECISION rungs** (Josh, 2026-07-07). The
297
- intuition "only 5 layers = few knobs" undercounts: the drafter's mass is
298
- ~10 TENSOR GROUPS, and two of them are 58% of the bytes — `lm_head`
299
- (~2 GB, read FULLY every round: the bandwidth whale) and `embed_tokens`
300
- (~2 GB, gather-only: ~free to read, pure resident-memory win), plus
301
- `markov_w2` (134 MB read ×7/round ≈ 940 MB). Both whales only shape the
302
- DRAFT distribution → acceptance-only risk. Mixed rungs to sweep: 3-bit
303
- lm_head + 3-bit markov_w2 + 4-bit layers; 2-bit embed variants; k_proj
304
- (2 M params) 8-bit for free. The ~10-group space is small enough for a
305
- near-exhaustive sweep through the SAME one-number harness — unlike
306
- sensitivity search on a full model. **Allocation objective (the point):
307
- PRESERVE the bf16 acceptance at the smallest cost, not minimize bytes —
308
- and allocation follows the MEASURED sensitivity table from 1e, never a
309
- prior.** The mixed rungs are built FROM the table: give the measured-
310
- sensitive groups more bits (or TQ them, post-Phase-5), squeeze the
311
- measured-insensitive ones. The "only 5 layers" worry dissolves either
312
- way — the tensor-group space (~10 knobs, two of them 58% of the bytes)
313
- is the real granularity, and 1e prices every knob empirically.
314
- - [ ] **5c.** If TurboQuant wins: fold the recipe into 4b's UX (the
315
- conversion the server offers is the TurboQuant one).
316
-
317
- ## Phase 6 — quotable results + promotion
318
-
319
- - [ ] Clean-machine protocol (reboot + `sudo purge`), then: bench-feature-
320
- matrix conc-1 AND agg×4, serial vs best-spec-config, on 12B (and e4b as
321
- the expected-negative control). Promote to `benchmarks/RESULTS.md`
322
- "composition"; update decode-speed-program.md (lever 1c: measured),
323
- STATUS, and the handoff's FIRST LIVE RUN section with the closing
324
- numbers.
325
- - [ ] Loose ends carried from PR #19, closed or re-deferred with reasons:
326
- the paper-faithful gated RNN head (seqHead:"gru", currently variant-
327
- documented), paper-Alg-1/STS survival-product scheduler (Lab item),
328
- per-slot spec under batching (unified-engine frontier row — NOT this
329
- program).
330
-
331
- ## Dependency graph + who does what
332
-
333
- ```
334
- 0a (oracle gate, Josh: venv+GPU) ──┐
335
- 0b (γ sweep, Josh: GPU) ──────────┼─→ 1a→1b→1c→1d (quant baseline; 1d Josh GPU)
336
- 0c (attribution, Josh: GPU) ───────┘ │
337
- ├─→ 1.5 (OPTIONAL acceptance
338
- │ upside: fine-tune on our
339
- │ target's hiddens + threshold
340
- │ sweep; run if 1's preserved
341
- │ acceptance falls short)
342
- ├─→ 2a-2c (tightening; CPU-gated)
343
- 3a-3b (generator tap; parallel anytime) ────┤
344
- └─→ 4 (UX, needs 0–3 data)
345
- TurboQuant merge ─→ 5a-5c (reuses 1c harness) ─→ 6 (clean machine, Josh)
346
- ```
347
- Priority note: Phase 1's PRESERVATION question ("do we keep 26–33% at
348
- 4-bit?") is the program's hinge — one A/B answers it; if affine-4 bleeds,
349
- the answers are MEASURED (1e sensitivity table → mixed allocation) and
350
- ENGINEERED (Phase 5: TQ-4 at equal bpw — the better quant is the designed
351
- fix, not a fallback).
352
-
353
- Code phases (1a/1b/2/3/4-impl) are agent-runnable sessions; every GPU
354
- measurement is Josh's shell. Nothing except Phase 5 waits on TurboQuant —
355
- Phases 0–4 can land first so TurboQuant drops into a finished harness.
356
-
357
- ## Exit criteria for the whole program
358
-
359
- 1. Spec wall-clock ≥ 1.3× serial on 12B at the recommended config,
360
- clean-machine paired — or a written verdict that it can't be reached and
361
- why (with the config left as a characterized default-off lever).
362
- 2. **Acceptance PRESERVED and understood**: the quantized drafter holds the
363
- bf16 baseline's 26–33% (or the mixed rung that does is adopted, or the
364
- loss is measured and accepted with numbers); the optional 1.5 upside
365
- levers are run-or-explicitly-deferred — the drafter predicts tokens;
366
- small was never the goal.
367
- 3. The acceptance-per-byte curve exists (TurboQuant vs 4-bit vs mixed vs
368
- bf16), with acceptance-at-fixed-budget allocation swept (5b′).
369
- 4. The serving surface is documented, defaults decided per-pair and
370
- recorded, and a fresh `mlx-bun get` → serve → speedup flow works without
371
- reading any design doc.