Skip to content

Conversation

@tshmilnvidia
Copy link
Collaborator

@tshmilnvidia tshmilnvidia commented Jul 13, 2025

Passing mode & directory parameters to relevant onboard & offload functions.

Summary by CodeRabbit

  • New Features

    • Users can specify KV‑cache transfer mode and optional directory when loading, allocating, onboarding, or offloading cache blocks; generation requests expose these settings.
  • Bug Fixes

    • Transfer mode and directory are now consistently passed through block management and transfer flows.
  • Chores

    • Directory accessor return changed to a const‑reference to avoid unnecessary copies (public API update).

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 21, 2025

📝 Walkthrough

Walkthrough

Adds optional KV-cache transfer mode and directory parameters to block-management APIs and GenerationRequest accessors, and changes KvCacheRetentionConfig::getDirectory() to return a const reference; parameters are threaded through WindowBlockManager, BlockManager, and transfer-manager call sites without altering core logic.

Changes

Cohort / File(s) Change Summary
Batch manager headers
cpp/include/tensorrt_llm/batch_manager/kvCacheManager.h
Extended public signatures in WindowBlockManager and BlockManager to accept executor::KvCacheTransferMode mode = DRAM and std::optional<std::string> directory = std::nullopt. Added GenerationRequest::getTransferMode() and GenerationRequest::getDirectory() accessors (returns const&).
Batch manager implementation
cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp
Threaded mode and directory through implementations and call sites: getFreeBlock, loadOrAllocateBlocks, onboardBlock, offloadBlock, allocation/replacement helpers, and calls into the transfer manager; behavior unchanged aside from parameter passing.
Executor header
cpp/include/tensorrt_llm/executor/executor.h
Changed KvCacheRetentionConfig::getDirectory() return type from std::optional<std::string> (by value) to const std::optional<std::string>&.
Executor implementation
cpp/tensorrt_llm/executor/kvCacheRetentionConfig.cpp
Updated implementation to return mDirectory by const& to match the header change.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant BlockManager
    participant WindowBlockManager
    participant TransferManager

    Client->>BlockManager: onboardBlock(block, windowSize, mode, directory)
    BlockManager->>WindowBlockManager: onboardBlock(block, windowSize, mode, directory)
    WindowBlockManager->>WindowBlockManager: getFreeBlock(..., mode, directory)
    WindowBlockManager->>TransferManager: onboard(block, mode, directory)
Loading
sequenceDiagram
    participant Client
    participant BlockManager
    participant WindowBlockManager
    participant TransferManager

    Client->>BlockManager: offloadBlock(block, windowSize, mode, directory)
    BlockManager->>WindowBlockManager: offloadBlock(block, windowSize, mode, directory)
    WindowBlockManager->>TransferManager: offload(block, 0, mode, directory)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • pcastonguay
  • chuangz0
  • Shixiaowei02
  • Tabrizian
  • nv-guomingz

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 079ae7d and 58a1aac.

📒 Files selected for processing (4)
  • cpp/include/tensorrt_llm/batch_manager/kvCacheManager.h (5 hunks)
  • cpp/include/tensorrt_llm/executor/executor.h (1 hunks)
  • cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp (13 hunks)
  • cpp/tensorrt_llm/executor/kvCacheRetentionConfig.cpp (1 hunks)
👮 Files not reviewed due to content moderation or server errors (4)
  • cpp/include/tensorrt_llm/executor/executor.h
  • cpp/tensorrt_llm/executor/kvCacheRetentionConfig.cpp
  • cpp/include/tensorrt_llm/batch_manager/kvCacheManager.h
  • cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{cpp,cxx,cc,cu,h,hpp,hxx,hh,cuh}

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

**/*.{cpp,cxx,cc,cu,h,hpp,hxx,hh,cuh}: In C++, close namespaces with a comment naming the namespace (e.g., } // namespace foo)
Prefer const/constexpr variables over #define for constants
Declare variables const if not modified after initialization
Use Allman brace style in C++
C++ filenames use lowerCamelCase and must be case-insensitively unique within a build target
C++ type names use UpperCamelCase
Local variables, methods, and namespaces use lowerCamelCase
Global non-static variables not in anonymous namespace use gPrefix lowerCamelCase (e.g., gExample)
Static globals or globals in anonymous namespaces use sPrefix lowerCamelCase
Locally visible static variables start with 's' (e.g., static std::once_flag sFlag;)
Member variables use mPrefix lowerCamelCase; public members may omit but are encouraged to use 'm'
Constants (enums, global/static/function-scope magic numbers) use kPREFIXED_UPPER_SNAKE (e.g., kDIGIT_NUM)
If macros are unavoidable, use UPPER_SNAKE_CASE (prefer constants over #define)
Constructor parameter that conflicts with a public member name gets trailing underscore (foo_)
Literal suffixes should be uppercase (e.g., 1234L not 1234l)
C++: use spaces only; indent 4 spaces
Run clang-format (LLVM style) before submitting; wrap lines at 120 characters
If formatting must be bypassed, use // clang-format off/on around the section
Prefer smart pointers; use unique_ptr for sole ownership, shared_ptr for shared; weak_ptr only in exceptional cases
Do not use deprecated pre-C++11 smart pointers
Use C++ style comments; avoid C comments except special inline cases; prefer // single-line
Capitalize and punctuate full-sentence comments
Follow Doxygen rules: use //! for comments and //!< for members in C++
Disable code with #if/#endif and mnemonic conditions; avoid commented-out code; avoid dead code
Do not throw exceptions across library boundaries
Use least-forceful casts; avoid removing const/volatile; avoid C-style and functional casts (except constructors); p...

Files:

  • cpp/include/tensorrt_llm/executor/executor.h
  • cpp/tensorrt_llm/executor/kvCacheRetentionConfig.cpp
  • cpp/include/tensorrt_llm/batch_manager/kvCacheManager.h
  • cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp
**/*.{h,hpp,hxx,hh,cuh,cpp,cxx,cc,cu}

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

Parameter names must be consistent between declarations and definitions

Files:

  • cpp/include/tensorrt_llm/executor/executor.h
  • cpp/tensorrt_llm/executor/kvCacheRetentionConfig.cpp
  • cpp/include/tensorrt_llm/batch_manager/kvCacheManager.h
  • cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp
**/*.{h,hpp,hxx,hh,cuh}

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

Header files must use include guards named TRTLLM__H without underscores prefix/suffix (e.g., TRTLLM_FOO_BAR_HELLO_H)

Files:

  • cpp/include/tensorrt_llm/executor/executor.h
  • cpp/include/tensorrt_llm/batch_manager/kvCacheManager.h
**/*.{cpp,cxx,cc,cu,h,hpp,hxx,hh,cuh,py}

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

Prepend NVIDIA copyright header (current year) to all source files

Files:

  • cpp/include/tensorrt_llm/executor/executor.h
  • cpp/tensorrt_llm/executor/kvCacheRetentionConfig.cpp
  • cpp/include/tensorrt_llm/batch_manager/kvCacheManager.h
  • cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp
**/*.{cpp,cxx,cc,cu}

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

**/*.{cpp,cxx,cc,cu}: Avoid literal values except for 0, nullptr, true, false; use named constexpr for other literals
Place semicolon of empty for/while loop on a new line
Always use brace-delimited bodies for switch/while/do-for/if/else
Use inline C comments in argument lists when parameter meaning is unclear (e.g., /* checkForErrors = */ false)
Do not use assignment in subexpressions (e.g., if (x = y) ... is forbidden)
Switch on enums should enumerate all values and omit default to catch new values at compile time
Structure switch statements; prohibit fallthrough except between empty cases; each case ends with break or throw; return at end of case not allowed; put break inside braces for compound case
Prefer anonymous namespaces over static for internal linkage of functions
Every defined function must be called at least once (no unused methods)

Files:

  • cpp/tensorrt_llm/executor/kvCacheRetentionConfig.cpp
  • cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Pre-commit Check
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 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.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

return mKvCacheRetentionConfig.getTransferMode();
}

[[nodiscard]] std::optional<std::string> getDirectory() const
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::optional<std::string>& is better.

Copy link
Collaborator

@Shixiaowei02 Shixiaowei02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this also be included in the test, please? Thank you.

@tshmilnvidia tshmilnvidia changed the title Pass mode & directory [None][fix]Pass mode & directory Aug 13, 2025
@tshmilnvidia tshmilnvidia changed the title [None][fix]Pass mode & directory [None][fix] Pass mode & directory Aug 13, 2025
Passing mode & directory parameters to relevant onboard & offload
functions.

Signed-off-by: Tomer Shmilovich <[email protected]>
@glevnv
Copy link
Contributor

glevnv commented Aug 13, 2025

Could this also be included in the test, please? Thank you.

Done

@Shixiaowei02 Shixiaowei02 requested a review from bo-nv August 13, 2025 15:09
@bo-nv
Copy link
Collaborator

bo-nv commented Aug 14, 2025

Could this also be included in the test, please? Thank you.

Done

IIUC, we already have these changes in #5488. can we close this one? @glevnv

@tshmilnvidia
Copy link
Collaborator Author

tshmilnvidia commented Aug 18, 2025

@bo-nv Closing this one, included in #5488

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community want to contribute PRs initiated from Community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants