Prefix caching for PagedAttention
- [x] Prefix cacher handles pagedattention seqs
- [x] Updated sequence logic
- [ ] Updated inputs processing
Currently not working yet.
[!WARNING]
Rate limit exceeded
@EricLBuehler has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 4 seconds before requesting another review.
β How to resolve this issue?
After the wait time has elapsed, a review can be triggered using the
@coderabbitai reviewcommand as a PR comment. Alternatively, push new commits to this PR.We recommend that you space out your commits to avoid hitting the rate limit.
π¦ How do rate limits work?
CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.
π₯ Commits
Reviewing files that changed from the base of the PR and between 01cedfa0921b39f574b8a98c0a554b86676563dd and 378487667c297db3e050abbc3a464a1777b3ee8e.
π Files selected for processing (1)
docs/PAGED_ATTENTION.md(1 hunks)
Walkthrough
This update refactors the PagedAttention and block engine infrastructure to remove explicit lifetime annotations, replacing mutable references with thread-safe, shared ownership via Arc<Mutex<_>>. It introduces new block-based caching mechanisms, updates method signatures for concurrency, and enhances block management. The changes propagate through input processors, sequence management, schedulers, and cache handling, unifying interfaces and improving modularity.
Changes
| File(s) | Change Summary |
|---|---|
src/pipeline/inputs_processor.rs, src/pipeline/mod.rs, src/pipeline/speculative.rs, src/pipeline/speech.rs, src/vision_models/*/inputs_processor.rs |
Removed lifetime parameters from PagedAttentionMeta and related method signatures; updated handling to use owned/shared types. |
src/paged_attention/block_engine.rs, src/dummy_paged_attention/block_engine.rs |
Added Debug, Clone, and Hash to LogicalTokenBlock; added accessors; enhanced allocation logic to support prefilled blocks; fixed CPU allocator flag. |
src/paged_attention/block_engine_sequence.rs, src/dummy_paged_attention/block_engine_sequence.rs |
Changed trait method to return slice of logical blocks; added method for taking prefilled physical blocks. |
src/paged_attention/mod.rs, src/dummy_paged_attention/mod.rs |
Publicly re-exported PhysicalTokenBlock; implemented cache configuration logic. |
src/paged_attention/scheduler.rs, src/dummy_paged_attention/scheduler.rs |
Wrapped BlockEngine in Arc<Mutex<_>>; updated all usages to lock for thread safety; updated method signatures for concurrency. |
src/scheduler/mod.rs, src/scheduler/default_scheduler.rs |
Changed scheduler trait methods to return owned or shared types instead of references; updated for thread safety. |
src/engine/add_request.rs, src/engine/mod.rs |
Updated prefix cache handling to support both normal and paged (block-based) cache variants; improved scheduler/block engine initialization. |
src/sequence.rs |
Added support for physical token blocks in paged attention metadata; added prefill methods; refactored token-to-block logic; updated block engine sequence trait implementation. |
src/prefix_cacher.rs |
Introduced block-based prefix caching; added new cache structures and lookup logic; updated cache manager to support both token and block-based caches. |
src/diffusion_models/processor.rs |
Updated method signatures to remove lifetimes from paged attention metadata. |
src/vision_models/*/inputs_processor.rs |
Updated input processor method signatures to accept owned paged attention metadata. |
mistralrs-quant/src/metal_kernels/mod.rs, mistralrs-quant/src/utils/ops.rs |
Replaced manual ceiling division with div_ceil; minor optimizations and signature simplification. |
Sequence Diagram(s)
sequenceDiagram
participant Client
participant Scheduler
participant BlockEngine
participant PrefixCacheManager
participant Sequence
Client->>Scheduler: Add request (with tokens)
Scheduler->>PrefixCacheManager: search_for_matching_cache(tokens)
alt Block-based cache enabled
PrefixCacheManager->>BlockEngine: Get logical/physical blocks
PrefixCacheManager-->>Scheduler: Return MatchingCache::Paged
else
PrefixCacheManager-->>Scheduler: Return MatchingCache::Normal
end
Scheduler->>BlockEngine: allocate(mut Sequence)
BlockEngine->>Sequence: assign blocks (may use prefilled)
Scheduler->>Sequence: prefill_v2_normal or prefill_v2_paged
Sequence-->>Scheduler: Sequence ready
Poem
In fields of memory, blocks align,
With mutex guards, their fates entwine.
No lifetimes chase the rabbits hereβ
Just shared Arc paths, all crystal clear!
Caches leap, and tokens bound,
Prefilled blocks are hopping 'round.
πβ¨ Rusty dreams, concurrency found!
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
πͺ§ Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>, please review it. -
Explain this complex logic. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai explain this code block. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase. -
@coderabbitai read src/utils.ts and explain its main purpose. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format. -
@coderabbitai help me debug CodeRabbit configuration file.
-
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
-
@coderabbitai pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Code Metrics Report
=============================================================================== Language Files Lines Code Comments Blanks =============================================================================== C Header 3 62 53 0 9 CSS 1 428 366 12 50 Dockerfile 1 41 22 10 9 HTML 1 58 46 4 8 JavaScript 7 1221 915 169 137 JSON 12 107 106 0 1 Makefile 1 6 5 0 1 Python 86 4046 3414 158 474 Shell 1 63 26 18 19 Plain Text 3 3723 0 2413 1310 TOML 20 607 549 10 48 YAML 2 21 19 2 0 ------------------------------------------------------------------------------- Jupyter Notebooks 3 0 0 0 0 |- Markdown 2 77 32 31 14 |- Python 2 205 178 1 26 (Total) 282 210 32 40 ------------------------------------------------------------------------------- Markdown 56 4932 0 3761 1171 |- BASH 9 99 96 0 3 |- JSON 1 12 12 0 0 |- Python 7 121 109 0 12 |- Rust 22 757 634 1 122 |- TOML 2 75 63 0 12 (Total) 5996 914 3762 1320 ------------------------------------------------------------------------------- Rust 386 130170 116052 2765 11353 |- Markdown 178 2235 29 1996 210 (Total) 132405 116081 4761 11563 =============================================================================== Total 583 145485 121573 9322 14590 ===============================================================================