Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25727
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 56bb153 with merge base 2bb454f ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude /pr-review Please review this PR (head |
|
Claude finished @Gasoonjia's task in 30m 51s —— View job PR Review: #25727Request changes: cache-on groups are sized as if every member will reuse its longest cached prefix, and nothing re-checks the half-of- Detailed reviewSummaryThe PR adds The main problem is that this charge is an estimate that nothing re-checks, so a group can go far past its cap whenever a credited clone is refused. The other findings are minor:
I read the code for this review but did not build it or run the tests. Code Quality
Testing
Performance
RecommendationRequest Changes. The cache-on group cost should be bounded by what each member actually reuses. Alternatively, accept the overshoot explicitly, document it, and add a test for it. The other findings are minor and could be follow-ups. |
PrefixCache::find_identities() runs find_identity() for several requests at once. Each wave selects the next candidate of every request still searching and queues its clone before awaiting any, so Runner serves the whole wave in one engine iteration; a request whose clone is refused continues in the next wave. Each result matches find_identity() against the cache as it was at the call, errors stay per request, and find_identity() now delegates to it. ServingRuntime now also groups queued anonymous text generations when prefix caching is enabled. A group looks up all of its members with one find_identities() call and then issues the cold opens of its misses together, before submitting the members in queue order. Previously each member awaited its own clone, and then its cold open, before the next member was looked at, so a shared-prefix burst was admitted one request per executed batch. With caching, the group bound of half the step prefill budget counts only the positions a member still has to prefill after its longest cached prefix, found without cloning. Shared-prefix bursts therefore group widely, while prompts that are long after reuse keep one-per-step admission. Keyed requests, image prompts, single requests and cache-less groups are unchanged.
PrefixCache::longest_match() returns the match find_identity() would try first, in one scan without allocating or cloning. find_identities() drops its unreachable settle guard, since each wave settles every clone it queues, and its candidate and search state become private nested structs so the helpers are no longer templates. Tests now show that the clones of a wave are pending together, using the order in which the engine serves them, and cover a std::bad_alloc that ends only the query that raised it.
A cache-on group was sized by charging each member its prompt minus its longest cached prefix, and nothing re-checked that after the clone waves. A refused or skipped clone could leave many members prefilling far more than the half-step budget in one step. After the lookup, the group now recomputes each member's cost from the prefix it adopted and keeps the members that fit in queue order. The rest release their clones and pending opens on control and return to the inbox as their original commands. A failed lookup ends the group the way a failed preparation does. The cost estimate uses PrefixCache::longest_match(). A member with nothing cached issues its cold open while the group is sized, so the open shares the engine pass of the first clone wave. generate() takes the group lookup by value, so whatever a member does not adopt is released on control when it returns. Serving tests now each hold the first prefill and check counts only a group can reach, and a failed preparation is shown to end a cache-on group.
When a preparation fails after other members are waiting, the failed member ends the group with its rejection already delivered. If the clone-wave budget check then cut the group at an earlier member, the failed member was requeued with the cut ones and prepared a second time: its input, consumed by the first attempt, could prepare successfully and run a request whose Failed terminal had already been emitted. Members rejected in preparation are now always launched, and only prepared cut members and the untried tail return to the inbox. PrefixCachingStillGroupsShortPrompts also checks that no slice of the first prompt ran before the second finished preparing.
|
@claude /pr-review Please review the current head
Full model, H100, c=32, base #25726: shared prefix +45% throughput, −68% TTFT. Unique prompts are neutral within run-to-run noise (−1 to −2% throughput, +2% TTFT, inside the base-vs-base variance of about ±3%). Outputs at c=1 are identical. |
a611fe5 to
526a4b5
Compare
|
Claude finished @Gasoonjia's task in 32m 40s —— View job PR Review: #25727Request changes: the group cap now holds after the clone wave, but a member it cuts is requeued with the same credit, so when clones keep being refused each later group clones it again (about N² clone attempts for N members); the other six findings are minor. Detailed reviewSummaryThis revision bounds cache-on groups by the prefix each member actually adopted, adds The cap now holds, but a cut member is requeued with nothing recorded about the clone it lost. When clones are refused for a structural reason, every later group credits that member and clones it again. The other findings are minor:
I read the code for this review but did not build it or run the tests. Code Quality
Testing
Performance
RecommendationRequest Changes. Requeued members should be sized by the prefix they actually got, so that persistent clone refusals cannot turn the cut into repeated clone waves. The other findings are minor and could be follow-ups. |
A member cut by the clone-wave budget check was requeued with nothing recorded about its lookup, so the next group credited it with the same longest match and cloned the refused snapshot again. With refusals that repeat, such as an executor that clones only at saved boundaries, N members took about N squared clone attempts. A cut member now records the prefix it adopted (0 after a miss), and its later sizing and lookups are bounded by it, so each member tries a refused snapshot at most once. A cancelled member no longer anchors a group: it costs nothing in either the sizing loop or the budget check, so the first live member behind it is never cut. The unreachable branch for a failed lookup in a kept group is removed, and the generate_group() comment now states that a cache-on group bounds its pre-submission tokenization by free session slots rather than the budget. New tests cover the exact clone counts, a cancelled head member, a cut miss whose pending open is released, and credited members that miss and open together.
|
@claude /pr-review Please review the current head
|
A cut member's reuse bound records the prefix its lookup adopted, so that it does not retry a longer snapshot that was refused. A miss whose cold open was issued while the group was sized never looked anything up, yet a cut gave it a bound of 0 and blocked all of its future prefix reuse, including entries cached before its next pass. Only members that went through the lookup are now bounded. The comment also says that only longer refused snapshots are excluded: an equal-length one may be retried once.
|
Thanks for the approval. I pushed
I left three items for a small follow-up:
|
A cache-on group submits its members back to back, so the prompt-end capture lanes that one-at-a-time admission recycles between members were still busy for all but the first few, and the rest skipped their captures. The cache then kept older entries whose cells no running request shares. With the cell KV cache, every step reads cells up to the highest one in use, so decode steps got slower: on Muse Glimmer with 4 capture lanes, steady decode at 8 and 16 concurrent requests was about 2% slower, with about 500 more cells resident than on the base. A member of a group of two or more that finds no lane at submission now retries at each later output and queues the same prompt-end capture once a lane frees, while it is still decoding. Like a first-output capture, it is handed to control only once its clone has settled, using the new PrefixCache::PromptCapture::ready(), so collecting it never blocks control. Single requests and one-member groups keep skipping, as before.
|
@claude /pr-review Please review the current head Cause: capture lanes are taken at submission and a group submits all its members together, so only as many members as there are lanes captured their prompt end. The cache kept stale entries whose cells no running request shares, which widened the cell-cache read window by 8–16%. Fix: in a group of two or more, a member that finds no free lane retries on each later token and captures its prompt end ( Results: steady decode at B=8/16 goes from −2.4/−2.1% to about −0.5%, within session-to-session variation. The unique-prompt burst is neutral, and the shared-prefix wins are kept (+18/+44/+64% at B=16/32/48). Tests: new |
|
Claude finished @Gasoonjia's task in 36m 0s —— View job PR Review: #25727 (head
|
The deferred prompt-end capture moved the request's callback into its closure before allocating the closure, so a std::bad_alloc there left the request without a callback. It now copies the callback, so a failed setup keeps it intact. The comments now say that deferral handles a lane cap below a group's size (with the default lane count every member finds a lane), and state the handoff of capture_lane and prefix_capture between the callback and control.
|
Thanks for the approval. I pushed
I left three items for follow-ups:
|
Stacked on #25726.
Adds
PrefixCache::find_identities(), which runsfind_identity()for several requests in waves. Each wave queues one clone per request that is still searching before awaiting any, and a refused clone retries in the next wave. Errors stay per request, and Use/Skip/Stop selectors, entry IDs and caller-sidetouch()are unchanged.find_identity()now delegates to it.PrefixCache::longest_match()returns the matchfind_identity()would try first, in one scan without allocating or cloning.With the prefix cache enabled,
ServingRuntimenow also groups queued anonymous text requests, building on #25726's cold-open groups:longest_match(), so sizing clones nothing. It counts against the same half-of-step_prefill_budget()cap.Results. Official
Muse-Glimmer-30B-KQuant-17GB-Q4_K_M.gguf(HF meta-models/Muse-Glimmer-30B-GGUF), H100, CUDA graphs on, prefix cache on (8 entries, 4 capture slots), paired base (#25726) / PR runs:Peak VRAM rises from 21.6 to 24.1 GiB in a short-prompt decode sweep with the cache on: a group of short prompts is prefilled in one step of up to half the per-step budget (about 2K tokens). That stays below the 25.0 GiB the base build already reaches under the same server configuration when it serves 1.2K-token prompts, so the configured worst-case footprint doesn't grow. Host RSS is unchanged.
Prompt-end captures in groups. Capture lanes are taken at submission, and a group submits its members together. When the lanes are capped below the group size (a small
max_prefix_captures, or a checkpoint interval or policy; with the default lane count every member finds one), a member that finds no free lane retries on later tokens and captures its prompt end mid-decode once a lane frees. It hands the capture to control only after the clone completes (PrefixCache::PromptCapture::ready()), so control never blocks. Without this, only as many members as there are lanes captured, and stale entries widened the cell-cache read window enough to slow steady decode by about 2%. The trade-off: lanes freed mid-decode now go to waiting grouped members first. A newly submitted single request (which doesn't retry) is more likely to skip its capture, and a keyed turn whose replacement needsclone_prefix()may find no lane and re-prefill from position 0 instead of cloning its prefix.Output determinism. At c=1, outputs are identical to the base, including every prefill length up to 127k. At c=32 on the shared workload, repeated PR runs match each other about 81% of the time, against about 95% for repeated base runs. Prefill lengths match on every request and the differences mostly start late in the text (median at character 204), so this comes from batch-composition-dependent numerics, not from reusing the wrong state. Cache entries are idle snapshots inserted on control between groups, so no member can clone an entry that is still being captured.
Trade-off. Because a cache-on group counts only uncached positions, the tokenization before its first submission is bounded by its free session slots rather than by the budget: a burst of long, mostly cached prompts is prepared in full first, in exchange for one shared admission.
Test plan: 23 new tests (10 batching, 13 serving) and one rewritten serving test (#25726's
PrefixCachingDisablesGroupingbecomesPrefixCachingStillGroupsShortPrompts). They cover wave-vs-sequential equivalence, clones pending together (checked by the order the engine serves them),longest_match(), Skip/Stop, entry IDs and touch, per-request clone failures includingstd::bad_alloc, capture-lane limits, shutdown while pending, the cache-on group budget before and after the waves, cut members (exact clone counts, released pending opens, no re-preparation of a rejected member, later reuse by a member cut before its lookup), cancelled head members, failed preparations, and credited members that miss. Each new behavior's test was checked to fail with its code removed, except the release of a cut member's pending open, which the same call releases anyway when it returns; that path is covered by a test and by the fixture's leak check. They are stable over 1000 repeats and 8×300 in parallel. Two more tests cover the deferred prompt-end capture (MembersWithoutALaneCaptureTheirPromptsLater,PromptCaptureIsReadyOnceItsCloneSettles). Serving suite: 317 pass (14 skipped, same as main). Batching suite: 240 pass.