mlx-bun 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -32
- package/docs/README.md +58 -42
- package/docs/archive/investigations/benchmark-ledger-through-v0.4.0.md +3617 -0
- package/docs/archive/investigations/openjarvis-fit.md +198 -0
- package/docs/archive/investigations/qwen38-27b-campaign-log.md +1092 -0
- package/docs/archive/planning/release-notes-v0.4.0.md +45 -0
- package/docs/archive/planning/release-notes-v0.5.0.md +37 -0
- package/docs/design/batching.md +1535 -50
- package/docs/design/decode-speed-program.md +394 -1171
- package/docs/design/generic-model-support.md +195 -3
- package/docs/design/kv-cache.md +538 -225
- package/docs/design/speculative-decoding.md +552 -50
- package/docs/design/turboquant.md +140 -17
- package/docs/design/unified-engine-frontier-plan.md +259 -150
- package/docs/planning/PRODUCT_ROADMAP.md +21 -6
- package/docs/planning/public-readiness-handoff.md +244 -0
- package/docs/planning/public-readiness.md +149 -0
- package/docs/reference/benchmarks.md +3537 -1112
- package/docs/reference/cli.md +102 -2
- package/docs/reference/distribution.md +45 -13
- package/docs/reference/environment.md +159 -13
- package/docs/reference/library-api.md +18 -4
- package/docs/reference/memory.md +1 -1
- package/docs/reference/models.md +28 -7
- package/docs/reference/server-api.md +257 -33
- package/docs/reference/server-config.md +372 -151
- package/docs/reference/troubleshooting.md +13 -21
- package/package.json +2 -2
- package/src/audio/audiotoolbox.ts +112 -0
- package/src/audio/conformer.ts +8 -0
- package/src/audio/mic-capture.ts +98 -0
- package/src/audio/silero-vad.ts +379 -0
- package/src/audio/whisper-decode.ts +774 -0
- package/src/audio/whisper-fast.ts +732 -0
- package/src/audio/whisper-format.ts +73 -0
- package/src/audio/whisper-mel.ts +185 -0
- package/src/audio/whisper-timing.ts +274 -0
- package/src/audio/whisper-tokenizer.ts +239 -0
- package/src/audio/whisper-transcribe.ts +410 -0
- package/src/backends/mlx/assistant-target.ts +46 -0
- package/src/backends/mlx/autoregressive-draft-rows.ts +120 -0
- package/src/backends/mlx/autoregressive.ts +22 -1
- package/src/backends/mlx/batch-group.ts +464 -236
- package/src/backends/mlx/cache-attachment.ts +67 -0
- package/src/backends/mlx/cache-layout.ts +31 -0
- package/src/backends/mlx/checkpoint-state.ts +53 -0
- package/src/backends/mlx/continuation-persistence.ts +107 -0
- package/src/backends/mlx/continuation-request.ts +43 -0
- package/src/backends/mlx/continuation.ts +77 -0
- package/src/backends/mlx/draft-target.ts +7 -22
- package/src/backends/mlx/encoder-cache.ts +25 -0
- package/src/backends/mlx/fill-append.ts +21 -8
- package/src/backends/mlx/fill-group.ts +497 -0
- package/src/backends/mlx/full-kv-row-append.ts +32 -0
- package/src/backends/mlx/full-kv-row-donor.ts +54 -0
- package/src/backends/mlx/full-transitioning-kv-rows.ts +65 -0
- package/src/backends/mlx/gateway-binding.ts +122 -19
- package/src/backends/mlx/kv-codec.ts +9 -0
- package/src/backends/mlx/kv-maintenance.ts +161 -0
- package/src/backends/mlx/kv-tensor-rows.ts +212 -0
- package/src/backends/mlx/mixed-iteration.ts +62 -0
- package/src/backends/mlx/model-prompt.ts +46 -32
- package/src/backends/mlx/model-serving.ts +5 -4
- package/src/backends/mlx/paged-cache-codec.ts +27 -0
- package/src/backends/mlx/prefill-cohort.ts +100 -0
- package/src/backends/mlx/prefill-policy.ts +26 -0
- package/src/backends/mlx/prefill-rows.ts +244 -0
- package/src/backends/mlx/prefill.ts +1 -1
- package/src/backends/mlx/projected-context-rows.ts +72 -0
- package/src/backends/mlx/prompt-input.ts +29 -0
- package/src/backends/mlx/qwen-prompt-input.ts +40 -0
- package/src/backends/mlx/request-state-policy.ts +54 -0
- package/src/backends/mlx/rollback.ts +45 -4
- package/src/backends/mlx/row-sampling.ts +49 -0
- package/src/backends/mlx/serial-executor.ts +51 -73
- package/src/backends/mlx/speculative-group.ts +438 -0
- package/src/backends/mlx/speculative-round.ts +161 -0
- package/src/backends/mlx/speculative.ts +24 -7
- package/src/backends/mlx/state-rows.ts +104 -0
- package/src/backends/mlx/state-views.ts +21 -1
- package/src/backends/mlx/target-layout-capability.ts +35 -0
- package/src/backends/mlx/transitioning-kv-rows.ts +173 -0
- package/src/cli.ts +333 -36
- package/src/contracts/execution.ts +21 -0
- package/src/contracts/object-cache.ts +8 -0
- package/src/contracts/pi-provider.ts +1 -1
- package/src/contracts/pi.ts +3 -1
- package/src/contracts/prefix-cache.ts +33 -0
- package/src/contracts/resources.ts +7 -0
- package/src/contracts/sampling.ts +23 -0
- package/src/contracts/scheduling.ts +27 -0
- package/src/engine/execution-plan.ts +38 -25
- package/src/engine/execution-tasks.ts +44 -0
- package/src/engine/namespaced-cache.ts +13 -0
- package/src/engine/resources.ts +12 -1
- package/src/engine/scheduler.ts +32 -7
- package/src/fill/fill-session.ts +14 -3
- package/src/fit.ts +29 -15
- package/src/generate.ts +105 -195
- package/src/grammar.ts +13 -0
- package/src/inference/draft-acceptance.ts +41 -0
- package/src/inference/draft-output.ts +49 -0
- package/src/inference/prefill.ts +6 -0
- package/src/inference/rollback.ts +2 -2
- package/src/kv-scheme.ts +92 -12
- package/src/kv-store.ts +183 -93
- package/src/lab/README.md +5 -1
- package/src/lab/paged-kv/paged-attention.ts +117 -0
- package/src/lab/paged-kv/paged-kv-rows.ts +111 -0
- package/src/lab/paged-kv/paged-kv.ts +126 -46
- package/src/md-modules.d.ts +5 -0
- package/src/mlx/array.ts +39 -1
- package/src/mlx/ffi.ts +19 -0
- package/src/mlx/normalized-argmax.ts +116 -0
- package/src/mlx/ops.ts +97 -10
- package/src/model/artifact-identity.ts +73 -0
- package/src/model/batched-kv.ts +235 -0
- package/src/model/batched-mask.ts +12 -4
- package/src/model/batched-quant.ts +8 -2
- package/src/model/batched-quantized-kv.ts +144 -0
- package/src/model/batched-rotating-quant.ts +76 -15
- package/src/model/batched-rotating-state.ts +76 -0
- package/src/model/batched-rotating.ts +64 -22
- package/src/model/batched-row-storage.ts +52 -0
- package/src/model/batched-ssm.ts +52 -0
- package/src/model/batched-turboquant-kv.ts +94 -0
- package/src/model/compiled-decode.ts +7 -1
- package/src/model/decoded-kv-donor.ts +12 -0
- package/src/model/delayed-quantized-kv.ts +72 -0
- package/src/model/delayed-rotating-quantized-kv.ts +93 -0
- package/src/model/delayed-turboquant-kv.ts +57 -0
- package/src/model/factory.ts +26 -0
- package/src/model/fingerprint.ts +12 -0
- package/src/model/full-prefill-padding.ts +56 -0
- package/src/model/full-prefill-row.ts +105 -0
- package/src/model/gemma4-base.ts +183 -82
- package/src/model/gemma4.ts +116 -28
- package/src/model/generated/gemma4-12b.ts +4 -1
- package/src/model/generated/gemma4-26b.ts +4 -1
- package/src/model/generated/gemma4-e4b.ts +4 -1
- package/src/model/glm52-cache.ts +80 -4
- package/src/model/glm52-mla.ts +12 -6
- package/src/model/glm52.ts +19 -40
- package/src/model/kv-attention-view.ts +70 -0
- package/src/model/minicpm5.ts +11 -7
- package/src/model/profile.ts +29 -4
- package/src/model/quantized-append-attention.ts +31 -0
- package/src/model/qwen3-delta-state.ts +74 -0
- package/src/model/qwen3-delta.ts +59 -36
- package/src/model/qwen3-mrope.ts +7 -9
- package/src/model/qwen3_5.ts +177 -75
- package/src/model/rotating-kv-donor.ts +35 -0
- package/src/model/rotating-kv-layout.ts +262 -0
- package/src/model/rotating-row-transaction.ts +35 -0
- package/src/model/speculative-rotating-kv.ts +101 -0
- package/src/model/ssm-prefill-padding.ts +39 -0
- package/src/model/support.ts +8 -0
- package/src/model/token-groups.ts +66 -0
- package/src/model/trellis-linear.ts +4 -4
- package/src/model/turboquant-codec.ts +89 -0
- package/src/model/universal/dense.ts +14 -13
- package/src/model/whisper.ts +435 -0
- package/src/native/mic_capture.swift +92 -0
- package/src/native-pack.ts +6 -5
- package/src/pi-web.ts +9 -1
- package/src/preflight.ts +31 -15
- package/src/prompt-cache.ts +306 -86
- package/src/runtime-config.ts +1 -5
- package/src/safetensors.ts +9 -2
- package/src/sampler.ts +37 -25
- package/src/serve/audio-routes.ts +323 -0
- package/src/serve/chat-request.ts +2 -0
- package/src/serve/chat-stage.ts +19 -14
- package/src/serve/completion-executor.ts +9 -1
- package/src/serve/discovery-routes.ts +17 -1
- package/src/serve/generated-token-history.ts +57 -0
- package/src/serve/generation-gateway.ts +88 -38
- package/src/serve/model-binding.ts +7 -1
- package/src/serve/model-host.ts +3 -4
- package/src/serve/preparation.ts +3 -3
- package/src/serve/prompt-response-trace.ts +14 -0
- package/src/serve/request-plan.ts +6 -3
- package/src/serve/request-prep.ts +40 -25
- package/src/serve/text-completion-stage.ts +2 -2
- package/src/serve/transcription-server.ts +64 -0
- package/src/serve/transcription-service.ts +502 -0
- package/src/server.ts +185 -261
- package/src/spec/assistant-rows.ts +93 -0
- package/src/spec/assistant-source.ts +28 -18
- package/src/spec/cache-identity.ts +22 -0
- package/src/spec/deepspec-rows.ts +29 -0
- package/src/spec/deepspec-source.ts +12 -10
- package/src/spec/dflash-source.ts +28 -4
- package/src/spec/drafter.ts +153 -142
- package/src/spec/dspark/deepspec-module.ts +95 -120
- package/src/spec/dspark/module-dflash.ts +126 -170
- package/src/spec/glm52-mtp-graph.ts +29 -0
- package/src/spec/glm52-mtp-rows.ts +132 -0
- package/src/spec/glm52-mtp-source.ts +54 -136
- package/src/spec/glm52-mtp-state.ts +33 -0
- package/src/spec/ngram-source.ts +115 -21
- package/src/spec/projected-draft-rows.ts +73 -0
- package/src/spec/qwen-mtp-module.ts +171 -0
- package/src/spec/qwen-mtp-rows.ts +230 -0
- package/src/spec/qwen-mtp-source.ts +84 -226
- package/src/spec/qwen-mtp-state.ts +30 -0
- package/src/spec/serve-loop.ts +73 -69
- package/src/spec/source.ts +93 -15
- package/src/spec/two-model-rows.ts +62 -0
- package/src/spec/two-model.ts +45 -103
- package/src/ssd-cache.ts +107 -36
- package/src/ssd-durability.ts +29 -27
- package/src/storage/host-buffer.ts +24 -0
- package/src/storage/kv-writer.ts +83 -0
- package/src/storage/kv-writer.worker.js +264 -0
- package/src/storage/retention-policy.ts +37 -0
- package/src/tiered-prompt-cache.ts +45 -0
- package/src/vision/embedder.ts +8 -0
- package/src/vision/prompt.ts +101 -65
- package/src/vision/qwen3vl-prompt.ts +101 -64
- package/src/vision/qwen3vl-tower.ts +11 -0
- package/src/vision/siglip.ts +8 -0
- package/src/web/app.html +12 -0
- package/src/web/app.js +217 -57
- package/src/web/src/chat.ts +4 -1
- package/src/web/src/composer.ts +3 -0
- package/src/web/src/voice.ts +141 -0
- package/src/web/sw.js +1 -1
- package/src/backends/mlx/memory-guard.ts +0 -40
- package/src/spec/prefix-state.ts +0 -45
- /package/docs/{planning → archive/planning}/release-notes-v0.3.0.md +0 -0
|
@@ -177,7 +177,7 @@ refuses otherwise. GLM-5.2's checkpoint-native MTP row mounts by default
|
|
|
177
177
|
|
|
178
178
|
| kind | source | what fills the draft | target state used | draft sampler | default γ | oracle / gate |
|
|
179
179
|
|---|---|---|---|---|---|---|
|
|
180
|
-
| `two-model` | `src/spec/two-model.ts` | a full second model, autoregressive, own KV | none | request sampler | 3 (mlx_lm.server) | **L1**: mlx_lm.server `--draft-model`, same pair, greedy, token-for-token (spec-vs-spec).
|
|
180
|
+
| `two-model` | `src/spec/two-model.ts` | a full second model, autoregressive, own KV | none | request sampler | 3 (mlx_lm.server) | **L1**: mlx_lm.server `--draft-model`, same pair, greedy, token-for-token (spec-vs-spec). Shared B1/B>1 autoregressive draft state retains independent attention/recurrent boundaries and the pending final-token lag; paired RAM/SSD checkpoints use backend cache codecs. Tokenizer-family probe at startup refuses mismatches (upstream silently accepts ~0%). |
|
|
181
181
|
| `assistant` | `src/spec/assistant-source.ts` (+ `drafter.ts`) | Gemma "-assistant" Q-only 4-layer head | donor K/V (last sliding + last full layer) + anchor hidden, borrowed each step | greedy (own head) | 3 | **L2**: optiq `spec_generate` — e4b γ=2 identical 48-token output AND identical accept/reject trace (drafted 60 / accepted 17 / target calls 31), `scripts/oracle/oracle-spec.py`. Head picked by TENSOR PRESENCE (centroid vs tied-embedding) — optiq's config-based detection loads the 12B/26B unified drafters with zero-init centroids → 0% acceptance; ours 29% on the same artifact. |
|
|
182
182
|
| `dspark` | `src/spec/dflash-source.ts` (+ `dspark/module-dflash.ts`) | our trained DSpark block drafter (KV injection + Markov + confidence) | multi-layer hidden tap (`tapLayers`, e4b {20,31,41,42}) grown into H_ctx | greedy | pinned to `cfg.gamma` | **Lab** (no external oracle for our checkpoints): CPU smoke, infer-loop bit-identity pins, real-weights serve gate. See §4. |
|
|
183
183
|
| `deepspec` | `src/spec/deepspec-source.ts` (+ `dspark/deepspec-module.ts`) | DeepSeek's released `Gemma4DSparkModel` drafters (e.g. `dspark_gemma4_12b_block7`, γ=7) | tap `[5,17,29,41,46]` on the 12B, projected into an incremental context-KV cache; accepted rows only | argmax (temp-0 reference) | pinned to `block_size` | **DeepSpec reference** at temperature 0: its leaky rejection sampling degenerates to exact argmax token-match, RNG-free — round-for-round trace fixtures (`scripts/oracle/oracle-dspark-deepspec.py`; the compare script was deleted 2026-08-23, git history). |
|
|
@@ -794,23 +794,68 @@ it is separate from the already-fixed target-cache disposal and admission work.
|
|
|
794
794
|
|
|
795
795
|
### 4.8 Paired Qwen MTP conversation state
|
|
796
796
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
797
|
+
`DraftSource.checkpoint` supplies the method's companion state. Qwen captures
|
|
798
|
+
draft KV and the preceding target hidden row; the executor pairs these with
|
|
799
|
+
target KV/recurrent state and exact processed token IDs in the shared cache.
|
|
800
|
+
Restore requires an exact prefix under the same compatibility namespace.
|
|
801
|
+
RAM hits lend immutable views and preserve the donor. Reuse never trims
|
|
802
|
+
recurrent state to an arbitrary common prefix.
|
|
803
803
|
|
|
804
804
|
The MTP cache is one position behind the target at a prefill boundary. Extending
|
|
805
805
|
it first pairs the next incoming token with the saved preceding hidden row,
|
|
806
806
|
then processes the remaining suffix. Future generation cannot alter the retained
|
|
807
|
-
prefix. The
|
|
808
|
-
budget
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
807
|
+
prefix. The working-tree migration removes the provider's private store and
|
|
808
|
+
separate budget. All tensors use the existing RAM budget, eviction and SSD
|
|
809
|
+
queue. Native bf16/KV4 tests pass on M1 Max and M4 Pro through repeated RAM
|
|
810
|
+
reuse and SSD cache/provider restart. Completed generated-state publication
|
|
811
|
+
and matched performance remain open. Storage and identity details live in
|
|
812
|
+
[kv-cache method companion state](kv-cache.md#method-companion-state).
|
|
813
|
+
|
|
814
|
+
`DraftProvider.grouped` now opens method-owned row state using the same
|
|
815
|
+
companion checkpoint format. Its sampler is injected; the provider retains
|
|
816
|
+
weights while the group owns draft KV and hidden rows. Prepared requests can
|
|
817
|
+
join, retire, reorder, drain and rejoin without exposing tensor layouts to
|
|
818
|
+
scheduling or introducing another cache store. Capture and membership changes
|
|
819
|
+
occur between committed rounds. The request source and group share Qwen's
|
|
820
|
+
attachment encoding and restoration.
|
|
821
|
+
|
|
822
|
+
The provider interface is adopted in the working tree after bf16/KV4/KV8
|
|
823
|
+
full-round controls at B=1/2/4 on both Macs, including rebuilt checkpoints,
|
|
824
|
+
SSD restart continuations and both complete model-free suites. Extraction
|
|
825
|
+
removes padding, so the continuation control also rebuilds its raw state to
|
|
826
|
+
match attention geometry. The initial M4 comparison against retained padding
|
|
827
|
+
changed subsequent draft KV despite matching tokens and target state; that
|
|
828
|
+
result is retained. These are internal refactor controls. Coordinated
|
|
829
|
+
target/draft admission now uses staged state publication, described in
|
|
830
|
+
batching §7. Source
|
|
831
|
+
identity and raw checks are in the composition-baseline reports under
|
|
832
|
+
`mtp-provider-group-manifest.json`.
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
The isolated serving candidate adds method preparation and advancement to the
|
|
836
|
+
existing execution group. The scheduler retains its queue, execution lease and
|
|
837
|
+
admission policy; the method owns target/draft state, acceptance and sampling.
|
|
838
|
+
The gateway asks the binding for its supported grouped methods and forwards
|
|
839
|
+
output metadata and speculative usage. No second MTP scheduler is introduced.
|
|
840
|
+
Its real KV4 HTTP test passes on M1 Max and M4 Pro: four submitted requests
|
|
841
|
+
reach a target verification graph with shape B=4, each returns seeded samples
|
|
842
|
+
and logprobs, and the group drains. B=1 token and acceptance checks compare
|
|
843
|
+
against the existing request producer. Callback-stop, failure, cancellation,
|
|
844
|
+
EOS and shared RAM-prefix checks are included in the extended native gate.
|
|
845
|
+
Mixed HTTP checks on both Macs compose structured JSON, seeded sampling and
|
|
846
|
+
logprobs with ordinary requests in the same MTP group. Shared-method SSD
|
|
847
|
+
restart preserves target/draft state, tokens and acceptance traces on both.
|
|
848
|
+
An extended M1 native check also admits a shorter-lived request with a different
|
|
849
|
+
prompt length while another request is decoding, then repeats the same schedule
|
|
850
|
+
with matching outputs. Admission now publishes target state, draft state and
|
|
851
|
+
executor membership together before releasing superseded state. A reproduced
|
|
852
|
+
cleanup failure formerly left a rejected row active; the admission failure
|
|
853
|
+
handler now retires that row before another method round. The candidate remains
|
|
854
|
+
isolated pending complete composition and paired performance acceptance.
|
|
855
|
+
Timing results and their limits live in benchmarks.md. Evidence:
|
|
856
|
+
`reports/qwen38-closeout/composition-baseline/mtp-serving-method-manifest.json`.
|
|
857
|
+
|
|
858
|
+
For the original private-cache candidate, the M4 Pro unit gate passed 18 tests. Native prompts at 128, 513 and
|
|
814
859
|
2,051 tokens pass six restore checks with unchanged state hashes, token IDs
|
|
815
860
|
and acceptance traces; repeated allocation is stable at each length. The HTTP
|
|
816
861
|
gate completes eight responses with identical text, token counts and finish
|
|
@@ -871,12 +916,18 @@ section 7.7. Raw evidence: `reports/qwen38-rd/mtp-cache-candidate-native.json` a
|
|
|
871
916
|
|
|
872
917
|
## 6. Composition rules (as served)
|
|
873
918
|
|
|
874
|
-
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
919
|
+
- Method selection precedes placement. Qualified Qwen MTP uses grouped
|
|
920
|
+
target/draft state, sampling and checkpoint interfaces in the shared
|
|
921
|
+
executor. Other draft providers still use the serial verifier.
|
|
922
|
+
- KV policy stays with the request. Shared Qwen MTP supports bf16 and
|
|
923
|
+
start-zero uniform KV4/KV8/TurboQuant. Unsupported compositions select
|
|
924
|
+
ordinary decoding. Current defaults and qualifications live in server-config.md.
|
|
878
925
|
- Structured output composes (the constrained verify walk).
|
|
879
|
-
-
|
|
926
|
+
- Qwen MTP prefill state uses the shared RAM/SSD cache. The source supplies
|
|
927
|
+
draft KV and the pending hidden row through its checkpoint interface;
|
|
928
|
+
the cache owns retention and persistence. Other speculative sources still
|
|
929
|
+
begin with fresh state until they supply a checkpoint codec. Generated-output
|
|
930
|
+
capture remains R17 work.
|
|
880
931
|
- Native GLM MTP and an explicit `--draft-model`/`--draft-kind` are mutually
|
|
881
932
|
exclusive; one provider per request so two draft histories never advance
|
|
882
933
|
target or grammar state twice.
|
|
@@ -1009,11 +1060,12 @@ gets assert fills; verify proposals are dropped and counted
|
|
|
1009
1060
|
(`usage.fill.verifyUnsupported`). Checkpointing is real work (~48 DeltaNet
|
|
1010
1061
|
states on Qwen3.8) and is measured: `usage.fill.checkpointMs`.
|
|
1011
1062
|
|
|
1012
|
-
**
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1063
|
+
**Remaining fill integration.** Prompt lookup, Qwen MTP and standalone
|
|
1064
|
+
drafting now share the grouped method lifecycle at B1/B>1 for qualified
|
|
1065
|
+
target layouts (see batching.md). DSpark and other provider migrations remain.
|
|
1066
|
+
Unifying fill proposals with draft proposals through one apply primitive is
|
|
1067
|
+
still open; the existing fill implementation retains its cache transaction
|
|
1068
|
+
contract while that method composition is qualified.
|
|
1017
1069
|
|
|
1018
1070
|
### 7.2 The echo tier (K3c, Lab, `MLX_BUN_FILL=echo`)
|
|
1019
1071
|
|
|
@@ -1056,16 +1108,13 @@ The bar for this tier is NOT token identity (sampling never guaranteed that):
|
|
|
1056
1108
|
it is a paired A/B on task success and wall clock over mocked-replay agent
|
|
1057
1109
|
sessions. Default off until that lands.
|
|
1058
1110
|
|
|
1059
|
-
**Composition.**
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
multi-token append is L-generic but unvalidated), and sliding-window models
|
|
1067
|
-
(RotatingKVCache multi-token append is O(window) via `#updateConcat` — one
|
|
1068
|
-
warning, then no fill).
|
|
1111
|
+
**Composition.** Strict fill has serial and shared methods. Shared fill keeps
|
|
1112
|
+
request-local sampler history and absolute seeded positions while using the
|
|
1113
|
+
same preparation and encoded-row interfaces as other methods. Echo verification
|
|
1114
|
+
remains an explicit serial operation. Grammar, probability metadata, media,
|
|
1115
|
+
mounted drafting, paging and interrupted-generation checkpoints remain separate
|
|
1116
|
+
compositions. Quantized committed append is supported by the qualified model
|
|
1117
|
+
bindings described below; quantized echo verification remains inactive.
|
|
1069
1118
|
|
|
1070
1119
|
**Mismatch policy.** If `parseGeneratedToolCalls` rejects the emitted markup
|
|
1071
1120
|
on a request whose rows fired, `usage.fill.parseFallback` increments and
|
|
@@ -1363,22 +1412,30 @@ decode. The machine still fails the quiet preflight, so these are diagnostic
|
|
|
1363
1412
|
results. Both external-drive failures remain recorded separately. Evidence:
|
|
1364
1413
|
`fill-append-http-internal-repeat.json` and `fill-append-http-internal-review.json`.
|
|
1365
1414
|
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1415
|
+
The original quantized-KV append screen passed TurboQuant K8V3 after fixing
|
|
1416
|
+
retained temporary state views through `leaseCacheStates`, but affine KV4
|
|
1417
|
+
changed recurrent state after the first full-attention layer. That failure
|
|
1418
|
+
is now resolved: multi-token affine attention selected different arithmetic
|
|
1419
|
+
from one-token decode, both in tiled and ordinary unfused forms. The model's
|
|
1420
|
+
committed-append path now computes each query against its own causal KV
|
|
1421
|
+
prefix using the one-token attention operation, while retaining shared
|
|
1422
|
+
projection work. No sampled decode or ordinary prefill arithmetic changes.
|
|
1423
|
+
|
|
1424
|
+
On M4 Pro, packed and RTN4 Qwen27B both preserve complete hidden/logit/cache
|
|
1425
|
+
bytes and four subsequent continuations for KV4/KV8 at prefixes 128 and
|
|
1426
|
+
1021, including the attention boundary. The real KV4 generation loop also
|
|
1427
|
+
preserves emitted IDs, final state, subsequent logits and active allocation,
|
|
1428
|
+
with nonzero fill and zero verification. The append binding declares affine
|
|
1429
|
+
format support; HTTP preparation and placement leave that decision to the
|
|
1430
|
+
method. K8V3 TurboQuant now uses the same declaration and delayed-conversion
|
|
1431
|
+
boundary interface. Both Qwen artifacts pass real-generation state/continuation
|
|
1432
|
+
and six-pair HTTP comparisons; quantized echo verification remains separate.
|
|
1433
|
+
Full numerical and HTTP measurements live in benchmarks.md. Tests:
|
|
1434
|
+
`tests/unit/quantized-append-attention.test.ts`,
|
|
1435
|
+
`tests/parity/qwen-affine-append.test.ts`, and
|
|
1436
|
+
`MLX_BUN_TEST_FILL_KV_BITS=4` with the existing strict-fill parity test.
|
|
1437
|
+
Earlier failure/lease evidence remains `fill-append-quant-cache-review.json`
|
|
1438
|
+
and `fill-append-state-ownership-native-test.log`.
|
|
1382
1439
|
|
|
1383
1440
|
The literal/reasoning checks deliberately decline ambiguous text, including some
|
|
1384
1441
|
otherwise valid prose with unmatched quote characters. This is bounded
|
|
@@ -1548,6 +1605,451 @@ grammar/KV/batch/logprobs/seed exclusions individually after their own gates.
|
|
|
1548
1605
|
The full experimental matrix and completion rule are in
|
|
1549
1606
|
[decode-speed-program.md](decode-speed-program.md#7-qwen38-27b-research-program).
|
|
1550
1607
|
|
|
1608
|
+
#### Shared strict-fill method
|
|
1609
|
+
|
|
1610
|
+
`backends/mlx/fill-group.ts` composes `MlxPrefillCohort`, `MlxStateRows`, the
|
|
1611
|
+
model graph, the sampler and the common prompt-cache interface. The scheduler
|
|
1612
|
+
continues to select work through `MlxGroupedMethod`. It does not compile tool
|
|
1613
|
+
schemas or choose filled tokens. A request owns its `FillSession`, partial
|
|
1614
|
+
proposal and sampler history.
|
|
1615
|
+
|
|
1616
|
+
Ordinary samples retain build-next-before-read overlap. The method commits a
|
|
1617
|
+
token to sampler history only when that token becomes model input. An in-flight
|
|
1618
|
+
sample replaced by a strict continuation never enters history. Known positions
|
|
1619
|
+
skip sampling; if every next position is known, the method also omits the
|
|
1620
|
+
vocabulary projection. The model binding supplies the maximum committed chunk
|
|
1621
|
+
size for the current row geometry. When every row has a known continuation and
|
|
1622
|
+
the model permits wider chunks, the method uses the same append operation as
|
|
1623
|
+
explicit serial execution. Qualified Qwen B1 uses its specialized multi-position
|
|
1624
|
+
operation; wider rows retain one-position arithmetic and pipeline overlap.
|
|
1625
|
+
Performance parity remains a measured acceptance gate.
|
|
1626
|
+
|
|
1627
|
+
Before a row joins, the method flushes pending outputs. Retirement and
|
|
1628
|
+
cancellation settle exactly the emitted prefix of a proposal once. Cache
|
|
1629
|
+
publication uses the tokens actually consumed by the model, which can lead
|
|
1630
|
+
visible output by one pipelined position or the remaining committed span.
|
|
1631
|
+
The cache owns RAM retention and
|
|
1632
|
+
queued SSD persistence. No storage work is awaited by the method.
|
|
1633
|
+
|
|
1634
|
+
The row-aware `appendHiddenRows` interface separately accepts borrowed `[B,L]`
|
|
1635
|
+
inputs and asks the model for its maximum chunk length at the actual B. The
|
|
1636
|
+
qualified Qwen binding retains its specialized B1 append and declares one
|
|
1637
|
+
position for wider rows. Full hidden outputs, live cache bytes and subsequent
|
|
1638
|
+
logits match ordinary same-B forwards after retirement on M1 MiniCPM/Qwen0.8B
|
|
1639
|
+
and M4 packed Qwen27B with bf16, KV4 and k8v3.
|
|
1640
|
+
|
|
1641
|
+
`tests/unit/fill-group.test.ts` exercises actual shared execution, including
|
|
1642
|
+
mixed sampled/filled rows, head omission, stream stops, length limits,
|
|
1643
|
+
consumer failures, cancellation and late joins. `tests/parity/shared-fill.test.ts`
|
|
1644
|
+
compares ordinary, empty-fill and saved-continuation arms at matched B1/B2/B4
|
|
1645
|
+
with seeded sampling, presence/repetition penalties and bf16/KV4/k8v3. All
|
|
1646
|
+
nine cases pass on M1 MiniCPM, Qwen0.8B and Gemma4-e4b and M4 packed Qwen27B.
|
|
1647
|
+
Gemma's sliding layers remain bf16 in the TurboQuant arm.
|
|
1648
|
+
|
|
1649
|
+
The M4 delayed-conversion gate caught two composition defects. Shared row
|
|
1650
|
+
layouts did not expose their pending precision boundary to committed append;
|
|
1651
|
+
the affine attention view also bypassed the model's single-position reduction
|
|
1652
|
+
policy. The cache now publishes `maxAppendTokens()` from logical row offsets,
|
|
1653
|
+
including padding and retirement, and the attention view carries the qualified
|
|
1654
|
+
committed-position policy to its codec. Both delayed KV4 and k8v3 seeded cases
|
|
1655
|
+
pass after splitting the five-token span into two and three positions at the
|
|
1656
|
+
boundary. Separate B1 full-hidden/cache-byte/continuation comparisons pass for
|
|
1657
|
+
bf16, KV4, k8v3 and both delayed formats. Earlier failed logs are retained.
|
|
1658
|
+
|
|
1659
|
+
The first unequal-prompt comparison did not fix the admission geometry and
|
|
1660
|
+
produced different later tokens; preserve it as an unmatched experiment.
|
|
1661
|
+
A later fixture reused a short suffix which recurred during stochastic
|
|
1662
|
+
sampling and wrongly supplied the same continuation twice. The numerical
|
|
1663
|
+
gate now supplies a saved span at one exact position. Parser/source validity
|
|
1664
|
+
has its own tests; numerical replay does not prove arbitrary suffix asserts.
|
|
1665
|
+
The failed logs and corrected runs remain in `reports/prefill-observation/`.
|
|
1666
|
+
Serving binding tests also cover seeded placement and `usage.fill` propagation.
|
|
1667
|
+
The six-arm M4 HTTP comparison preserves all 108 responses and all paired token/cache counts, with six durable SSD restarts. Sequential shared strict-fill performance matches serial within 0.13%; the fill-off comparison and concurrent latency tradeoffs are recorded in benchmarks.md. Model-declared codec eligibility is resolved once at binding: unsupported multi-position formats still use shared one-position fill. A separate k4v3 seeded gate proves that execution with no specialized append.
|
|
1668
|
+
|
|
1669
|
+
#### Shared echo verification
|
|
1670
|
+
|
|
1671
|
+
The fill method accepts both asserted and verified proposals. A pending
|
|
1672
|
+
sample checks the first echo token without replacing the sampler's choice.
|
|
1673
|
+
When a live row has a verified echo continuation, the method supplies
|
|
1674
|
+
its proposal to `advanceSpeculativeOutputs`, the same grouped target
|
|
1675
|
+
verification and output-aligned rollback operation used by speculative
|
|
1676
|
+
providers. Ordinary rows join with empty proposals and retain only their
|
|
1677
|
+
consumed inputs. Asserted spans keep their append policy. Proposals discovered
|
|
1678
|
+
while publishing pending output stay within the scheduler's declared token
|
|
1679
|
+
work; any remainder belongs to the request's next iteration.
|
|
1680
|
+
No scheduler or storage branch chooses echo tokens.
|
|
1681
|
+
|
|
1682
|
+
Each request retains its own seed and processor history. The sampler adapter
|
|
1683
|
+
commits a token when it becomes model input; rejected proposals never enter
|
|
1684
|
+
that history. Eligible plain-greedy rows use the sampler's existing independent
|
|
1685
|
+
verification kernel. Output delivery determines how much state survives a consumer
|
|
1686
|
+
stop, then the common cache receives the corresponding tokens and row state.
|
|
1687
|
+
The cache retains RAM donors and owns SSD persistence. Checkpoint telemetry
|
|
1688
|
+
includes the shared cohort's begin and resolve time for each participating
|
|
1689
|
+
request. Fill remains opt-in. Shared paged execution is unsupported. Qwen MTP can
|
|
1690
|
+
consume verified echo continuations through the provider operation below.
|
|
1691
|
+
|
|
1692
|
+
`shared-echo.test.ts` audits the real sampler against an independent sampler
|
|
1693
|
+
on the exact same score tensor and selected-token history, across B1/B2/B4,
|
|
1694
|
+
bf16, KV4, k8v3 and delayed quantization. It covers accepted, first-rejected,
|
|
1695
|
+
partially rejected, mixed and staggered proposals plus a consumer stopping inside
|
|
1696
|
+
the span. Published cache keys must match emitted history and every layer offset.
|
|
1697
|
+
B2 retained state also survives SSD store/reopen with identical state and two
|
|
1698
|
+
subsequent logit vectors against its RAM clone. These checks pass on M1
|
|
1699
|
+
Qwen0.8B/Gemma-e4b and M4 packed Qwen27B. HTTP tests cover actual copied tool arguments,
|
|
1700
|
+
seeded concurrent requests, follow-up reuse and durable SSD restart.
|
|
1701
|
+
|
|
1702
|
+
An early experiment compared multi-position verification against one-position
|
|
1703
|
+
ordinary decoding and found changed sampled tokens. That comparison changes
|
|
1704
|
+
numerical geometry and is preserved as an unmatched experiment, not an exact
|
|
1705
|
+
oracle. The original strict-fill exact replay gate remains unchanged. Echo
|
|
1706
|
+
acceptance preserves the sampler's decision for the verified logits; it does
|
|
1707
|
+
not promise identical text to a different forward shape. Request timing and
|
|
1708
|
+
paired-response results are recorded in benchmarks.md.
|
|
1709
|
+
|
|
1710
|
+
#### Echo with a mounted MTP provider
|
|
1711
|
+
|
|
1712
|
+
`DraftRowGroup.consume` consumes externally verified target tokens and hidden
|
|
1713
|
+
context, retaining the specified prefix length for each row. Provider
|
|
1714
|
+
capabilities advertise this operation before execution. The Qwen MTP provider
|
|
1715
|
+
uses its existing true-hidden prefill graph and per-row rollback; it neither
|
|
1716
|
+
samples draft tokens nor projects its vocabulary during this operation.
|
|
1717
|
+
|
|
1718
|
+
The speculative method first compares ordinary MTP output with a pending copy
|
|
1719
|
+
proposal. A first-token mismatch uses no additional target forward. Once output
|
|
1720
|
+
establishes a matching prefix, the method verifies the remaining copied span.
|
|
1721
|
+
Other rows supply empty proposals. The existing verifier and
|
|
1722
|
+
sampler select output, then output delivery determines how many inputs survive.
|
|
1723
|
+
The provider consumes that same prefix before ordinary MTP resumes. Target and
|
|
1724
|
+
companion state are published together through the unchanged cache interface.
|
|
1725
|
+
No scheduling or storage implementation selects between echo and MTP.
|
|
1726
|
+
|
|
1727
|
+
`FillSession.observe` records sampled output independently of proposal timing.
|
|
1728
|
+
The method asks for verified proposals at committed output boundaries. Under
|
|
1729
|
+
MTP, asserted template spans remain ordinary sampled output; this combination
|
|
1730
|
+
adds echo without changing the strict append algorithm. Grammar, probability
|
|
1731
|
+
metadata, media, paging and providers without external-token consumption remain
|
|
1732
|
+
outside this combination's serving coverage.
|
|
1733
|
+
|
|
1734
|
+
`usage.fill` counts verified echo proposals. Learned-provider drafted/accepted
|
|
1735
|
+
counts, rounds and acceptance histograms exclude echo. Target calls and tokens
|
|
1736
|
+
per forward cover both kinds of round. A request can legitimately use no
|
|
1737
|
+
learned drafts if echo supplies every continuation. Both-machine companion
|
|
1738
|
+
oracle checks cover external prefixes and subsequent full decoder output;
|
|
1739
|
+
shared tests cover sampling, mixed rows, rejection, stop and paired SSD state.
|
|
1740
|
+
|
|
1741
|
+
|
|
1742
|
+
### 7.5 Logical jump-ahead prefill
|
|
1743
|
+
|
|
1744
|
+
Proposal by Josh Rossi, recorded 2026-09-08. Research proposal, not an
|
|
1745
|
+
implemented semantic intervention or a measured task-time improvement.
|
|
1746
|
+
This is the canonical write-up and proposed preprint question. The existing
|
|
1747
|
+
fixed-serialization implementation is described in §7.4. The broader
|
|
1748
|
+
proposal deliberately permits a different continuation.
|
|
1749
|
+
|
|
1750
|
+
The governing [product objective](../planning/PRODUCT_ROADMAP.md#product-north-star),
|
|
1751
|
+
in Josh's words, is "The absolute BEST local AI experience on a mac". It
|
|
1752
|
+
covers the entire project, including simple installation, direct application
|
|
1753
|
+
integration and JavaScript/TypeScript development. A preprint is optional.
|
|
1754
|
+
This research serves that objective by finishing tasks sooner, producing
|
|
1755
|
+
better results, or making a more capable model practical on the same hardware.
|
|
1756
|
+
A hypothetical 30% reduction in task completion time would be a meaningful
|
|
1757
|
+
product improvement, not a measured result of this proposal. Evaluate the
|
|
1758
|
+
complete experience, including quality, reliability, latency and memory,
|
|
1759
|
+
rather than treating a token-rate increase or a publication as the goal.
|
|
1760
|
+
|
|
1761
|
+
The model often spends time deciding what to do, writes relevant content
|
|
1762
|
+
in its reasoning, and then generates that content again inside a tool call.
|
|
1763
|
+
Josh proposes letting the runtime recognize the intended action, construct
|
|
1764
|
+
some or all of its tool-call representation, and append it through prefill.
|
|
1765
|
+
The model continues from the supplied history and actual tool result.
|
|
1766
|
+
The runtime does not ask the target model to verify that it would have
|
|
1767
|
+
sampled each supplied token.
|
|
1768
|
+
|
|
1769
|
+
The research question has two parts:
|
|
1770
|
+
|
|
1771
|
+
1. With perfect knowledge of an eligible continuation, how much decode time
|
|
1772
|
+
can be replaced by cheaper prefill and construction work?
|
|
1773
|
+
2. With an imperfect predictor, how often can the model recover from an
|
|
1774
|
+
unsuitable intervention, and what does that recovery cost?
|
|
1775
|
+
|
|
1776
|
+
The deciding quantity is time saved by logical jump-ahead prefill minus time
|
|
1777
|
+
spent on recovery, with intervention overhead included and task quality held
|
|
1778
|
+
to an independently evaluated standard. Prediction errors do not by
|
|
1779
|
+
themselves rule out a useful speedup. Their consequences determine the cost.
|
|
1780
|
+
|
|
1781
|
+
#### Context management is the broader premise
|
|
1782
|
+
|
|
1783
|
+
Josh's framing is that working with LLMs is largely context management.
|
|
1784
|
+
For the local inference system under our control, the runtime owns every
|
|
1785
|
+
token supplied to the model. At each generation step, the abstraction is
|
|
1786
|
+
`token sequence in -> next-token distribution -> sampled token`.
|
|
1787
|
+
The KV and recurrent caches are computed representations of that history,
|
|
1788
|
+
not an independent record of the path the model might have taken.
|
|
1789
|
+
|
|
1790
|
+
The runtime can construct, insert, replace, summarize or remove context.
|
|
1791
|
+
It can choose what the model needs to decide and what software can supply.
|
|
1792
|
+
The full original transcript need not remain the active inference context.
|
|
1793
|
+
It can remain in the audit log while a different sequence drives the next
|
|
1794
|
+
step. The resulting sequence still must be processed consistently by the
|
|
1795
|
+
model and preserve enough information for the task.
|
|
1796
|
+
|
|
1797
|
+
Logical jump-ahead prefill and micro-compaction are two applications of this
|
|
1798
|
+
control. One supplies a continuation before it is redundantly generated.
|
|
1799
|
+
The other retires or rewrites material after its immediate purpose is served.
|
|
1800
|
+
Both should be judged by successful task completion, elapsed time and the
|
|
1801
|
+
cost of recovering from an inadequate context decision.
|
|
1802
|
+
|
|
1803
|
+
#### Mechanism and example
|
|
1804
|
+
|
|
1805
|
+
Suppose the reasoning contains a settled instruction to write `hello.txt`
|
|
1806
|
+
with the contents `hello, world!`. The normal path generates a tool name,
|
|
1807
|
+
argument names, path and escaped contents. The proposed path constructs that
|
|
1808
|
+
representation from the available trace, appends it as assistant tool-call
|
|
1809
|
+
content, and executes the call through the normal tool dispatcher.
|
|
1810
|
+
|
|
1811
|
+
An intervention consists of:
|
|
1812
|
+
|
|
1813
|
+
1. Detect an eligible boundary using only context available at that moment.
|
|
1814
|
+
2. Select an action or source span and construct the continuation, including
|
|
1815
|
+
required escaping and protocol delimiters.
|
|
1816
|
+
3. Append the supplied tokens through the model's state-update path, then
|
|
1817
|
+
resume generation at the next unresolved choice or dispatch a complete call.
|
|
1818
|
+
4. Return the actual tool outcome and allow the model to continue, including
|
|
1819
|
+
correcting an unsuitable action when needed.
|
|
1820
|
+
|
|
1821
|
+
The state update still runs model forward computation. Attention KV,
|
|
1822
|
+
recurrent state, positions and parser state must describe the new sequence.
|
|
1823
|
+
It saves sequential token decisions and can avoid intermediate vocabulary
|
|
1824
|
+
projections and verification work. Copying text from an earlier position
|
|
1825
|
+
does not generally permit copying that position's KV, because its context
|
|
1826
|
+
and position differ. Editing an existing prefix also requires invalidating
|
|
1827
|
+
and recomputing affected state. Appending at the current boundary is the
|
|
1828
|
+
smallest implementation to study.
|
|
1829
|
+
|
|
1830
|
+
There is no hidden record of the alternate tokens the model would have
|
|
1831
|
+
sampled. Given consistent state for the supplied prefix, subsequent decoding
|
|
1832
|
+
conditions on that prefix. This does not imply that every supplied action is
|
|
1833
|
+
appropriate or that the model always recovers. Those are empirical questions.
|
|
1834
|
+
|
|
1835
|
+
#### Perfect prediction and imperfect recovery
|
|
1836
|
+
|
|
1837
|
+
Perfect prediction supplies an upper-bound experiment. Replacing a known
|
|
1838
|
+
span's serial generation with a cheaper append saves time. Span size,
|
|
1839
|
+
context length, kernel behavior and construction overhead determine the
|
|
1840
|
+
amount. Very short spans can cost more to detect and append than to decode.
|
|
1841
|
+
|
|
1842
|
+
For the oracle experiment, use the saved future continuation to choose the
|
|
1843
|
+
span, while requiring the copied source content to exist before the jump.
|
|
1844
|
+
This deliberately uses hindsight to measure opportunity. It is not evidence
|
|
1845
|
+
that an online detector can identify those opportunities. An online policy
|
|
1846
|
+
must receive only the prefix available at the intervention boundary.
|
|
1847
|
+
|
|
1848
|
+
With an imperfect policy, an action may still satisfy the task even when it
|
|
1849
|
+
differs from the saved continuation. Another action may require correction.
|
|
1850
|
+
For example, the runtime supplies `ls` in an unsuitable working directory.
|
|
1851
|
+
The returned listing fails to answer the model's question, so the model
|
|
1852
|
+
changes directory or asks for a different listing. The extra reasoning,
|
|
1853
|
+
request prefill, tool calls and tool execution count as recovery cost.
|
|
1854
|
+
|
|
1855
|
+
Record errors the model fails to notice, persistent loops and unsuccessful
|
|
1856
|
+
tasks too. Recovery is possible, not guaranteed. A retry alone is not proof
|
|
1857
|
+
of recovery; the task must regain useful progress and ultimately meet its
|
|
1858
|
+
acceptance criteria. Identical sampled tokens are not required for success.
|
|
1859
|
+
|
|
1860
|
+
#### Cost model
|
|
1861
|
+
|
|
1862
|
+
For an intervention, define:
|
|
1863
|
+
|
|
1864
|
+
| Symbol | Cost |
|
|
1865
|
+
|---|---|
|
|
1866
|
+
| `D` | Serial decode time avoided for the replaced span |
|
|
1867
|
+
| `P` | Time to prefill the supplied continuation and resume |
|
|
1868
|
+
| `H` | Detection, selection, serialization and other intervention overhead |
|
|
1869
|
+
| `R` | Additional downstream time caused by correction or other consequences |
|
|
1870
|
+
|
|
1871
|
+
The local accounting model is:
|
|
1872
|
+
|
|
1873
|
+
```text
|
|
1874
|
+
net saving = D - P - H - R
|
|
1875
|
+
```
|
|
1876
|
+
|
|
1877
|
+
If a fraction `q` of interventions require recovery, and their mean added
|
|
1878
|
+
cost is `C`, a simplified expectation is:
|
|
1879
|
+
|
|
1880
|
+
```text
|
|
1881
|
+
expected net saving = E[D - P - H] - q * C
|
|
1882
|
+
break-even recovery frequency = E[D - P - H] / C
|
|
1883
|
+
```
|
|
1884
|
+
|
|
1885
|
+
The break-even expression assumes positive `C`, successful eventual recovery
|
|
1886
|
+
and no other downstream differences. Here `q` measures harmful interventions
|
|
1887
|
+
requiring recovery, not disagreement with a hypothetical sampled string.
|
|
1888
|
+
Span length, uncertainty and recovery cost may be correlated; measure their
|
|
1889
|
+
joint behavior rather than multiplying unrelated averages.
|
|
1890
|
+
|
|
1891
|
+
This decomposition explains the mechanism. The authoritative measurement is
|
|
1892
|
+
complete task wall time against a paired baseline. A changed trajectory can
|
|
1893
|
+
alter later reasoning, tool latency, cache reuse and compaction. Those effects
|
|
1894
|
+
belong in the result even when they cannot be assigned to one jump. Do not
|
|
1895
|
+
double-count overlapping spans or add savings from dependent interventions
|
|
1896
|
+
as if each occurred in the original unmodified run.
|
|
1897
|
+
|
|
1898
|
+
#### Evidence and first experiment
|
|
1899
|
+
|
|
1900
|
+
The completed Kanban trace supplies a workload and an offline opportunity
|
|
1901
|
+
analysis. Generation-to-generation duplicate coverage and the narrower
|
|
1902
|
+
reasoning-to-tool coverage are recorded in the
|
|
1903
|
+
[completed Kanban benchmark](../reference/benchmarks.md#completed-fresh-pi-kanban-with-bounded-range-cache-m4-pro-2026-09-08).
|
|
1904
|
+
Those counts retain first occurrences, merge overlapping later positions and
|
|
1905
|
+
exclude replayed request history. They use retokenized payloads rather than
|
|
1906
|
+
the original sampled token stream, so they are opportunity estimates.
|
|
1907
|
+
The longest whole-file repeat was a write followed by a read. It does not
|
|
1908
|
+
establish that the model first wrote that whole file in reasoning.
|
|
1909
|
+
|
|
1910
|
+
Start with these experiment arms:
|
|
1911
|
+
|
|
1912
|
+
| Arm | Purpose |
|
|
1913
|
+
|---|---|
|
|
1914
|
+
| Ordinary decoding | Establish task success, timing and natural retry behavior |
|
|
1915
|
+
| Existing strict fill | Isolate savings from fixed serialization already supported |
|
|
1916
|
+
| Oracle content jumps | Estimate savings with hindsight and no selection mistakes |
|
|
1917
|
+
| Online logical jumps | Measure an implementable policy using only the current prefix |
|
|
1918
|
+
| Controlled mistaken jumps | Measure detection, recovery and failure under known perturbations |
|
|
1919
|
+
|
|
1920
|
+
For the online arm, begin with complete literal content already in the trace
|
|
1921
|
+
and a partially generated tool call that identifies the destination. This
|
|
1922
|
+
reduces the decisions the runtime must infer. Then evaluate earlier action
|
|
1923
|
+
selection as a separate policy. Track changes in opportunity coverage and
|
|
1924
|
+
recovery cost as the policy becomes more permissive.
|
|
1925
|
+
|
|
1926
|
+
Use fresh workspaces and matched prompts, models, quantization, tool access,
|
|
1927
|
+
context limits and hardware conditions. Preserve the same cache and decoding
|
|
1928
|
+
configuration across arms where supported. The Kanban configuration and
|
|
1929
|
+
strict fill currently have composition restrictions; establish a supported
|
|
1930
|
+
common control before attributing a difference to logical jumps. Keep the
|
|
1931
|
+
separate MLX-LM comparison as a reference experiment, not a substitute for
|
|
1932
|
+
this within-engine ablation.
|
|
1933
|
+
|
|
1934
|
+
Record supplied and sampled tokens separately, source-span provenance,
|
|
1935
|
+
intervention boundaries, append cost, selection cost, tool outcomes, extra
|
|
1936
|
+
turns, recovery time, compactions and complete task time. Keep raw generated
|
|
1937
|
+
text and supplied text distinguishable in the audit log, while making the
|
|
1938
|
+
model-visible history consistent with the action actually executed.
|
|
1939
|
+
|
|
1940
|
+
Repeat paired runs over multiple tasks and sampling trials. A matching seed
|
|
1941
|
+
does not preserve the trajectory after an intervention. Evaluate artifacts
|
|
1942
|
+
with independent task checks. Report success rate and the distribution of
|
|
1943
|
+
task times, including slow recoveries, timeouts and failures. Fast failed
|
|
1944
|
+
runs must not improve the reported time-to-success result. Where retries
|
|
1945
|
+
are allowed, include their cost under a predefined retry budget.
|
|
1946
|
+
|
|
1947
|
+
#### Micro-compaction after tool execution
|
|
1948
|
+
|
|
1949
|
+
Josh proposes replacing a long reasoning segment after its associated tool
|
|
1950
|
+
calls have completed. For example, the model may spend roughly 50,000 tokens
|
|
1951
|
+
planning and drafting, then write files and inspect the results. At that
|
|
1952
|
+
boundary, the runtime could replace the reasoning with a concise account of
|
|
1953
|
+
decisions, completed actions, observed results and unresolved work.
|
|
1954
|
+
|
|
1955
|
+
This is selective compaction at a task boundary. It need not wait until the
|
|
1956
|
+
whole context window approaches its limit. A candidate procedure is:
|
|
1957
|
+
|
|
1958
|
+
1. Identify the reasoning segment whose associated actions have completed.
|
|
1959
|
+
2. Preserve current requirements, decisions that still constrain the work,
|
|
1960
|
+
observed failures and pending questions in a compact replacement.
|
|
1961
|
+
3. Retain the relevant tool-call/result pairs and references to written
|
|
1962
|
+
artifacts. Keep the original trace available outside the active context.
|
|
1963
|
+
4. Build the revised token sequence, recompute affected model state, and
|
|
1964
|
+
continue the task from that sequence.
|
|
1965
|
+
|
|
1966
|
+
The replacement may come from a model-generated summary or deterministic
|
|
1967
|
+
extraction of completed actions and results. Compare these methods rather
|
|
1968
|
+
than assuming another long generation is necessary. A successful file write
|
|
1969
|
+
provides an artifact the model can read again; whether that makes the full
|
|
1970
|
+
earlier draft disposable depends on the remaining task. Missing rationale
|
|
1971
|
+
or a discarded constraint can require recovery even when the file survives.
|
|
1972
|
+
|
|
1973
|
+
Removing earlier tokens changes the context for retained later tokens.
|
|
1974
|
+
Ordinary prefix caching can preserve the unchanged prefix, but it cannot
|
|
1975
|
+
generally reuse the old suffix state as if the removed reasoning were still
|
|
1976
|
+
present. Recompute that suffix under the new history. Any method that keeps
|
|
1977
|
+
stale state intentionally is a separate approximation to evaluate.
|
|
1978
|
+
|
|
1979
|
+
Micro-compaction cannot recover the time already spent generating the long
|
|
1980
|
+
reasoning segment. It can reduce later context-processing work and memory
|
|
1981
|
+
use, and may change subsequent generation or avoid a larger compaction.
|
|
1982
|
+
Measure those effects over the remaining task:
|
|
1983
|
+
|
|
1984
|
+
```text
|
|
1985
|
+
net saving = future context-processing and trajectory savings
|
|
1986
|
+
- summary/extraction cost
|
|
1987
|
+
- state-rebuild and management cost
|
|
1988
|
+
- extra recovery cost
|
|
1989
|
+
```
|
|
1990
|
+
|
|
1991
|
+
Because a warm prefix cache already avoids much repeated prefill, removed
|
|
1992
|
+
token counts alone do not establish savings. Context length can still affect
|
|
1993
|
+
subsequent attention work and capacity. Record actual cache reuse, rebuild
|
|
1994
|
+
time, memory, later decode time and rereads caused by missing information.
|
|
1995
|
+
|
|
1996
|
+
Compare the existing compaction policy, post-tool micro-compaction,
|
|
1997
|
+
jump-ahead alone, and their combination. Use the same task checks and failure
|
|
1998
|
+
accounting as the jump experiment. Their gains need not add: removing a
|
|
1999
|
+
reasoning segment also removes a potential source for later content copying.
|
|
2000
|
+
An external source store could retain it, with retrieval cost included.
|
|
2001
|
+
|
|
2002
|
+
#### Related work and the proposed preprint
|
|
2003
|
+
|
|
2004
|
+
Josh identified the connection to structured output and grammars at the
|
|
2005
|
+
outset. [XGrammar](https://github.com/mlc-ai/xgrammar) implements efficient
|
|
2006
|
+
grammar-constrained generation. SGLang's
|
|
2007
|
+
[jump-forward decoding](https://www.lmsys.org/blog/2024-02-05-compressed-fsm/)
|
|
2008
|
+
directly prefills strings fixed by a grammar until the next branch. These
|
|
2009
|
+
are established relatives of fixed-serialization fill.
|
|
2010
|
+
|
|
2011
|
+
[Copy-as-Decode](https://arxiv.org/abs/2604.18170), an April 2026 preprint,
|
|
2012
|
+
is direct prior art for unverified content prefill. The model emits an
|
|
2013
|
+
explicit instruction selecting input line ranges, then the runtime prefills
|
|
2014
|
+
their contents without probabilistic verification. It studies an oracle
|
|
2015
|
+
savings bound and span-selection errors. Editing belongs within this
|
|
2016
|
+
proposal's scope, including when edits are tool calls; the application label
|
|
2017
|
+
does not establish a separate invention. The relevant difference to study
|
|
2018
|
+
is runtime inference from reasoning or a partial call versus an explicit
|
|
2019
|
+
model-selected copy instruction, and the cost of subsequent agent recovery.
|
|
2020
|
+
The paper does not establish agentic multi-file coverage.
|
|
2021
|
+
|
|
2022
|
+
Harness intervention is also established. AI SDK supports
|
|
2023
|
+
[custom tool-call repair](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling#tool-call-repair),
|
|
2024
|
+
Pydantic AI exposes
|
|
2025
|
+
[JSON and argument modification hooks](https://github.com/pydantic/pydantic-ai/blob/main/docs/capabilities/custom.md),
|
|
2026
|
+
and OpenClaw can
|
|
2027
|
+
[insert loop warnings and block repeated calls](https://docs.openclaw.ai/tools/loop-detection).
|
|
2028
|
+
These show that an agent system can alter actions or subsequent context
|
|
2029
|
+
outside the sampler. They do not measure this proposal's speedup.
|
|
2030
|
+
|
|
2031
|
+
Exact [speculative sampling](https://proceedings.mlr.press/v202/leviathan23a.html)
|
|
2032
|
+
preserves the target distribution conditional on a given context and sampling
|
|
2033
|
+
policy. Logical jumps choose supplied context without that requirement.
|
|
2034
|
+
An exact speculative decoder could still accelerate free generation between
|
|
2035
|
+
jumps.
|
|
2036
|
+
|
|
2037
|
+
The search so far has not identified a direct demonstration of runtime
|
|
2038
|
+
inference of a tool continuation from current reasoning, unverified prefill
|
|
2039
|
+
of that continuation, and whole-agent evaluation of savings against recovery
|
|
2040
|
+
cost. This is a bounded search finding, not a priority claim or proof of
|
|
2041
|
+
absence. The broader unverified-copy mechanism already has overlapping work.
|
|
2042
|
+
|
|
2043
|
+
A working preprint title is **Logical jump-ahead prefill: trading redundant
|
|
2044
|
+
agent decoding for recovery cost**. The contribution to pursue is a defined
|
|
2045
|
+
intervention mechanism, an oracle opportunity bound, an online policy, and a
|
|
2046
|
+
measured relationship between saved decode time and recovery cost at retained
|
|
2047
|
+
task quality. A negative or workload-dependent result would still answer the
|
|
2048
|
+
question. The current trace analysis motivates that study; it does not yet
|
|
2049
|
+
establish the paper's performance result. A broader literature review and
|
|
2050
|
+
the controlled experiments above remain necessary before claiming novelty
|
|
2051
|
+
or a practical speedup.
|
|
2052
|
+
|
|
1551
2053
|
## 8. Open items
|
|
1552
2054
|
|
|
1553
2055
|
- K3 (fill): the packed 27B positive-fill token-identity fixture passes;
|