Skip to content

feat: non-consuming clone-and-pin paged adoption - #232

Merged
inureyes merged 2 commits into
mainfrom
feat/issue-227-clone-and-pin-adoption
Jun 12, 2026
Merged

inureyes merged 2 commits into
mainfrom
feat/issue-227-clone-and-pin-adoption

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Implements #227. 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 (the hazard documented on this issue from the #226 measurement).

  • Paged entries now adopt by CLONE. The scheduler's new path runs under the non-consuming CacheEntry::with_detached and calls CachePool::clone_detached_paged_prefix: an adoptable copy referencing the SAME physical blocks, pinned twice per block exactly as detach_paged would 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.
  • 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 states) decline to a cold prefill with the entry untouched. A paged entry under a dense decode backend declines without consuming, where the old path took the set and then released it.
  • The fix(server): paged backend declines every partial prefix adoption, and APC+paged loses even multiturn reuse #225 take-plus-trim arm remains as the defensive fallback behind the clone path.

Measured effect (llama-3.2-1b, --apc-enabled, M1 Ultra)

metric before after
burst (8 concurrent siblings) adoptions 1 of 8 (3648 cached tokens) 8 of 8 (29184)
burst-phase footprint peak 2815 MiB (pre-#224) / 2081 (post) 1630 MiB (v0.1.4 dense baseline: 1653)
burst phase wall 11.8 s 3.5 s
cannibalization repro: A's re-match depth after a divergent B 32 tokens (entry gutted) 3808 tokens (entry intact)

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 against the dense reference, declined targets leak no pins.
  • Real-model gates (qwen3 + llama3): new paged_clone_and_pin_share tests 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).
  • Suites: core 873 lib tests (single failure is the pre-existing release-mode pack3 should_panic on main), server 3150, cold clippy clean, fmt clean.

Closes #227

inureyes added 2 commits June 12, 2026 14:00
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).
@inureyes
inureyes merged commit 944d538 into main Jun 12, 2026
4 checks passed
@inureyes
inureyes deleted the feat/issue-227-clone-and-pin-adoption branch June 12, 2026 05:35
@inureyes inureyes added this to the 0.2 milestone Jun 21, 2026
@inureyes inureyes self-assigned this Aug 31, 2026
@inureyes inureyes added status:done Completed type:enhancement New features, capabilities, or significant additions priority:medium Medium priority labels Sep 6, 2026
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(server): non-consuming paged adoption so concurrent same-prefix requests share one stored prefix

1 participant