Skip to content

fix(cache): include snapshot arrays in RAM cache capacity - #2457

Open
remote-controlled-man wants to merge 2 commits into
abetlen:mainfrom
remote-controlled-man:codex/prflow-d42eae33522a
Open

remote-controlled-man wants to merge 2 commits into
abetlen:mainfrom
remote-controlled-man:codex/prflow-d42eae33522a

Conversation

@remote-controlled-man

Copy link
Copy Markdown
Contributor

LlamaRAMCache.cache_size counts only llama_state_size, although Llama.save_state() also copies the token and logits arrays into each snapshot. The cache can therefore retain snapshots whose payloads exceed capacity_bytes.

Include both NumPy buffers in the existing size calculation so the existing LRU eviction loop accounts for the snapshot payload. Add regression tests and a changelog entry.

Validation on macOS arm64 / Python 3.12.14:

  • make test: 34 passed, including the 8 new regression/control cases and existing native model tests.
  • make lint: Ruff lint and formatting checks passed (30 files).
  • Restoring the original size calculation: 6 new cases fail and 2 normal-hit controls pass.
  • A real eval()/save_state() snapshot from the cached stories15M-q4_0.gguf contains 34,797 native bytes, 640,000 logits bytes and 1,024 token bytes. At a 34,797-byte capacity, the original cache retains it; the fix evicts it.

The tests cover capacity boundaries, LRU order, replacement, exact hits and prefix hits. The native library was built with GGML_NATIVE=OFF. Other platforms were not tested locally.

Found through local source inspection and execution. Issue/PR searches for RAM cache capacity and snapshot arrays found no overlapping fix. Prepared with OpenAI Codex assistance, including a separate independent code and validation review.

Copilot AI balanced review requested due to automatic review settings November 27, 2026 12:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants