Repository navigation
feat(scheduler): add radix_lookahead keys to the prefix cache - #834
Merged
Merged
Conversation
6 of 8 tasks
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.
Refs #828
Part of the speculative decoding plan in #828; it can merge independently of the seams PR. Nothing turns it on in this PR:
radix_lookaheaddefaults toFalse, and the MTP PR turns it on for MTP drafts. The full stack is in the draft PoC #832.Summary
Adds
radix_lookahead: booltoCacheManager. Withradix_lookahead=True, the prefix cache keys position i by the token pair (t_i, t_{i+1}) instead of t_i (a lookahead key).Why
An MTP draft's KV at position i is computed from the target's hidden state at i and the token at i+1. With token keys, a prefix hit can reuse a draft KV slot that was written for a different next token: when two cached requests share a prefix and then fork, the slot just before the fork may come from the other branch. With lookahead keys, a hit also has to match the token after each position, so every draft KV slot it reuses was written for the same next token. The cost: where a query forks from a cached path, its hit ends one position before the fork, then rounds down to a page (a whole page when the fork is page-aligned); a query that continues a cached path, such as the next turn of a conversation, hits as far as with token keys.
Design
CacheManager._keys(ids, n)returns the radix keys of the first n positions: the ids themselves whenradix_lookaheadis off, otherwise each id packed with the next one into an int64 (ids stay below 2^31, multimodal pseudo ids included). A position whose next token is not known yet has no lookahead key, so the keys can be one shorter than n._keys, except in the SWA radix cache, which keeps token keys;radix_lookahead=Truewith it fails an assert.Tests
tests/scheduler/test_radix_lookahead.py(CPU, realCacheManagerand radix trees):Test environment
Results
The new test file on its own (CPU):
5 passed.
Unit tests, with
radix_lookaheadleft off everywhere outside the new test:1586 passed, 202 skipped, 1 failed. The failure is
tests/models/test_quant_config.py::test_scheme_for_agrees_with_the_stored_tensors[apodex/Apodex-1.1-mini-NVFP4[index-only]](a local checkpoint withquant_method: modelopt_mixed); it fails the same way on main 408e6ae.Smoke test on this branch, passed: