Repository navigation
Capture every prompt end in the shared LLM serving prefix cache - #24624
mergennachin wants to merge 9 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24624
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New Failures, 1 Unrelated FailureAs of commit 381baa0 with merge base 0fc43f6 ( NEW FAILURES - The following jobs have failed:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
d45a786 to
5e75b20
Compare
|
@claude /pr-review |
|
Claude finished @mergennachin's task in 20m 7s —— View job Summary: The new Detailed reviewPR Review: #24624 SummaryThis PR adds an opt-in
All 10 changed files were reviewed. Code Quality
Testing
API Design
Performance
RecommendationRequest Changes
|
5e75b20 to
2ea9667
Compare
3c7a6d3 to
25c8d8a
Compare
|
@claude /pr-review |
|
Claude finished @mergennachin's task in 20m 35s —— View job Summary: This needs discussion before merge: in prompt-end-only mode each continuation and replacement holds a transient row until it finishes, the flag behaves differently alongside an interval or policy, the new capacity check is untested, and a helper change is unreachable. Detailed reviewPR Review: #24624SummaryThis PR adds opt-in
All 15 changed files were reviewed. Code Quality
Testing
API Design
Performance
RecommendationNeeds Discussion
|
fae875c to
cd0c76e
Compare
cd0c76e to
5a15c6c
Compare
|
@claude /pr-review |
|
Claude finished @mergennachin's task in 33m 18s —— View job Request Changes: turning per-session prompt-end checkpoints on by default for Muse-Glimmer quadruples the default executor rows (4 → 16), which breaks existing 65536-cell CUDA exports and command lines. Separately, Detailed reviewPR Review: #24624SummaryThe PR gives each named session in
Code Quality
Testing
API Design
Backward Compatibility
RecommendationRequest Changes What blocks approval:
Review only: no code was changed, and nothing was built or run. |
|
Prefix caching configuration feels like getting complicated to me. Enabling --prefix-checkpoint-prompt-end saves every session request’s prompt end instead of only the initial prompt, and changes --prefix-cache-entries 8 from 8 checkpoints total to 8 per session. What do you think about separating checkpoint ownership from capture policy? Ownership: shared across sessions, or private per session. These can be expressed separately, for example: The entry limit would apply to the selected scope. We can still reject the unsupported combinations. However, separating ownership from capture policy might not worth redesigning if we don’t plan to support more combinations. For example, do we expect to support other capture policies with per-session ownership in the future, or is per-session caching intended to be limited to prompt-end checkpoints? Could be a follow up work as well. |
|
Agreed, it got too complicated. Rather than splitting, I'm removing per-session ownership from this PR. If we need per-session ownership later, --prefix-cache-scope shared|session can be added without breaking anything, with the entry limit applying to the selected scope as you suggested. We'll have three options: --prefix-cache-entries N: total shared checkpoints; 0 turns caching off |
Per-session ownership gave anonymous requests no reuse, multiplied reserved rows by max_sessions, cleared checkpoints on idle eviction, and gave --prefix-cache-entries two meanings. Prompt-end capture now uses the shared cache, selected with --prefix-checkpoint-prompt-end initial|every, and stays opt-in for Muse-Glimmer. Both settings skip prompt ends already retained and release capture rows once the clone settles; the control thread is notified only then, so collecting a capture never waits on the engine.
This PR needs a
|
|
@claude /pr-review |
|
Claude finished @mergennachin's task in 29m 18s —— View job Needs discussion: with Detailed reviewPR Review: #24624SummaryThe PR adds Code Quality
Testing
Performance
RecommendationNeeds Discussion
Review steps
This was a review only: no code was changed, and nothing was built or run. |
Reading a prompt is the slow first step of answering it: the model processes every token to build its internal state (prefill). With prefix caching on, the serving runtime saves that state as a snapshot, so a later request that starts with the same text can skip re-reading it.
Today the server saves a snapshot only for the first prompt of each session. Later turns aren't saved, so whenever the live session can't be reused, everything after the first prompt is read again. That happens when a turn is cancelled and retried, when another session (such as a sub-agent) continues the same conversation, or when an idle session is evicted and the client resends its history.
This PR adds an option to save every turn's prompt, not just the first:
Use
--prefix-checkpoint-prompt-end everyto turn it on;initial, the default, keeps today's behavior. Snapshots go into the existing shared cache and count against the existing--prefix-cache-entrieslimit, so the memory reserved for a given setting doesn't change. It's off by default in both the generic and Muse-Glimmer servers, and it can't be combined with--prefix-checkpoint-interval.Saving is best effort. The server skips prompts it has already saved, and it frees the temporary slot used to make a copy as soon as the copy exists, instead of holding it until the response finishes. Both behaviors also apply to the default mode.
An earlier version of this PR kept a separate cache for each session. Based on review feedback, it now uses the shared cache instead. That way requests without a session ID benefit too, and
--prefix-cache-entrieskeeps a single meaning.Review order:
serving_runtime.handprefix_cache.h, thenserving_runtime.cpp. The rest is tests, launchers, and docs.Tested with the serving and batching C++ suites (296 and 227 tests) and the launcher Python tests. The end-to-end Muse-Glimmer check from the earlier version hasn't been re-run yet.
Authored with OpenAI Codex and Claude Code.