Skip to content

fix: preserve prefixes when checkpoint cannot fit - #74

Closed
sanjaibalajee wants to merge 1 commit into
ashhart:mainfrom
sanjaibalajee:fix/preserve-checkpoints-on-admission
Closed

sanjaibalajee wants to merge 1 commit into
ashhart:mainfrom
sanjaibalajee:fix/preserve-checkpoints-on-admission

Conversation

@sanjaibalajee

Copy link
Copy Markdown
Contributor

Summary

  • Check whether a checkpoint copy or snapshot load can fit even after reclaiming all eligible MLX cache and retained prefixes. If it cannot, decline it before evicting useful prefixes.
  • Keep the existing reclaim path for copies that can fit.
  • Clarify that a larger explicit context can serve a request without enough memory to retain its prompt for a later turn.

Validation

  • pytest tests/test_prompt_memory.py tests/test_resume_memory.py tests/test_checkpoint_memory.py: 46 passed.
  • Ruff E/F checks passed (excluding existing E501 line-length violations).
  • Adjacent memory-budget/spill tests: 46 passed, 3 failed; the same three failures reproduce on pristine upstream on this 8 GiB host because their mocked expectations assume 12/64 GiB host memory.

Refs #71 (the checkpoint-admission safeguard; this does not claim to resolve the full context-sizing issue).

@sanjaibalajee

Copy link
Copy Markdown
Contributor Author

@ashhart Could you review this checkpoint-admission safeguard when you have a chance? It addresses suggestion 3 in #71: impossible copies now leave existing retained prefixes intact, with regression tests for both checkpoint copies and snapshot loads. The focused suite passed 46/46.

ashhart added a commit that referenced this pull request Sep 29, 2026
…DA, expert-aligned prompt tiles

- Checkpoint copies and snapshot loads check again before every eviction, and a resumed prompt stops holding the
  stored prefix it copied; the memory tests pin host RAM, so they pass on any Mac (#74).
- #70's 64 GB M5 Pro measurements go into the README and recipes, labelled as 0.3.5.1.
- On M1-M4, Flash Next's prompt expert gathers take row tiles that never straddle experts (the scheduling idea of
  ml-explore/mlx#4567), same bits.
- A reader for ModelOpt and compressed-tensors NVFP4, FP8 and MXFP8 weights, W4A16 and W8A16 lane matmuls with exact
  weights, and Qwen3.8-27B on ModelOpt NVFP4 checkpoints.

Fixes #70.
@ashhart

ashhart commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Thanks @sanjaibalajee. This is in 0.3.6.3 with your commit under your name (af9639f8, with your GitHub noreply address).

Three changes of ours sit on top, in f9255598. The first pins host RAM in the tests you saw fail on
your 8 GiB Mac. I found four that read the host's memory through the budget code: the two serve cases, the
fitted-window banner and the refusal ceiling (the banner test failed at 64 GiB too). They now use the 128 GiB their
stubbed device_info describes and pass with RAM faked at 8, 12, 64 and 512 GiB.

The second runs your check before every eviction instead of once, against measured memory, so an eviction that
frees less than its entry's size stops the loop. 16 new test cases cover both paths, the checkpoint copy and the
snapshot load: exactly at the budget, freed MLX buffers going before any prefix, a feasible copy evicting only the
oldest prefixes it needs, an impossible one keeping every prefix and freed buffer, no store and an empty store, an
eviction that frees nothing, and the store budget refusing first.

The third came from running yours on a growing conversation. The scheduler held the prefix a turn resumed from
until that turn's prefill ended, so your check counted it as freeable when evicting it freed nothing. The turn's
own checkpoint then evicted everything and was refused anyway: on a 64 GB budget, a 101,950-token turn was kept,
the next turn resumed 101,943 tokens and left the store empty, and the one after prefilled from zero. The
scheduler now lets go of it once the store has handed over its copy.

You were right that this doesn't size the window; #71's fix is separate. Thanks for reading that loop closely
enough to catch the evict-then-refuse order. I hope you'll send the next one too.

@ashhart ashhart closed this Sep 29, 2026
BlivionIaG referenced this pull request in BlivionIaG/TensorFold Oct 20, 2026
…DA, expert-aligned prompt tiles

- Checkpoint copies and snapshot loads check again before every eviction, and a resumed prompt stops holding the
  stored prefix it copied; the memory tests pin host RAM, so they pass on any Mac (#74).
- #70's 64 GB M5 Pro measurements go into the README and recipes, labelled as 0.3.5.1.
- On M1-M4, Flash Next's prompt expert gathers take row tiles that never straddle experts (the scheduling idea of
  ml-explore/mlx#4567), same bits.
- A reader for ModelOpt and compressed-tensors NVFP4, FP8 and MXFP8 weights, W4A16 and W8A16 lane matmuls with exact
  weights, and Qwen3.8-27B on ModelOpt NVFP4 checkpoints.

Fixes #70.
@ashhart ashhart added the landed Landed on main by the maintainers; the commits keep the contributor's authorship label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

landed Landed on main by the maintainers; the commits keep the contributor's authorship

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants