Skip to content

Conversation

@nv-kmcgill53
Copy link
Contributor

@nv-kmcgill53 nv-kmcgill53 commented Oct 10, 2025

Summary by CodeRabbit

  • New Features
    • Added support for registering a forward-pass callback that runs immediately after computation, enabling timely cache management/offloading.
    • Enabled CUDA Graphs for scenarios using the KV cache connector, removing prior limitations and allowing graph-captured execution with callbacks.
    • Forward-pass notifications now work consistently across both eager and CUDA Graphs paths, improving throughput and reducing stalls during cache offloading.

Description

This PR enables NVIDIA Dynamo's KV Block Manager to register a forward pass cuda event and associated callback through the connector worker api.

Upon finishing the forward pass, TRTLLM now optionally records a user supplied cuda event on the same stream as the forward pass. Immediately thereafter, the user's provided callback is invoked. which (optionally) waits on the event.

In conjunction with: ai-dynamo/dynamo#3297

Test Coverage

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

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 [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]

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

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--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-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-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.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline 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 in addition to running 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-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

For guidance on mapping tests to stage names, see docs/source/reference/ci-overview.md
and the scripts/test_to_stage_mapping.py helper.

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.

In model_engine.py, during the warmup phase, there is an option for graph capturing
if graph capturing is enabled. This commit adds a lot of logging needed to trace the
calls executing in different parts of TRTLLM, this can be removed later. Ability to
insert an event at the end of the capture and then hold that event on replay is
proven.

Signed-off-by: Kyle McGill <[email protected]>
This update records an event at the end of the forward pass
regardless of whether the forward pass was done in graph_capture
graph_replay, or eager_execution mode. This will allow KVMB to
register cuda events with TRTLLM and then await on them in
different streams

Signed-off-by: Kyle McGill <[email protected]>
Signed-off-by: Kyle McGill <[email protected]>
Signed-off-by: Kyle McGill <[email protected]>
Signed-off-by: Kyle McGill <[email protected]>
Signed-off-by: Kyle McGill <[email protected]>
@nv-kmcgill53 nv-kmcgill53 requested a review from a team as a code owner October 10, 2025 22:36
@nv-kmcgill53 nv-kmcgill53 changed the title Foward pass final event Enable CUDA graph support for KvConnectorWorker API Oct 10, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 10, 2025

📝 Walkthrough

Walkthrough

Introduces a forward-pass CUDA event callback mechanism. Adds an inner ForwardPassCallback class and registration API to KvCacheConnectorWorker. Integrates callback registration and invocation in ModelEngine/PyTorchModelEngine after each forward. Wires registration in py_executor_creator and removes a CUDA graph guard to allow this path.

Changes

Cohort / File(s) Summary
KV cache connector API
tensorrt_llm/_torch/pyexecutor/kv_cache_connector.py
Added KvCacheConnectorWorker.ForwardPassCallback class with callback(); introduced abstract register_forward_pass_callback() returning a ForwardPassCallback tied to a torch.cuda.Event.
Model engine callback integration
tensorrt_llm/_torch/pyexecutor/model_engine.py
Imported KvCacheConnectorWorker; added ModelEngine.register_forward_pass_callback(callback); added PyTorchModelEngine.forward_pass_callback attribute and concrete registration; after forward (eager and CUDA graph), records CUDA event and invokes callback if set.
Executor creator wiring
tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
Removed CUDA-graph guard blocking KV connector hooks; if a KV connector worker is provided, obtains and registers its forward-pass callback with the PyTorch model engine.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant ExecCreator as PyExecutorCreator
  participant Engine as PyTorchModelEngine
  participant CUDA as CUDA Stream/Event
  participant KV as KvCacheConnectorWorker.ForwardPassCallback

  Client->>ExecCreator: create_engine(worker=KvCacheConnectorWorker?)
  alt Worker provided
    ExecCreator->>KV: worker.register_forward_pass_callback()
    KV-->>ExecCreator: ForwardPassCallback
    ExecCreator->>Engine: register_forward_pass_callback(callback)
  end

  loop Each forward
    Client->>Engine: forward(inputs)
    Engine->>CUDA: run forward (eager or CUDA graph)
    Engine->>CUDA: event.record() at end of forward
    alt Callback registered
      Engine->>KV: callback()
    end
    Engine-->>Client: outputs
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description Check ⚠️ Warning The pull request description retains placeholder template comments for the title and CodeRabbit summary instead of providing an actual formatted PR title, and the Test Coverage section is empty despite its heading being present. While the Description and Checklist sections are included, the absence of a filled-out title and missing details on test cases means the submission does not fully adhere to the repository’s required description template. These omissions leave critical context and validation information undefined. Please replace the placeholder title comment with a properly formatted PR title including the ticket or issue identifier and type, fill in the Test Coverage section with relevant test names or descriptions that cover the new functionality, and remove any unused template comments to ensure the description fully matches the repository’s template requirements.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title correctly highlights the introduction of CUDA graph support for the KV connector API, which is a real part of the changeset, but it omits the key addition of forward-pass callback capabilities and uses an imprecise class name. Despite these omissions, it remains partially related to the main work described in the pull request.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2695d70 and 2199b7b.

📒 Files selected for processing (3)
  • tensorrt_llm/_torch/pyexecutor/kv_cache_connector.py (2 hunks)
  • tensorrt_llm/_torch/pyexecutor/model_engine.py (4 hunks)
  • tensorrt_llm/_torch/pyexecutor/py_executor_creator.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Use only spaces, no tabs; indent with 4 spaces.

Files:

  • tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
  • tensorrt_llm/_torch/pyexecutor/kv_cache_connector.py
  • tensorrt_llm/_torch/pyexecutor/model_engine.py
**/*.py

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.py: Python code must target Python 3.8+.
Indent Python code with 4 spaces; do not use tabs.
Maintain module namespace when importing; prefer 'from package.subpackage import foo' then 'foo.SomeClass()' instead of importing the class directly.
Python filenames should be snake_case (e.g., some_file.py).
Python classes use PascalCase names.
Functions and methods use snake_case names.
Local variables use snake_case; prefix 'k' for variables that start with a number (e.g., k_99th_percentile).
Global variables use upper SNAKE_CASE prefixed with 'G' (e.g., G_MY_GLOBAL).
Constants use upper SNAKE_CASE (e.g., MY_CONSTANT).
Avoid shadowing variables from an outer scope.
Initialize all externally visible members of a class in the constructor.
Prefer docstrings for interfaces that may be used outside a file; comments for in-function or file-local interfaces.
Use Google-style docstrings for classes and functions (Sphinx-parsable).
Document attributes and variables inline so they render under the class/function docstring.
Avoid reflection when a simpler, explicit approach suffices (e.g., avoid dict(**locals()) patterns).
In try/except, catch the most specific exceptions possible.
For duck-typing try/except, keep the try body minimal and use else for the main logic.

Files:

  • tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
  • tensorrt_llm/_torch/pyexecutor/kv_cache_connector.py
  • tensorrt_llm/_torch/pyexecutor/model_engine.py
**/*.{cpp,cxx,cc,h,hpp,hh,hxx,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Prepend the NVIDIA Apache-2.0 copyright header with current year to the top of all source files (e.g., .cpp, .h, .cu, .py).

Files:

  • tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
  • tensorrt_llm/_torch/pyexecutor/kv_cache_connector.py
  • tensorrt_llm/_torch/pyexecutor/model_engine.py
🧬 Code graph analysis (3)
tensorrt_llm/_torch/pyexecutor/py_executor_creator.py (2)
tensorrt_llm/_torch/pyexecutor/model_engine.py (1)
  • register_forward_pass_callback (474-476)
tensorrt_llm/_torch/pyexecutor/kv_cache_connector.py (1)
  • register_forward_pass_callback (110-123)
tensorrt_llm/_torch/pyexecutor/kv_cache_connector.py (1)
tensorrt_llm/_torch/pyexecutor/model_engine.py (1)
  • register_forward_pass_callback (474-476)
tensorrt_llm/_torch/pyexecutor/model_engine.py (1)
tensorrt_llm/_torch/pyexecutor/kv_cache_connector.py (4)
  • KvCacheConnectorWorker (82-187)
  • register_forward_pass_callback (110-123)
  • callback (89-93)
  • ForwardPassCallback (84-93)

@pcastonguay pcastonguay requested a review from QiJune October 14, 2025 21:30
nv-kmcgill53 and others added 3 commits October 14, 2025 17:42
This commit changes the API expected by the model engine
to call a user provided callable instead of a predefined
class. The result is a more generic API which others can
program for.

Signed-off-by: Kyle McGill <[email protected]>
@pcastonguay pcastonguay changed the title Enable CUDA graph support for KvConnectorWorker API [None][feat] Enable CUDA graph support for KvConnectorWorker API Oct 15, 2025
@pcastonguay
Copy link
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21479 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

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

@nv-kmcgill53
Copy link
Contributor Author

I'm good to merge this when you all are. Thanks for the help!

@pcastonguay
Copy link
Collaborator

/bot run --disable-fail-fast --add-multi-gpu-test

@pcastonguay
Copy link
Collaborator

/bot kill

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21605 [ kill ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21605 [ kill ] completed with state SUCCESS
Successfully killed previous jobs for commit 70aa387

@pcastonguay
Copy link
Collaborator

/bot run --disable-fail-fast --add-multi-gpu-test

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21636 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

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

@pcastonguay
Copy link
Collaborator

/bot run --disable-fail-fast --add-multi-gpu-test

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21719 [ run ] triggered by Bot. Commit: cd7d101

Copy link
Collaborator

@thorjohnsen thorjohnsen left a comment

Choose a reason for hiding this comment

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

LGTM.

@pcastonguay pcastonguay enabled auto-merge (squash) October 17, 2025 21:45
@tensorrt-cicd
Copy link
Collaborator

PR_Github #21719 [ run ] completed with state SUCCESS. Commit: cd7d101
/LLM/main/L0_MergeRequest_PR pipeline #16367 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

@pcastonguay pcastonguay merged commit 136e0e6 into NVIDIA:main Oct 17, 2025
5 checks passed
govind-ramnarayan pushed a commit to nv-auto-deploy/TensorRT-LLM that referenced this pull request Oct 21, 2025
yufeiwu-nv pushed a commit to yufeiwu-nv/TensorRT-LLM that referenced this pull request Oct 24, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 1, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 3, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 3, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 3, 2025
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.

7 participants