Repository navigation
feat(models): add prompt-cache snapshots for qwen4_exp - #2911
Merged
Merged
Conversation
Qwen3.8-Flash-Next re-read its whole history on every turn because it implemented no snapshot hooks. The family now snapshots all per-sequence state for the exact-prefix store: GatedDeltaNet state, PLE window and n-gram contexts, KV and the QSA index. Restore validates family, layer count, layer kind, shapes and KV mode with named errors. A capture whose attention offset differs from the claimed token length is refused, restores start with an empty rollback log, and sequences with image or video MRoPE state decline the snapshot. Snapshot sizing counts the family's state, and growth of the snapshot store now re-checks the macOS memory reserve (#2883 step 4). Refs #2885
A snapshot with a token length but no GatedDeltaNet state or PLE window would have restored as a silently reset sequence; it now fails with a named error. Also move the snapshot-growth gate above the doc comment it had split from `whole_prompt_reuse_cap` and correct the memory doc, which still said no prompt-cache store is gated. Refs #2885
inureyes
marked this pull request as ready for review
November 9, 2026 18:08
inureyes
added a commit
that referenced
this pull request
Nov 10, 2026
## Summary Records the timing and memory measurements that #2908, #2906, #2912, #2909, #2911 and #2918 deferred to a quiet host, in `docs/benchmark_results/qwen4-exp-deferred-measurements-m3ultra-2026-11-10.md` (Mac Studio M3 Ultra, 512 GB, `main` @ `60a3270c`). - Native MTP (#2880, #2917): 1.30x / 1.10x / 1.76x (code / prose / enumeration) for the OptiQ 2-bit target with the bf16 split head, 1.38x / 1.00x / 1.74x for the 4-bit target with its embedded head. - SSD expert streaming (#2882): decode 42.8 tok/s resident, 23.0 at a 24 GB arena (89.8% hit), 18.3 at 8 GB (74.9% hit). Router sync costs 8.0 s per run at both sizes, more than the I/O wait. Output identical across arms. - External PLE (#2881): 31 GB less resident (78.5 to 47.3 GB), same TTFT at 4K and 32K, identical output in every mode. - Prompt-cache second turn (#2885): 0.51 to 0.60 s cached vs 15.1 s (16K) and 28.6 to 28.9 s (32K) after a reset, byte-identical in 10/10 repetitions. - macOS memory soak (#2883): 0 compressions and 0 swap-outs in every setting. A 512 GB host cannot show the eviction the issue targets. ## Script changes - `scripts/bench_speculative.sh`: new `flashnext` and `flashnext4` pairings. - `scripts/macos_memory_soak.sh`: send the `model` field (every request got HTTP 400 without it), and default `--out` gets a `-wire-weights` suffix under `--wire-weights` so it no longer overwrites the plain run. ## Not covered A Mac with less memory than the checkpoint, the `prepare-expert-stream` contiguous file, and streaming combined with the external PLE table. Refs #2880, #2881, #2882, #2883, #2885, #2917
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part A of #2885. Part B (mid-prompt checkpoints) is not implemented here; the issue scopes it to later PRs, so this PR only refs the issue.
qwen4_expnow implements the snapshot hooks. A snapshot holds the GatedDeltaNet state, PLE window and n-gram contexts, KV and the QSA index, at stored dtypes, and never the n-gram row table, so resident and external stores restore alike. Restore fails with a named error on a foreign family, layer count or kind, shape, or KV mode.Decisions:
Validation
mlxcel-server: a second turn restored 4327/4363 tokens (/v1/cache/statssnapshot hit). A repeated request hit at its history boundary (4327/4332) and all 256 greedy tokens matched the cache-reset run.Differences from the acceptance criteria
--prefill-chunk-size, but the history segment is always one uncut forward, so that control did not vary the partition. This matches the partition class indocs/CONTINUOUS_BATCHING.md; it was not separately proven to be rounding alone.Not verified: the 16K and 32K TTFT benchmarks (deferred, shared host), real external-table restore (a delegating test store stands in), and the workspace test suite. Part B criteria are not started.
Known limits: the growth gate charges a whole entry even when the insert replaces or supersedes one, so under memory pressure a turn's update can be refused and later turns reuse less; refusals appear in logs, not in
/v1/cache/stats.Measured on the OptiQ checkpoint: 240 MB per snapshot at 4327 tokens, store capacity 2.10 GB, estimate within 0.4%.
Refs #2885