Repository navigation
fix: reject ATOM prefix cache with kv_blocks == lanes + 1 (#172) - #181
Merged
Merged
Conversation
…#172) With one block besides the scratch block per lane, the only cache entry is also the copy source of a prefix hit, so _take(keep=src) found no block, raised "no KV block available" and poisoned the batcher. Prefix caching now needs kv_blocks >= lanes + 2, which always leaves an evictable entry other than the source. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Background
AtomKVBlocksacceptskv_blocks == lanes + 1(one block per lane plus the scratch block). With prefix caching on, a finished request's block becomes the only cache entry; when a new request in that lane shares its prefix,admit()calls_take(keep=src), finds no victim other than the source, raisesRuntimeError("no KV block available"), andstep()poisons the batcher. Repro: batch=1, blocks=2, the same prompt twice.Changes
opt_prime/opt_prime/accel/platforms/atom/batching.py:81-82: withprefix_cache,AtomKVBlocksrequireskv_blocks >= lanes + 2and raisesValueErrorotherwise. When a lane is admitted at mostlanes - 1blocks are held by lanes, solanes + 2blocks always leave an entry other than the copy source (or a free block). TheAtomBatcherdocstring states the requirement.opt_prime/tests/test_atom_batching.py:test_prefix_cache_needs_an_evictable_blockchecks the rejection, and thatkv_blocks == lanes + 1without prefix cache still serves the same prompt twice token-exactly.I chose rejection over reusing the source block in place: it is a two-line change, and with a single cache block the reuse path would only help the exact-repeat case at the cost of extra special cases in
_take/admit(skipping the copy, dropping the index entries, LRU bookkeeping).Verification
CPU only (fake RBLN SDK of the existing tests, no NPU), Python 3.10, torch 2.10.0+cu128, base optimus-rm @253be20.
On the unfixed code (from
opt_prime/):and the issue's repro (same prompt twice, batch=1, blocks=2, prefix cache) fails with
RuntimeError: no KV block availableatbatching.py:172. After the fix the new test passes;tests/test_atom_batching.py tests/test_pd_atom_reuse.py tests/test_pd_native_atom.py: 15 passed, 2 skipped.Whole suite:
Compatibility and limits
prefix_cache=Trueandkv_blocks == batch_size + 1now fail at construction instead of failing on the first prefix hit; they need one more compiled KV block.docs/validation/batching/ATOM.mdalready describeskv_blocks = B + cache + 1.kv_blocks == lanes + 1.Related Issue
Closes #172
🤖 Generated with Claude Code