Skip to content

[Bugfix][Core] Backport upstream Mamba prefix-cache retention - #15

Merged
Leonccaa merged 4 commits into
release/ct252-fp8-mtp-20260910from
fix/ct252-mamba-prefix-retention-20260913
Sep 13, 2026
Merged

Leonccaa merged 4 commits into
release/ct252-fp8-mtp-20260910from
fix/ct252-mamba-prefix-retention-20260913

Conversation

@Leonccaa

@Leonccaa Leonccaa commented Sep 13, 2026

Copy link
Copy Markdown
Owner

Review follow-up (2026-09-13; 9c62d99a07)

  • Fixes PR15 sparse event review: emit one BlockStored per contiguous retained logical range, with matching tokens, hashes, extra keys and logical parent; suppress empty events. Tests cover masks, null blocks, grouped hashes, LoRA, multimodal metadata and nonzero cache horizons.
  • Fixes PR617 decode boundary review: non-EAGLE retains both resend and completed extension boundaries before the cache horizon advances. Incremental decode tests cover 32/800-token blocks and zero/positive retention intervals. The EAGLE branch is unchanged.
  • All 38 new regression cases pass; against the previous source they produce 34 failures and 4 passes.
  • Combined prefix-cache and Mamba retention suite: 205 passed. Source and regression tests for both review fixes match PR617. The older base has neither the incorrect QSA return annotation nor the AGPL scale-gate test, so those upstream-base CI adjustments are not included here.

GPU evidence scope: the 37-request GPU acceptance below belongs to the preceding heads 820516bf5a / 5c49dbfb13. This follow-up is CPU-validated, with no new GPU acceptance claim. The tested MTP3 path used events disabled; its replay-boundary branch is unchanged. Newly fixed non-EAGLE and event-enabled paths have CPU regression coverage. No production or GPU-runtime changes were made.

Dense Mamba state snapshots can consume the shared block pool and evict the Attention prefix of an older long conversation. A subsequent follow-up then reports zero usable prefix and repeats the full prefill. This PR adapts upstream Mamba retention to 1Cat's aligned state layout and preserves uncached blocks for reuse before evicting cached prefixes.

Upstream provenance and configuration

This is a semantic backport of established upstream work, replacing the earlier custom environment-variable design:

  • vLLM #43447: uncached-first free queue and selective retention framework.
  • vLLM #45845: Mamba sparse retention to prevent recurrent snapshots from evicting Attention prefixes.
  • vLLM #47782: detect and retain shared-prefix junctions.
  • vLLM #53945 and #54713: MTP/EAGLE recovery boundaries for identical resend and longer sibling requests.

Configuration follows upstream main at fa008bdccf10f2f31f84553112a227cf1b8947d7: CacheConfig.prefix_cache_retention_interval, exposed as --prefix-cache-retention-interval.

Value Meaning
None Dense retention
0 (default) Retain necessary replay boundaries and detected shared-prefix junctions
Positive integer Additionally retain periodic checkpoints, in tokens, validated as a multiple of resolved cache alignment

For CT252's 800-token alignment, 4000/8000/16000/32000 correspond to 5/10/20/40 blocks. The former custom environment variable is removed: its 0 meant dense retention and corresponds to the new None, not the new 0.

1Cat adaptation and scope

  • Keep 1Cat's existing MTP safety backoff, per-group EAGLE classification, aligned state allocation, and offload bookkeeping.
  • Carry the detected junction through the request and scheduler to retention; preserve the existing two-value cache-lookup API used by connectors.
  • Apply sparse admission to aligned Mamba groups. Unproven mixed alignments fall back to dense retention; SWA policy remains unchanged. A positive interval without a Mamba group is rejected in this bounded backport.
  • A newly observed fork can still require replay before its junction is materialized. Retained checkpoints are evictable; this does not guarantee hits under arbitrary capacity pressure.
  • No model kernels, QSA operators, quantization paths, or speculative token acceptance changes.

Validation

CPU metadata regressions cover dense-vs-sparse long A/B retention, identical resend and longer sibling boundaries, detected junction reuse, main/draft mixed EAGLE groups, reference counts and scratch reuse, and token intervals across 16/512/800/1024-token block sizes. The 105 retention tests pass. Existing prefix-cache tests pass after updating exact queue-order assertions for the intended uncached-first policy. Applicable pre-commit checks pass.

The broader five-file CPU run reports 237 passed / 16 failed. All 16 failing node IDs also fail on the unmodified CT252 baseline (132 passed / 16 failed), from unavailable device inference and existing simplified config fixtures; there are no new failing nodes. These CPU tests do not establish CUDA/state-tensor correctness or production acceptance.

Historical GPU evidence is for the previous custom patch, not this final upstream-aligned implementation (TP4 V100, Flash-Next AWQ + native FP8 MTP3, 800-token state alignment):

Earlier policy A after long B: cached tokens / TTFT B after short C: cached tokens / TTFT
Original 0 / 73.453 s 0 / 75.846 s
Queue fix, dense custom 0 0 / 73.538 s 0 / 75.942 s
Queue fix, explicit 800 tokens 0 / 73.279 s 0 / 77.307 s
Queue fix, custom 16000 tokens 168800 / 1.040 s 174400 / 0.995 s
Queue fix, custom 5 blocks 168800 / 1.143 s 174400 / 1.064 s

The custom 5-block arm also exposed a first-fork miss despite a surviving Attention prefix, motivating the junction port. The subsequent 10-block arm was stopped during initialization; 20/40 were not run. No results are claimed for those arms.

The final port has now passed the bounded Flash-Next/V100/MTP3 GPU acceptance below. Production has not been patched.

Final-port GPU acceptance — 2026-09-13

PASS on exact head 820516bf5a (identical runtime source in release-port 5c49dbfb13). All nine changed source files were SHA-256 verified over the original b8aa release image. No diagnostic or 1CatAI#616 overlay. Default prefix_cache_retention_interval=0; TP4 V10032GB, Flash-Next AWQ + native FP8 MTP3, FP16 KV, C2, max context262144, batch8192, GMU0.984, KV capacity493491tokens.

37 requests completed; zero preemptions; no CUDA/OOM/engine errors.

Final-port check Cached tokens TTFT
A170123 repeat 168800 1.050s
A after B175321 cold prefill 168800 1.029s
A / B after C14017 168800 / 174400 1.031 / 0.997s
First119k fork (allowed replay) 0 50.757s
Same fork / second sibling 117600 / 117600 0.979 / 0.978s
15999 /16000 /16001-token repeat 14400 /14400 /15200 0.714 /0.703 /0.489s
A / B after600seconds with no inference 168800 /174400 2.217 /1.004s
A / B follow-up after warmed C2 + new third14k 168800 /174400 2.682 /1.280s

Seven serial prompt/output token arrays match the historical accepted arm. Three boundary cases and the fork sibling also match independent, unique-cache-salt cold controls token-for-token. Both long follow-ups and post-idle outputs match their cold references. The first unknown fork requires replay, then the materialized junction is reusable.

The clean warmed mixed run records343200 combined A+B prefix hits and0hits for the new third request. Over a16.776s pure dual stream window, A/B deliver67.716/39.700tok/s (combined107.416); A after the third delivers77.392tok/s alone. Maximum token gaps A0.943s/B0.061s. Third TTFT21.332s includes C2 queueing and is not a pure prefill measurement. A prior mixed arm following several independent fork/control prefixes had B cold and is not used as the warmed comparison. Retention does not eliminate finite-pool capacity eviction.

Reproduction: serial A170123 repeat, B175321, A, C14017, A/B; fork at119123tokens plus instruction tail, identical and sibling retries;15999/16000/16001 boundaries with fresh-salt controls; A4096-output/B768-output concurrent streams with a third cold14023-token request under C2, followed by A/B continuations; refresh A/B, wait600seconds without inference, repeat. Sampling temperature0; long stream stress ignores EOS. All assertions pass for cached-token deltas, zero preemptions, generated-token counts and the output comparisons above. Acceptance scope is this Flash-Next/V100/MTP3 configuration, not universal model/GPU coverage.

Recycle uncached scratch before cached blocks and add opt-in sparse checkpoint admission while preserving both replay boundaries.

Assisted-by: OpenAI Codex

Signed-off-by: Leonccaa <166551845+Leonccaa@users.noreply.github.com>
Leonccaa and others added 2 commits September 13, 2026 01:18
Express the opt-in interval in manager blocks so model-specific block sizes do not require token-unit conversion. Cover portable intervals and dense admission across four block sizes.

Co-authored-by: OpenAI Codex <noreply@openai.com>

Signed-off-by: Leonccaa <166551845+Leonccaa@users.noreply.github.com>
Adapt vLLM #45845, #47782, #53945 and #54713 to the 1Cat aligned-state layout. Replace custom interval environment variables with upstream token-based CacheConfig semantics.

Co-authored-by: OpenAI Codex <noreply@openai.com>
Signed-off-by: Leonccaa <166551845+Leonccaa@users.noreply.github.com>
@Leonccaa Leonccaa changed the title [Bugfix] Retain aligned Mamba prefixes across long prefills [Bugfix][Core] Backport upstream Mamba prefix-cache retention Sep 13, 2026
@Leonccaa
Leonccaa marked this pull request as ready for review September 13, 2026 15:44
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-13T15:49:46.293601Z 5c49dbf Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c49dbfb13

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

num_full_blocks=num_full_blocks,
block_size=self.block_size,
kv_cache_group_id=self.kv_cache_group_id,
block_mask=mask,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve KV-event hash/token correspondence

When KV-cache events are enabled, passing the sparse retention mask here causes cache_full_blocks to omit masked blocks from BlockStored.block_hashes while still emitting the entire newly processed token range in token_ids; for the default interval, most calls therefore emit an event with zero hashes and one block of tokens. This violates the event invariant len(token_ids) == block_size * len(block_hashes) used by KV-event consumers, so Mamba deployments using cache events can publish malformed store events or associate tokens with the wrong hashes.

Useful? React with 👍 / 👎.

Preserve logical event ranges and admit completed decode boundaries before the cache horizon advances. Add regression coverage and repair baseline CI typing and conflicting header checks.

Co-authored-by: OpenAI Codex <noreply@openai.com>
Signed-off-by: Leonccaa <166551845+Leonccaa@users.noreply.github.com>
@Leonccaa
Leonccaa merged commit 2bb8cb6 into release/ct252-fp8-mtp-20260910 Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant