Skip to content

Conversation

zhengd-nv
Copy link
Collaborator

@zhengd-nv zhengd-nv commented Jul 17, 2025

Description

Add delay metrics in KV cache measure helper to track extra TTFT introduced by disaggregated serving. Also add transmission time recording in the generation instance, using the context request id for comparation.

The delay refers to:

  • Context instances: The time period between the first (also the only) token generated and the start time of cache sending.
  • Generation instances: The time period between the arrival of the generation-only request and the start time of cache receiving. This includes generation-side initialization and sending request info to the context instance.

Test Coverage

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

run [--disable-fail-fast --skip-test --stage-list "A10-1, xxx" --gpu-type "A30, H100_PCIe" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-[Post-Merge]-1, xxx"]

Launch build/test pipelines. All previously running jobs will be killed.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-1, xxx". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests. Will also run L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-[Post-Merge]-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-[Post-Merge]-1, xxx".

For guidance on mapping tests to stage names, see docs/source/reference/ci-overview.md.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

Summary by CodeRabbit

  • New Features

    • Enhanced performance metrics tracking for KV cache transfers, including detailed timing, delay, and bandwidth measurements during cache send and receive operations.
    • Performance metrics collection can now be enabled via an environment variable for chat and completion endpoints.
  • Improvements

    • Metrics output now includes delay, duration, and bandwidth for each KV cache transfer, providing more comprehensive insights into system performance.
    • Improved accuracy of transfer size reporting and refined logging for request context IDs.
    • Unified metric helper usage across cache formatters and data transceivers for consistent measurement handling.

Copy link
Contributor

coderabbitai bot commented Jul 17, 2025

📝 Walkthrough

Walkthrough

The changes add conditional delay measurement and reporting for KV cache data transfers in the format and unformat methods of cache formatter classes. The KvCacheMeasureHelper class is enhanced to store detailed metrics including delay, duration, and bandwidth, with sender/receiver distinction. Python server code is updated to enable performance metrics based on an environment variable.

Changes

File(s) Change Summary
cpp/tensorrt_llm/batch_manager/cacheFormatter.cpp
cpp/tensorrt_llm/batch_manager/mlaCacheFormatter.cpp
Added conditional delay measurement and reporting in format and unformat methods; refactored metric reporting to include delay.
cpp/tensorrt_llm/batch_manager/dataTransceiver.h Added nested Measure struct to KvCacheMeasureHelper; updated appendKVCacheTransfer method to include delay; added markAsSender method; changed internal storage and CSV output accordingly.
cpp/tensorrt_llm/batch_manager/cacheFormatter.h
cpp/tensorrt_llm/batch_manager/mlaCacheFormatter.h
Moved kvCacheMeasureHelper member to BaseCacheFormatter; added markAsSender method; removed redundant members from derived classes.
cpp/tensorrt_llm/batch_manager/dataTransceiverImpl.cpp Added calls to markAsSender(true) and markAsSender(false) in constructors of DataSenderImpl and DataReceiverImpl respectively.
tensorrt_llm/serve/openai_server.py Enabled setting sampling_params.return_perf_metrics based on TRTLLM_KVCACHE_TIME_OUTPUT_PATH environment variable in async generation functions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant openai_server.py
    participant CacheFormatter/MLACacheFormatter
    participant KvCacheMeasureHelper

    User->>openai_server.py: Send request
    openai_server.py->>openai_server.py: Check TRTLLM_KVCACHE_TIME_OUTPUT_PATH
    openai_server.py->>CacheFormatter/MLACacheFormatter: Call format/unformat (with return_perf_metrics)
    CacheFormatter/MLACacheFormatter->>KvCacheMeasureHelper: appendKVCacheTransfer(delay, duration, size)
    KvCacheMeasureHelper->>KvCacheMeasureHelper: Store Measure (delay, duration, bandwidth)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 998e177 and 2475ac2.

📒 Files selected for processing (3)
  • cpp/tensorrt_llm/batch_manager/cacheFormatter.h (1 hunks)
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.h (4 hunks)
  • cpp/tensorrt_llm/batch_manager/dataTransceiverImpl.cpp (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • cpp/tensorrt_llm/batch_manager/dataTransceiverImpl.cpp
  • cpp/tensorrt_llm/batch_manager/cacheFormatter.h
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.h
⏰ 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

🪧 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 docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for 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 or @coderabbitai title 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.

@zhengd-nv zhengd-nv changed the title chore: record delay introduced by disaggregated serving in kv cache measure [TRTLLM-6549] chore: record delay introduced by disaggregated serving in kv cache measure Jul 17, 2025
@zhengd-nv
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12183 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12183 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9049 completed with status: 'SUCCESS'

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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 812243b and 3657333.

📒 Files selected for processing (4)
  • cpp/tensorrt_llm/batch_manager/cacheFormatter.cpp (10 hunks)
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.h (4 hunks)
  • cpp/tensorrt_llm/batch_manager/mlaCacheFormatter.cpp (5 hunks)
  • tensorrt_llm/serve/openai_server.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.12.2)
tensorrt_llm/serve/openai_server.py

257-257: Undefined name os

(F821)


410-410: Undefined name os

(F821)

🔇 Additional comments (6)
cpp/tensorrt_llm/batch_manager/mlaCacheFormatter.cpp (2)

111-117: LGTM! Timing logic for cache sending is well-implemented.

The conditional initialization of lastTokenTime and delay calculation properly handles the case when performance metrics are disabled by using a sentinel value.

Also applies to: 236-244


297-311: LGTM! Comprehensive timing implementation for cache receiving.

The code properly:

  • Uses context request ID for tracking generation-side metrics
  • Conditionally tracks arrival time based on performance metrics flag
  • Accumulates sizes correctly across multiple receive operations
  • Records delay from arrival time to cache receive start

Also applies to: 395-441

cpp/tensorrt_llm/batch_manager/dataTransceiver.h (2)

272-294: Well-designed struct for encapsulating KV cache transfer metrics.

The Measure struct effectively groups related metrics with clear documentation of units. The updated appendKVCacheTransfer method signature maintains consistency.


306-324: LGTM! Clear CSV output format for performance metrics.

The updated CSV headers and output formatting correctly reflect the new Measure struct fields with appropriate units.

cpp/tensorrt_llm/batch_manager/cacheFormatter.cpp (2)

169-175: Consistent timing implementation for cache sending.

The delay tracking logic correctly measures the time from last token generation to cache send start, maintaining consistency with the MLA formatter implementation.

Also applies to: 360-368


423-439: Comprehensive timing coverage across all receive paths.

The implementation correctly tracks delays and sizes across all code paths (zero-copy, legacy, and normal), ensuring consistent performance metrics regardless of the transfer method used.

Also applies to: 656-724

@zhengd-nv zhengd-nv marked this pull request as ready for review July 18, 2025 05:57
@zhengd-nv
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12282 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12282 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9121 completed with status: 'FAILURE'

@zhengd-nv
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12406 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12406 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9223 completed with status: 'FAILURE'

@zhengd-nv
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12415 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12415 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9231 completed with status: 'FAILURE'

@zhengd-nv
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12428 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12428 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9241 completed with status: 'FAILURE'

@zhengd-nv
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12449 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12449 [ run ] completed with state FAILURE

@zhengd-nv
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12493 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12493 [ run ] completed with state FAILURE

@Shunkangz
Copy link
Collaborator

LGTM. As @pcastonguay said, let's merge this PR first and then after we merge the customer's metric PR, we can see how to refactor this part and make it clean.

@Shixiaowei02
Copy link
Collaborator

Thanks for your work. I do have some confusion regarding the isContext() member and would appreciate if that part could be adjusted. Everything else looks good to me.

@zhengd-nv
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13002 [ run ] triggered by Bot

@zhengd-nv
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13124 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13124 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9822 completed with status: 'FAILURE'

@zhengd-nv
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13164 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13164 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9858 completed with status: 'FAILURE'

@zhengd-nv
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13337 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13337 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9968 completed with status: 'SUCCESS'

@Shixiaowei02 Shixiaowei02 merged commit c9ed1ab into NVIDIA:main Jul 30, 2025
3 checks passed
lancelly pushed a commit to lancelly/TensorRT-LLM that referenced this pull request Aug 6, 2025
… in kv cache measure (NVIDIA#6135)

Signed-off-by: zhengd-nv <[email protected]>
Signed-off-by: Lanyu Liao <[email protected]>
jain-ria pushed a commit to jain-ria/TensorRT-LLM that referenced this pull request Aug 7, 2025
@zhengd-nv zhengd-nv deleted the pd-record-delay branch August 11, 2025 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants