Repository navigation
Reuse committed prompt prefixes from active text requests - #24471
mergennachin wants to merge 2 commits into
Conversation
Allow anonymous text requests to clone a matching committed prompt prefix from an active request when it saves enough prefill work. Complete clones through the serving control loop, retain cached and cold fallback paths, and keep the feature disabled by default while evaluating performance. Authored with assistance from Codex.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24471
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 Cancelled Job, 1 Unrelated FailureAs of commit cf4a0cf with merge base 893d815 ( CANCELLED JOB - The following job was cancelled. Please retry:
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. |
This PR needs a
|
Validate nonnegative prefix options in one loop to keep the launcher within the repository complexity limit without changing the accepted ranges or error messages. The two launcher suites pass all 118 tests. Authored with assistance from Codex.
Summary
When two independent requests share a long prompt, the second can repeat prefill even though the first already holds the matching KV state. This adds an experimental serving path that clones the already-computed part of an active request's prompt, then prefills only the recipient's remaining input.
For each arriving anonymous text request, the server selects the active request offering the longest usable match. The clone position is the minimum of the common prompt length, the donor's committed position, and the recipient's prompt length minus one. That last token still runs through the model to obtain the recipient's next-token logits. Generated donor output is excluded from matching.
The server makes one asynchronous clone attempt using state already computed; it does not wait for the donor to reach a future position. The runner completes the clone outside its locks and returns it through the serving control loop. Both requests then own independent sessions and generation settings. If cloning fails, including when sliding-window state has been overwritten, the recipient falls back to the existing cached or full-prefill path.
--active-prefix-reuse-min-tokenssets the minimum extra prefill tokens saved over a cached match.0disables the feature by default; the current experiment uses1024. An equally useful cached prefix takes precedence. The policy uses the shared serving/runner code and existing MLX/CUDA clone implementations, with no scheduler or backend storage changes. Named sessions and multimodal requests retain their existing behavior.For review, start with candidate selection and clone completion in
serving_runtime.cpp, then the callback overload inrunner.cpp, followed by the focused tests and launcher plumbing. This PR is independent of #24304.This remains a draft while the paired replay and CUDA-device validation are pending. Authored with assistance from Codex.
Test plan
The rebased commit
cf4a0cf633was rebuilt from source, including the core runtime and MLX backend. It includes merged PRs #24302 and #24303.python -m pytest examples/llm_server/python/tests/test_serve_launcher.py examples/models/muse-glimmer/tests/test_serve_batching.py examples/models/muse-glimmer/tests/test_serve.py examples/llm_server/python/tests/test_sampling_params.py -q— 268 passed.clang-format --dry-run --Werror; changed Python files pass Ruff E/F checks and formatting checks. Launcher complexity check passes after consolidating range validation.