[HiCache] feat: add draft KV cache backing for L2/L3#21125
[HiCache] feat: add draft KV cache backing for L2/L3#21125xiezhq-hermann merged 17 commits intosgl-project:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a draft KV cache backing for the HiCache system, specifically targeting L2/L3 caches. This enhancement addresses a regression issue in speculative decoding where the draft model could see stale or incorrect slot indices after a load_back operation. The changes ensure that the draft KV pool is properly synchronized with the main KV cache, improving the accuracy and stability of speculative decoding. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for backing up the draft model's KV cache to L2 (host) and L3 (storage) when using HiCache with speculative decoding. This is achieved by a new HiCacheDraftMixin that hooks into HiCache's data movement operations (write, load, evict) to synchronize the draft KV cache with the main model's KV cache. The changes are well-integrated into HiRadixCache and HiMambaRadixCache. My main feedback is to refactor a piece of duplicated logic in the scheduler for better maintainability.
|
/rerun-failed-ci 1 |
|
can this work for eagle3? |
yes. but may not work well for multi-layer eagle |
|
/tag-and-rerun-ci |
|
Thanks for this work. Is this pr compatible with DSA model (#21259) ? |
|
/rerun-failed-ci |
ec43b6d to
3cfdf1a
Compare
3cfdf1a to
ec43b6d
Compare
ec43b6d to
3cfdf1a
Compare
|
/rerun-test test_hicache_storage.py test_hicache_variants.py test_hicache_storage_3fs_backend.py test_hicache_storage_file_backend.py test_hicache_storage_mooncake_backend.py test_hicache_storage_runtime_attach_detach.py test_hicache_spec_file_storage.py |
|
✅ ✅ ✅ |
ALL hicache ci passed & local ci passed |

Motivation
see #16964
Root Cause
In speculative decoding, the draft and target models share a
req_to_token_pool(KV cache index mapping) but maintain separate KV cache pools.When both HiCache and speculative decoding are enabled, the target KV cache may be loaded back from L2/L3. The shared index table is updated accordingly, but the draft model’s KV cache is not updated. As a result, the draft model reads incorrect KV, leading to accept length regression.
A natural alternative would be to re-run draft prefill to regenerate its KV cache after the target
load_back. However, in speculative decoding the draft prefill depends on target hidden states (fc(concat(embed(token_{i+1}), target_hidden_state_i))). When KV is loaded back from L2/L3, the target prefill stage is skipped and the full hidden states are not produced, so the draft model cannot perform prefill.Solution
This PR supports paired offload/load_back of the target and draft KV caches to/from L2/L3 (based on #17338).
How wo reproduce:
benchmark result before this feature(draft L2/L3kvcache):
benchmark result after this feature(draft L2/L3kvcache):
accelt length 3.07->6.94
Modifications
Accuracy Tests
Benchmarking and Profiling
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci