Skip to content

feat: Using NIXL for KV cache transfer when using disaggregated serving in TRTLLM #1591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

tanmayv25
Copy link
Contributor

@tanmayv25 tanmayv25 commented Jun 18, 2025

Updates build scripts to allow users to conveniently use NIXL for KV cache transfer when using dynamo with TRTLLM.

Summary by CodeRabbit

  • New Features

    • Added experimental support for disaggregated serving with KV cache transfer using NIXL in TensorRT-LLM.
    • Introduced a build flag to enable NIXL-based KV cache transfer.
  • Documentation

    • Updated instructions to explain how to enable and use NIXL for KV cache transfer.
    • Provided detailed steps for building, running, and switching between NIXL and UCX methods.
  • Chores

    • Improved build scripts to support new experimental options and environment variable management.

Copy link
Contributor

coderabbitai bot commented Jun 18, 2025

Walkthrough

The changes introduce an experimental NIXL-based KV cache transfer method for TensorRT-LLM, affecting the Dockerfile, build scripts, and documentation. New build arguments, environment variable management, and command-line flags were added to enable or disable this feature. The documentation now details how to use and switch between UCX and NIXL KV cache transfer methods.

Changes

File(s) Change Summary
container/Dockerfile.tensorrt_llm Added build arg ARCH_ALT, updated LD_LIBRARY_PATH, and introduced conditional environment variable setup for UCX/NIXL KV cache; added runtime env script.
container/build.sh Added --trtllm-use-nixl-kvcache-experimental flag, passed build arg to Docker, updated help message, and passed NIXL commit to wheel build.
container/build_trtllm_wheel.sh Added -n option for NIXL commit, copied and patched install_nixl.sh, changed build to two-step with NIXL support.
examples/tensorrt_llm/README.md Replaced "Future Work" with detailed instructions for enabling/disabling NIXL KV cache transfer; clarified environment variable usage.

Poem

In the warren of containers, a clever new trick,
With NIXL and UCX, choose your cache quick!
Scripts now smarter, flags in a row,
Docs guide your journey on which way to go.
🐇✨ Toggle and build, KV cache in flight—
The rabbit’s delighted, the future looks bright!


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.
    • 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 @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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 anywhere in the PR title to generate the title automatically.

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
examples/tensorrt_llm/README.md (2)

309-311: Fix grammar in Note about production suitability
The phrase “is not be suitable” is incorrect. Please update to “is not suitable” or “may not be suitable.”


335-336: Add missing article for clarity
Change “built in previous step” to “built in the previous step.”

container/build.sh (1)

523-526: Allow overriding NIXL commit in build.sh
Currently, build.sh always passes its internal NIXL_COMMIT to the wheel builder. To support custom NIXL commits, consider adding a CLI option (e.g. --nixl-commit) that updates NIXL_COMMIT before invoking build_trtllm_wheel.sh.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dd3c470 and 057f01d.

📒 Files selected for processing (4)
  • container/Dockerfile.tensorrt_llm (1 hunks)
  • container/build.sh (5 hunks)
  • container/build_trtllm_wheel.sh (3 hunks)
  • examples/tensorrt_llm/README.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
examples/tensorrt_llm/README.md

[grammar] ~311-~311: It seems that the verb “be” is not needed here.
Context: ...NIXL support is experimental and is not be suitable for production environments. #### Usin...

(BE_NOT_BE_JJ)


[uncategorized] ~335-~335: You might be missing the article “the” here.
Context: ...w to start the container image built in previous step. 3. **Start the disaggregated ser...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and Test - vllm
🔇 Additional comments (13)
container/Dockerfile.tensorrt_llm (4)

327-329: Ensure correct NIXL library path injection
The ARG ARCH_ALT and the prepend to LD_LIBRARY_PATH properly direct the runtime linker to the NIXL libraries based on CPU architecture.


331-337: Conditional environment variable for KV cache transfer
The RUN block correctly appends either TRTLLM_USE_NIXL_KVCACHE=1 or TRTLLM_USE_UCX_KVCACHE=1 to /etc/environment based on the experimental flag.


338-346: Generate runtime script for KV cache mode
The set_trtllm_env.sh script creation and permission setting correctly exports the chosen variable at container startup.


347-349: Source the KV cache script in shell initialization
Appending the source command to .bashrc ensures the environment variable is loaded for interactive sessions.

examples/tensorrt_llm/README.md (1)

301-302: Document NIXL experimental section header
The new section header clearly identifies the experimental NIXL KV cache transfer instructions.

container/build_trtllm_wheel.sh (4)

21-26: Add -n option for specifying NIXL commit
The new getopts block correctly parses -n into NIXL_COMMIT.


27-32: Update usage message to include -n flag
The usage instructions now properly document the -n: NIXL commit option.


41-43: Capture script directory for relative paths
Defining MAIN_DIR ensures subsequent file operations use a stable absolute path.


93-96: Split build into Triton devel and wheel stages
The two-step make tritondevel_build then make wheel_build with NIXL_ROOT correctly integrates NIXL during wheel compilation.

container/build.sh (4)

93-93: Declare default experimental flag
Setting TRTLLM_USE_NIXL_KVCACHE_EXPERIMENTAL="0" provides a clear default for the build argument.


170-176: Handle --trtllm-use-nixl-kvcache-experimental CLI option
The new case branch properly validates no argument is passed and sets the internal flag.


375-376: Document the new experimental flag in help
The help text now includes --trtllm-use-nixl-kvcache-experimental.


504-507: Pass NIXL flag as Docker build argument
Adding --build-arg TRTLLM_USE_NIXL_KVCACHE_EXPERIMENTAL ensures the Dockerfile sees the correct value.

Co-authored-by: Ryan McCormick <rmccormick@nvidia.com>
Signed-off-by: Tanmay Verma <tanmay2592@gmail.com>
Co-authored-by: Ryan McCormick <rmccormick@nvidia.com>
Signed-off-by: Tanmay Verma <tanmay2592@gmail.com>
Co-authored-by: Ryan McCormick <rmccormick@nvidia.com>
Signed-off-by: Tanmay Verma <tanmay2592@gmail.com>
Comment on lines +347 to +348
unset TRTLLM_USE_NIXL_KVCACHE
export TRTLLM_USE_UCX_KVCACHE=1
Copy link
Contributor

@rmccorm4 rmccorm4 Jun 18, 2025

Choose a reason for hiding this comment

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

Is it worth adding all this extra build logic, flags, documentation, etc. if we can just boil down the opt-in steps to something like this?


NIXL (Experimental)

To use NIXL for KV Cache transfer instead of UCX, set the relevant environment variables:

export TRTLLM_USE_NIXL_KVCACHE=1
export TRTLLM_USE_UCX_KVCACHE=0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are currently using the TensorRT-LLM wheel from pyPI by default. This has reduced the container build time considerably. However, these public wheels are not build with NIXL support.

Currently, there is no way around rebuilding the TRTLLM wheel from scratch with some extra flags if someone wants to use NIXL. We could have enabled NIXL by default but it would have undermined our build time optimization from using pyPI TRTLLM wheels. Once NIXL in TRTLLM is mature enough and available in TRTLLM wheels on pypi, we can simplify instructions to what you have mentioned above.
In this section, I just wanted to point out that TRTLLM wheels built with NIXL support can also be used to use UCX instead.

@tanmayv25 tanmayv25 requested a review from rmccorm4 June 19, 2025 01:30
@tanmayv25 tanmayv25 enabled auto-merge (squash) June 19, 2025 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants