Skip to content

Add sliding-window batching with BatchRotatingKVCache - #89

Open
ronaldmannak wants to merge 12 commits into
claude/a1-batch-kvcachefrom
claude/a2-batch-rotating-kvcache
Open

ronaldmannak wants to merge 12 commits into
claude/a1-batch-kvcachefrom
claude/a2-batch-rotating-kvcache

Conversation

@ronaldmannak

@ronaldmannak ronaldmannak commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #88.

What changed

  • BatchRotatingKVCache keeps each row's sliding attention window while preserving its logical position: window wrap, ragged prefill, filtering, compatible extension and extraction, with a single-token decode path.
  • Window, allocation-step and capacity-origin compatibility is validated before extension, and batched windows report through cache capacity and status. Pinned prefixes and rewind reserves are refused.
  • New in this update:
    • extract checks its row index with a precondition ("BatchRotatingKVCache row index out of range"). It read the row's padding and position through MLXArray subscripts, which do not trap past the batch, so extract(2) on a two-row batch returned a cache built from out-of-range metadata. mlx-vlm's BatchKVCache.extract raises an IndexError for the same case.
    • Pinned mlx-vlm references (mlx_vlm/models/cache.py at Neywa-Labs/mlx-vlm@dcea787) sit next to the existing mlx-lm references where the Swift code follows mlx-vlm: lengths filtered with the rows, the merge's window check, the all-empty merge.
    • BatchedSlidingWindowParityTests moves into BatchRotatingKVCacheTests.swift, and BatchedSlidingWindowParityTests.swift is deleted (aa59f4c; see Test changes).

Tests

Tests/MLXLMTests/BatchRotatingKVCacheTests.swift: BatchRotatingKVCacheTests (cache lifecycle, wrap, ragged prefill, extension checks, status) and, moved there in this update, BatchedSlidingWindowParityTests (ragged and merged Gemma 3 rows decoding past the window); and additions to KVCacheConfigurationTests. New in this update: extractOutOfRange (exit test). Without the precondition the process exits successfully (expected exit status ".failure", but ".exitCode(EXIT_SUCCESS)" was reported instead).

Round rollback follow-up

Positive-width staged rounds are refused while any row still has a negative logical position, or when the batch has no rows. Zero-width eligibility retains the existing window and eviction checks. The existing refusal of positive rounds that reach the window boundary or follow eviction is unchanged.

The refusal regressions fail with the guard removed without writing into the invalid round. Valid rounds after padding is consumed verify exact rollback and partial commit of retained K/V, row positions and the storage timeline; window-boundary and eviction refusals remain covered. Focused local validation passes 72 tests across 3 suites.

Codex prepared this follow-up, its regressions and validation at the maintainer's request for this origin fork.

Combined stack candidate 7510ad7 also passes 222 Swift Testing tests across 13 suites and 35 XCTest cases. CI-pinned swift-format 603 checks and all 11 library DocC products pass with warnings treated as errors. These are local results; fork CI remains skipped.

Evidence

Previous validation (aa59f4c), with BatchedSlidingWindowParityTests now in BatchRotatingKVCacheTests.swift:

DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer xcodebuild test -skipPackagePluginValidation \
  -scheme mlx-swift-lm-Package -destination 'platform=macOS' \
  -only-testing:MLXLMTests/BatchRotatingKVCacheTests -only-testing:MLXLMTests/BatchedSlidingWindowParityTests \
  -only-testing:MLXLMTests/KVCacheConfigurationTests

Suite "KV-cache configuration" passed after 0.048 seconds.
Suite BatchedSlidingWindowParityTests passed after 0.678 seconds.
Suite BatchRotatingKVCacheTests passed after 0.947 seconds.
Test run with 69 tests in 3 suites passed after 0.947 seconds.
** TEST SUCCEEDED **

The moved suite, alone, before the move (6e092d4) and after it (aa59f4c):

-only-testing:MLXLMTests/BatchedSlidingWindowParityTests
before: Test run with 2 tests in 1 suite passed after 0.518 seconds.
after:  Test run with 2 tests in 1 suite passed after 0.525 seconds.

With the precondition removed:

Test "extract refuses a row index past the batch" recorded an issue at BatchRotatingKVCacheTests.swift:720:32: Expectation failed: expected exit status ".failure", but ".exitCode(EXIT_SUCCESS)" was reported instead
Test run with 35 tests in 1 suite failed after 0.592 seconds with 1 issue.

swift-format format (604.0.0, repo .swift-format) leaves every file this update touches unchanged. Origin-fork GitHub Actions jobs are skipped by the workflow's repository-owner condition; the results above are local (M5 Max).

Rebased onto main 4ab2679 (2026-11-07)

Rebased from c8dabc6 onto main 4ab2679, which adds seven commits (22bdf2c..4ab2679): surrogate-pair escapes, weight-loading progress, LFM2.5, chat-session steering, VLM image prompts out of float32, LFM3, and Qwen 3.5 VLM YaRN. Git applied every commit of the stack without conflicts. git range-diff shows this PR's commits unchanged.

At this head (70d26a2):

DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer xcodebuild test -skipPackagePluginValidation \
  -scheme mlx-swift-lm-Package -destination 'platform=macOS' \
  -only-testing:MLXLMTests/BatchRotatingKVCacheTests -only-testing:MLXLMTests/BatchedSlidingWindowParityTests -only-testing:MLXLMTests/KVCacheConfigurationTests

Suite "KV-cache configuration" passed after 0.042 seconds.
Suite BatchedSlidingWindowParityTests passed after 0.683 seconds.
Suite BatchRotatingKVCacheTests passed after 0.964 seconds.
Test run with 72 tests in 3 suites passed after 0.964 seconds.
** TEST SUCCEEDED **

Batch row operations move to BatchableKVCache (2026-11-07b)

Rebased onto #88's 652c276, which moves the batch row operations from KVCache to the new BatchableKVCache protocol (see #88). New commit fc7cb8a: BatchRotatingKVCache conforms, its row methods no longer override BaseKVCache stubs, and its merge(_:) takes exactly RotatingKVCache rows. mergeCaches maps a RotatingKVCache row to BatchRotatingKVCache; RotatingKVCache loses its merge override that returned any KVCache, and the typed RotatingKVCache.merge(_:) -> BatchRotatingKVCache stays.

Simplicity-rule justification for the new protocol: five conforming types across the stack (BatchKVCache here in #88, BatchRotatingKVCache in #89, ArraysCache (with MambaCache) and CacheList in #90, BatchQuantizedKVCache in #94), used by BatchTokenIterator, which holds its layers as [any BatchableKVCache], and by CacheList, which reaches its children through it. It replaces refusing defaults on KVCache itself.

At this head (fc7cb8a, was 70d26a2):

DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer xcodebuild test -skipPackagePluginValidation \
  -scheme mlx-swift-lm-Package -destination 'platform=macOS' \
  -only-testing:MLXLMTests/BatchRotatingKVCacheTests -only-testing:MLXLMTests/BatchedSlidingWindowParityTests -only-testing:MLXLMTests/KVCacheConfigurationTests

Suite "KV-cache configuration" passed after 0.045 seconds.
Suite BatchedSlidingWindowParityTests passed after 0.660 seconds.
Suite BatchRotatingKVCacheTests passed after 0.923 seconds.
Test run with 73 tests in 3 suites passed after 0.923 seconds.
** TEST SUCCEEDED **

Merge validation and padding-only extraction (2026-11-07c)

Rebased onto #88's 1c399b0. New commit 081b109:

  • BatchRotatingKVCache.extract clamps the slice start to the written range, so a row whose padding is past it comes back empty, with the batch's window, step (allocationStep) and capacity origin. Before, it trapped. A row whose padding exactly reaches the written range already came back as zero-width arrays, and still does (oneTokenRaggedPrefill checks that). The extract reuses the leftPadding[index] and batchOffset[index] values it already read, so it adds no sync. It requires a finalized batch (lengths == nil); BatchableKVCache.extract(_:) now documents that the batch must be finalized: during a ragged prefill, before finalize() moves the right padding, a row's tokens are not yet where extract reads them.
  • RotatingKVCache.merge checks, before extending, that each input holds exactly one row and matches the first prefilled row in head count, head widths and dtype. A mismatch throws KVCacheError; before, it stopped in MLX's concatenate. It uses Add full-attention batch KV caches and checked row operations #88's validateBatchKVRows on the one-row batches it builds, reading only array metadata.

At this head (081b109, was fc7cb8a):

DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer xcodebuild test -skipPackagePluginValidation \
  -scheme mlx-swift-lm-Package -destination 'platform=macOS' \
  -only-testing:MLXLMTests/BatchRotatingKVCacheTests -only-testing:MLXLMTests/BatchedSlidingWindowParityTests -only-testing:MLXLMTests/KVCacheConfigurationTests

Suite "KV-cache configuration" passed after 0.046 seconds.
Suite BatchedSlidingWindowParityTests passed after 0.677 seconds.
Suite BatchRotatingKVCacheTests passed after 1.086 seconds.
Test run with 76 tests in 3 suites passed after 1.086 seconds.
** TEST SUCCEEDED **

Each new test, run alone with this head's tests on the code before the new commit:

-only-testing:MLXLMTests/BatchRotatingKVCacheTests/extractPaddingOnlyRow()
  Swift/arm64e-apple-macos.swiftinterface:18552: Fatal error: Range requires lowerBound <= upperBound
-only-testing:MLXLMTests/BatchRotatingKVCacheTests/extractBeforeFinalize()
  Test "extract refuses a ragged prefill before finalize" recorded an issue at BatchRotatingKVCacheTests.swift:861:32: Expectation failed: expected exit status ".failure", but ".exitCode(EXIT_SUCCESS)" was reported instead
-only-testing:MLXLMTests/BatchRotatingKVCacheTests/mergeRefusesMismatchedRows()
  MLX/ErrorHandler.swift:345: Fatal error: [concatenate] All the input array dimensions must match exactly except for the concatenation axis. However, the provided shapes are (1,1,3,1), (1,1,3,2), and the concatenation axis is 0.

Not done on purpose

Test changes

  • Added (2026-11-07c), each failing before 081b109 (output under Evidence): extractPaddingOnlyRow, extractBeforeFinalize (exit test) and mergeRefusesMismatchedRows in BatchRotatingKVCacheTests. No existing test changes.
  • Added: BatchRotatingKVCacheTests.batchableConformance: RotatingKVCache is not a BatchableKVCache, BatchRotatingKVCache.merge builds the batch from a rotating row, and merging no rows, a KVCacheSimple row or the batch itself throws.
  • Renamed: BatchRotatingKVCacheTests.protocolSurface says "through the BatchableKVCache type"; its assertion is unchanged.
  • Moved, no assertion changes: BatchedSlidingWindowParityTests (two Gemma 3 parity tests) and its helpers (tinyGemma3, mergeRows, filterRows, extractRow, expectExtractedRowsMatch) from BatchedSlidingWindowParityTests.swift to the end of BatchRotatingKVCacheTests.swift; the old file is deleted (aa59f4c). Two lines differ from a plain move:
    • the target file adds @testable import MLXLLM, as the old file had, for the tiny Gemma 3 text model;
    • tinyGemma3() names MLXLLM.Gemma3TextConfiguration, because the target's MLXVLM import declares a Gemma3TextConfiguration of its own.
  • The suite runs the same number of tests before and after the move (counts under Evidence).

AI assistance: the original implementation was developed with Claude Code. Codex implemented review fixes, reorganized the stack, and validated the rebuilt PRs at the maintainer's request for this origin fork. This update (the index check, its test, mlx-vlm references) was made with Claude Code.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T08:00:25.546946Z f26e133 New commits
ℹ️ 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: 2acd927b5d

ℹ️ 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".

ronaldmannak added a commit that referenced this pull request Nov 5, 2026
…rt evictions

A ragged prefill no longer trims the buffer to window - 1 old positions between chunks: a row that was complete lost a real token to every padding-only chunk of the rows still filling, and its extracted window then held padding. The buffer keeps every position until finalize, and the first decode step trims it to the window as before. trim is bounded by maxTrimCount, so it removes nothing once the window has filled instead of moving the ring cursor into negative territory. evictedTokenCount reports the positions the longest row no longer holds (Codex review on #89).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@ronaldmannak

Copy link
Copy Markdown
Owner Author

Re the three Codex findings, all fixed in the latest commit ("Keep completed rows' windows in a ragged prefill, clamp trim and report evictions"), each with a test built from the finding's own scenario:

  • trim after the window fills: trim is now bounded by maxTrimCount, so it returns 0 once the ring has wrapped instead of moving the cursor negative (test: trimAfterWrap).
  • completed rows in a ragged prefill: the concatenating update no longer trims to window - 1 old positions while prepare(lengths:) is in effect; the buffer keeps every position until finalize and the first decode step trims it to the window, so a row that finished at a chunk boundary keeps its full window (test: raggedPrefillKeepsCompletedRows, maxSize 4, lengths [8, 4], two four-token chunks). This is a deliberate deviation from mlx-lm's _update_concat, which has the same loss.
  • evictedTokenCount: overridden as the longest row's position minus the retained positions (test: evictedTokens).

@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: 2a0e49f5e7

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

/// What ``trim(_:)`` removes, while the window has not filled.
public override var maxTrimCount: Int { isTrimmable ? trimLimit : 0 }

P2 Badge Exclude evicted histories from the exact-rewind allowance

When merging a previously wrapped and trimmed source, written is initialized to its retained width rather than its absolute position, so this predicate can advertise exact rewinds after history has already been evicted. For example, write 17 tokens to a window-eight RotatingKVCache, trim two, and merge it: the source correctly reports maxTrimCount == 0, but the batch reports six because written == 6. Consequently, trimPromptCache([batch], numTokens: 1) succeeds even though replaying the removed token cannot recover its original attention window, silently changing continuation results. Account for each row's evicted history when determining the exact-rewind allowance instead of relying only on whether the retained buffer is smaller than the window.

ℹ️ 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".

@ronaldmannak

Copy link
Copy Markdown
Owner Author

Re the three Codex findings, all fixed in the latest commit ("Keep the rotating batch's padding a count, and report rows' positions and evictions"):

  • Padding cancelling after a wrap (:375). The port followed mlx-lm in decrementing leftPadding without a floor as the window filled, so a row's padding went negative and a later ragged prefill (or an extension) added its padding to a negative figure. Padding is now consumed oldest-first and stops at zero, in both updates and in the mask that predicts them, so extract and extend see the real count. New test raggedPrefillAfterWrap is your example: window four, two unpadded rows, five tokens, prepare(lengths: [2, 0]), a two-token chunk with padding for the completed row, finalize. The extracted row now holds its four tokens of history only (it exported [99, 1, 2, 3, 4] before), and the next decode step keeps both rows' windows.
  • Evictions with padding (:242). evictedTokenCount now counts each row's padding against the shared buffer width and takes the maximum. New test evictedTokensWithPadding: a wrapped row widened to nine positions (ten evicted) joins a ten-wide row with one position of padding; the batch reports ten (nine before). The trimmed-source form of your example is not reachable (RotatingKVCache does not trim once wrapped, and merge refuses a rewind reserve), so the test gets its padding from extend.
  • Capped offset (:42). offset is now the longest row's position, counted like RotatingKVCache.offset and like the batched global-attention layers', instead of min(written, window), so KVCacheStorage.inferProcessedTokenCount sees agreeing attention offsets for a merged Gemma 3 cache. Positions are per row (batchOffset), so the setter is a precondition failure rather than a move of the batch; nothing in the library sets a batch cache's offset. evictedTokens now also checks offset against the source row's.

Two more findings from the external review, fixed in the commit after ("Validate rows before a rotating merge, and bound a ragged prefill's buffer"):

  • All-empty merge adopted the first row's configuration. RotatingKVCache.merge now throws KVCacheError unless every row shares one window, allocation step and capacity origin, before either branch; prefilled rows with different windows used to hit extend's precondition instead. mergeRefusesUnbatchableCaches covers empty windows of 8 and 16, prefilled windows of 8 and 16, and steps of 2 and 4.
  • Ragged prefill storage. The concatenating update kept every position until finalize, so the buffer grew to the longest prompt (4096 wide for a 512 window). It now trims a ragged prefill to a full window after rolling the completed rows behind their padding, which is what this chunk gives them, so the buffer stays within a window and a chunk; the mask predicts the same trim. New parameterized test raggedPrefillBoundsStorage (window 4, chunks of 4, lengths [12, 4] and [10, 6], so one row completes at a chunk boundary and one mid-chunk) checks the width never exceeds eight and both rows decode from their correct windows afterwards.

Test changes: evictedTokens gains two offset expectations and mergeRefusesUnbatchableCaches three #expect(throws:); no existing expectation changed.

@ronaldmannak

Copy link
Copy Markdown
Owner Author

Re the Codex finding on the exact-rewind allowance (BatchRotatingKVCache.swift:240): fixed in 5dd2cd3 ("Refuse exact rewinds into a merged row's evicted history"). A batch whose rows have evicted anything is no longer trimmable: isTrimmable(after:) now also requires evictedTokenCount == 0, since a merged row can hold less than a window and still have evicted. New test mergedEvictedRowIsNotTrimmable is your example (17 tokens into a window of eight, trim two, merge): the batch reports nine evictions, maxTrimCount == 0, and canTrimPromptCache/trimPromptCache refuse one token; before the fix it reported maxTrimCount == 6 and trimmed. A merged row with no evictions still rewinds.

@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: a36b53b150

ℹ️ 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".

Comment thread Libraries/MLXLMCommon/KVCacheTree.swift Resolved
@ronaldmannak
ronaldmannak force-pushed the claude/a1-batch-kvcache branch from 634f402 to 93a4bc8 Compare November 6, 2026 03:54
@ronaldmannak
ronaldmannak force-pushed the claude/a2-batch-rotating-kvcache branch from 17a7d50 to 0a4975f Compare November 6, 2026 03:54
@ronaldmannak ronaldmannak changed the title Add BatchRotatingKVCache and RotatingKVCache.merge Add sliding-window batching with BatchRotatingKVCache Nov 6, 2026
@ronaldmannak
ronaldmannak force-pushed the claude/a2-batch-rotating-kvcache branch from 0a4975f to aa59f4c Compare November 6, 2026 20:41
@ronaldmannak
ronaldmannak force-pushed the claude/a1-batch-kvcache branch from 93a4bc8 to 0fea808 Compare November 6, 2026 20:41
@ronaldmannak
ronaldmannak force-pushed the claude/a2-batch-rotating-kvcache branch from aa59f4c to 4392aff Compare November 6, 2026 21:07
@ronaldmannak
ronaldmannak deleted the claude/a2-batch-rotating-kvcache branch November 7, 2026 01:01
@ronaldmannak
ronaldmannak restored the claude/a2-batch-rotating-kvcache branch November 7, 2026 01:02
@ronaldmannak ronaldmannak reopened this Nov 7, 2026
@ronaldmannak
ronaldmannak changed the base branch from batching/a1-batch-kvcache to claude/a1-batch-kvcache November 7, 2026 01:03
@ronaldmannak
ronaldmannak force-pushed the claude/a1-batch-kvcache branch from b6cdd4f to 9c6ef21 Compare November 7, 2026 05:11
@ronaldmannak
ronaldmannak force-pushed the claude/a2-batch-rotating-kvcache branch 2 times, most recently from 70d26a2 to fc7cb8a Compare November 7, 2026 06:25
ronaldmannak and others added 3 commits November 6, 2026 23:42
extract read the row's padding and position through MLXArray subscripts,
which do not trap past the batch: extract(2) on a two-row batch returned a
cache built from out-of-range metadata. It now checks the index with a
precondition, as mlx-vlm's BatchKVCache.extract raises an IndexError; the new
exit test fails without it (the process exits successfully).

The places that follow mlx-vlm's port (lengths filtered with the rows, the
window check and the all-empty merge) cite mlx_vlm/models/cache.py pinned at
mlx-vlm dcea787 next to the existing mlx-lm references.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ests.swift

BatchedSlidingWindowParityTests and its helpers move to the end of
BatchRotatingKVCacheTests.swift; BatchedSlidingWindowParityTests.swift is
deleted. No assertion changes. Two lines differ from a plain move: the target
file now imports MLXLLM (@testable, as the old file did) for the tiny Gemma 3
text model, and tinyGemma3() names MLXLLM.Gemma3TextConfiguration, since the
target's MLXVLM import declares a Gemma3TextConfiguration of its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ronaldmannak and others added 3 commits November 6, 2026 23:42
Keep sliding-window and eviction checks while refusing positive staged writes for negative row positions or zero rows. Preserve empty rounds and verify exact retained state and timeline alignment after supported rollback and partial commit.

AI assistance: implemented and validated with Codex for this origin fork.
The rotating batch's row methods implement BatchableKVCache instead of
overriding BaseKVCache stubs, and its merge takes exactly RotatingKVCache
rows. mergeCaches maps a RotatingKVCache row to BatchRotatingKVCache;
RotatingKVCache itself no longer has a merge that returns any KVCache.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- BatchRotatingKVCache.extract clamps the slice start to the written range, so
  a row whose padding is past it comes back empty with the batch's window, step
  and capacity origin instead of trapping. It requires a finalized batch.
- RotatingKVCache.merge throws KVCacheError before extending when an input
  holds more than one row or differs from the first prefilled row in heads,
  widths or dtype, instead of stopping in concatenation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ronaldmannak and others added 6 commits November 11, 2026 22:51
…ing-kvcache

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Cache storage no longer compares per-row positions, so the storage tests
stop asking it to: the reordered-rows and row-count rejections go, and
the ragged pair is kept as an adoption test at the longest row. The
padded pair now reports 6 and 7 from BatchKVCache.offset, as the rotating
cache already did.

What the removed checks stood for is tested on real operations instead:
the Gemma 3 merge test extends its live batch with two prefilled rows,
removes the longest row, and checks positions on every layer, the
extracted keys and values, and the next logits against solo caches.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The status switch had moved the upstream rotating case to the end and told a sliding window apart by its layer kind. The rotating case is back where main has it, and a rotating batch joins it by type. The capacity check gets back the comment that explains why a requested prefix never matches a batch.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…o it

The switch had been wrapped in an if, which re-indented every upstream line. A rotating batch is now handled inside the default branch, so only that branch changes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

2 participants