Repository navigation
feat: non-consuming clone-and-pin paged adoption - #232
Merged
Merged
Conversation
take_detached is one-shot, so the first adopter consumed the stored entry: concurrent same-prefix siblings cold-prefilled (one adoption out of eight on the burst workload), and combined with #225's trim a short partial match (even the ~30-token chat-template preamble) could gut a multi-thousand-token entry down to one block. Paged entries now adopt by CLONE. The scheduler's new path runs under CacheEntry::with_detached (non-consuming): it floors the match to the pool block boundary and calls CachePool::clone_detached_paged_prefix, which builds an adoptable copy referencing the SAME physical blocks, pinned twice per block exactly as detach_paged would (rollback on pin failure), with metadata-only handle clones re-anchored at the adopted length and real-bytes accounting carried over. The stored entry stays live for concurrent siblings and deeper future matches. Dense entries keep the legacy one-shot consume (their adoption genuinely moves buffers); clone-ineligible paged sets (Turbo4 sidecars, tensor-carrying dense-compat handles, sliding-window) decline to a cold prefill with the entry untouched. Validation: - Unit: clone shares the source's physical blocks with exact refcount choreography (2 source + 2 per clone, adopt releases the clone pin, full release returns to zero), divergent suffixes land on fresh blocks byte-identically, declined targets leak no pins. - Real-model (qwen3 + llama3): one stored entry serves two divergent borrowers byte-identically to cold runs and SURVIVES both. - HTTP E2E (llama-3.2-1b, --apc-enabled): the #226 cannibalization repro now keeps entry A intact (preamble-only B adopts 32 via clone; A's resend deep-matches 3808 tokens, was 32). Burst: all 8 siblings adopt (cached 29184 tokens, was 3648), burst-phase footprint 1630 MiB (v0.1.4 baseline 1653, pre-fix 2815), burst phase 3.4x faster (3.5 s vs 11-12 s). - Suites: core 873 lib (one pre-existing release-mode pack3 failure on main), server 3150, prefix-share parity 6/6 real-model, cold clippy clean, fmt clean.
…-ineligible sets (review follow-up) Review caught a HIGH regression: a whole-entry match passed the stored set's unfloored length (prompt + generated, almost never block-aligned) into clone_detached_paged_prefix, which rejects unaligned targets, so the default-config multi-turn continuation declined to a cold prefill. Both match shapes now floor to the pool block boundary; the re-prefill covers the dropped partial tail plus the new turn. Clone-ineligible paged sets (dense-compat handles, Turbo4, sliding-window; new DetachedPagedCacheSet::clone_eligible) fall through to the consuming take path instead of declining, so Int8-style paged entries keep their pre-#227 adoption behavior. E2E: default-config multiturn restored to cached 10976 tokens (the floored whole-entry clone; was 0 with the unfloored decline, 11067 on the pre-#227 consuming path, difference = the dropped partial tails). New real-model test pins the unaligned whole-entry floor (52-token entry, matched 52, floors to 32, byte-identical to cold, entry survives).
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
* feat: non-consuming clone-and-pin paged adoption take_detached is one-shot, so the first adopter consumed the stored entry: concurrent same-prefix siblings cold-prefilled (one adoption out of eight on the burst workload), and combined with lablup#225's trim a short partial match (even the ~30-token chat-template preamble) could gut a multi-thousand-token entry down to one block. Paged entries now adopt by CLONE. The scheduler's new path runs under CacheEntry::with_detached (non-consuming): it floors the match to the pool block boundary and calls CachePool::clone_detached_paged_prefix, which builds an adoptable copy referencing the SAME physical blocks, pinned twice per block exactly as detach_paged would (rollback on pin failure), with metadata-only handle clones re-anchored at the adopted length and real-bytes accounting carried over. The stored entry stays live for concurrent siblings and deeper future matches. Dense entries keep the legacy one-shot consume (their adoption genuinely moves buffers); clone-ineligible paged sets (Turbo4 sidecars, tensor-carrying dense-compat handles, sliding-window) decline to a cold prefill with the entry untouched. Validation: - Unit: clone shares the source's physical blocks with exact refcount choreography (2 source + 2 per clone, adopt releases the clone pin, full release returns to zero), divergent suffixes land on fresh blocks byte-identically, declined targets leak no pins. - Real-model (qwen3 + llama3): one stored entry serves two divergent borrowers byte-identically to cold runs and SURVIVES both. - HTTP E2E (llama-3.2-1b, --apc-enabled): the lablup#226 cannibalization repro now keeps entry A intact (preamble-only B adopts 32 via clone; A's resend deep-matches 3808 tokens, was 32). Burst: all 8 siblings adopt (cached 29184 tokens, was 3648), burst-phase footprint 1630 MiB (v0.1.4 baseline 1653, pre-fix 2815), burst phase 3.4x faster (3.5 s vs 11-12 s). - Suites: core 873 lib (one pre-existing release-mode pack3 failure on main), server 3150, prefix-share parity 6/6 real-model, cold clippy clean, fmt clean. * fix: floor whole-entry paged clone targets and fall through for clone-ineligible sets (review follow-up) Review caught a HIGH regression: a whole-entry match passed the stored set's unfloored length (prompt + generated, almost never block-aligned) into clone_detached_paged_prefix, which rejects unaligned targets, so the default-config multi-turn continuation declined to a cold prefill. Both match shapes now floor to the pool block boundary; the re-prefill covers the dropped partial tail plus the new turn. Clone-ineligible paged sets (dense-compat handles, Turbo4, sliding-window; new DetachedPagedCacheSet::clone_eligible) fall through to the consuming take path instead of declining, so Int8-style paged entries keep their pre-lablup#227 adoption behavior. E2E: default-config multiturn restored to cached 10976 tokens (the floored whole-entry clone; was 0 with the unfloored decline, 11067 on the pre-lablup#227 consuming path, difference = the dropped partial tails). New real-model test pins the unaligned whole-entry floor (52-token entry, matched 52, floors to 32, byte-identical to cold, entry survives).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements #227.
take_detachedis one-shot, so the first adopter consumed the stored entry: concurrent same-prefix siblings cold-prefilled (one adoption out of eight on the burst workload), and combined with #225's trim a short partial match (even the ~30-token chat-template preamble) could gut a multi-thousand-token entry down to one block (the hazard documented on this issue from the #226 measurement).CacheEntry::with_detachedand callsCachePool::clone_detached_paged_prefix: an adoptable copy referencing the SAME physical blocks, pinned twice per block exactly asdetach_pagedwould produce (with rollback on pin failure), metadata-only handle clones re-anchored at the adopted length, and real-bytes accounting carried over. The stored entry stays live for concurrent siblings and deeper future matches.Measured effect (llama-3.2-1b, --apc-enabled, M1 Ultra)
Validation
paged_clone_and_pin_sharetests prove one stored entry serves two divergent borrowers byte-identically to cold runs and survives both; all existing prefix-share, partial-share, and scheduler parity gates stay green (6/6 byte-identical).pack3should_panic on main), server 3150, cold clippy clean, fmt clean.Closes #227