Repository navigation
feat: add FlashStates hybrid prefix caching - #1806
Merged
Merged
Conversation
Signed-off-by: AlpinDale <alpindale@gmail.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Summary
Integrates GPU-resident FlashStates into Sonar for supported attention/recurrent hybrid models. Context parallelism and custom host-cache tier support through Mooncake will arrive in later PRs.
It's recommended to use this for multi-turn agentic workloads, especially when many long conversations compete for cache space. As an example, this was tested on 2x B300 GPUs:
Performance
What does each option do?
--mamba-frontier-checkpoint: Saves recurrent state at completed request boundaries, including positions between cache-block boundaries.--mamba-prefill-export: Saves additional checkpoints during prefill.--prefix-cache-eviction gds: Chooses eviction candidates using estimated recomputation cost relative to cache space.--prefill-cost-coefficients: Supplies the model’s prefill-cost estimate. The values above are for GLM, not universal defaults.--prefix-cache-leaf-last: Prefers retaining the newest checkpoint for a conversation.--prefix-cache-leaf-idle-seconds 60: Removes that preference after a checkpoint has been idle for 60 seconds. It does not forcibly expire it.If you're not sure what to set the coefficients to,
--prefill-cost-coefficients 1 0will provide you with a linear, although untuned, estimate. More details below.How to tune the cost coefficients
Only the ratio of the two coefficients matter, so users can tune one param:
Rrepresents how much more expensive processing a token becomes as its context grows. Sonar currently has no automatic calibration command.For practical tuning, start with
1 0, which estimates cost purely from token count. Then sweep a few ratios on a representative multi-turn workload:Above aren't actual measured recommendations, so try as many variations as you can to further tune this. Compare output throughput and p90 TTFT under cache pressure. Cache hit rate helps explain the result, but should not be the sole optimization target.
Fitting coefficients from timings
The implemented estimate for prefilling positions
[a, b)is:D: context-independent processing cost per token.E: additional per-token cost per 100,000 tokens of context.For an empirical fit:
Include an intercept C for fixed overhead, with constraints D > 0 and E ≥ 0.
D E, or equivalently1 E/D, and validate against the actual workload. Measured prefill execution time is preferable. Single-request TTFT with one output token is a usable approximation, but includes additional overhead.