Skip to content

Conversation

richardhuo-nv
Copy link
Contributor

@richardhuo-nv richardhuo-nv commented Aug 25, 2025

Summary by CodeRabbit

  • New Features

    • Pluggable KV-cache connector: config, Python bindings, runtime hooks, and optional executor integration for prefetching/loading/saving KV blocks (sync/async).
    • Public API extended to accept an optional KV connector and to expose a method to retrieve the unique primary KV pool for single-window setups.
  • Documentation

    • Added a self-contained example demonstrating on-disk KV cache persistence and a CLI demo.
  • Tests

    • New unit and integration tests covering scheduler behavior, async load/save, multi-rank coordination, and the example workflow.

Description

Supersedes #6488. Rebased onto latest main.

This is a first implementation of a KV connector API in TRTLLM. See https://docs.google.com/document/d/104jQ_Qhx5-rb1d-8ZBSN-jYQESaRjNJVhJoT3X7_KGw/edit?tab=t.0#heading=h.dh5skq4lgud6 for details. This is a very limited initial implementation, so a couple caveats:

  1. Doesn't support VSWA or cuda graphs
  2. Only supports the pytorch runtime
  3. Probably doesn't work with peft, lora, etc.

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 [--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.

Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
…t inside py_executor_creator, pass connector manager to kv cache manager

Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
@tensorrt-cicd
Copy link
Collaborator

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

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
tensorrt_llm/_torch/pyexecutor/py_executor_creator.py (2)

239-239: Fix logging call (args vs format string).

Passing a second positional arg without a %s will raise at runtime.

-    logger.info("ATTENTION RUNTIME FEATURES: ", attn_runtime_features)
+    logger.info("ATTENTION RUNTIME FEATURES: %s", attn_runtime_features)

187-191: Remove redundant LoadFormat import and unify its usage

  • At lines 187–188, delete the inner from tensorrt_llm.llmapi.llm_args import LoadFormat—reuse the top-level LoadFormat import
  • spec_config.load_format is declared as Union[str, LoadFormat]; comparing it directly to "dummy" may misfire when it’s an enum. Normalize to the enum (e.g. if spec_config.load_format == LoadFormat.DUMMY) or coerce string values into the LoadFormat enum for consistency
♻️ Duplicate comments (1)
tensorrt_llm/_torch/pyexecutor/py_executor_creator.py (1)

386-398: Disallow transceiver + connector early (repeat of prior feedback).

Connector is incompatible with KvCacheTransceiver; fail fast.

         if executor_config.scheduler_config.capacity_scheduler_policy != CapacitySchedulerPolicy.GUARANTEED_NO_EVICT:
             raise NotImplementedError(
                 "KV connector is only supported with guaranteed no evict scheduler policy."
             )
 
+        # Preemptively disallow transceiver + connector
+        if executor_config.cache_transceiver_config is not None:
+            raise NotImplementedError(
+                "KV Cache Connector is not supported together with KvCacheTransceiver."
+            )
🧹 Nitpick comments (2)
tensorrt_llm/_torch/pyexecutor/py_executor_creator.py (2)

15-17: Optional: prefer module import to preserve namespace.

Using direct symbol imports leaks many names; consider importing the module and qualifying usage.

-from tensorrt_llm.bindings.executor import (CapacitySchedulerPolicy,
-                                            ContextChunkingPolicy,
-                                            ExecutorConfig)
+import tensorrt_llm.bindings.executor as executor_bindings

Follow-ups (outside this hunk):

  • Replace references: CapacitySchedulerPolicy → executor_bindings.CapacitySchedulerPolicy, ContextChunkingPolicy → executor_bindings.ContextChunkingPolicy, ExecutorConfig → executor_bindings.ExecutorConfig.

386-389: Avoid logging full connector config (may contain sensitive fields).

Log module/class identifiers instead.

-        logger.info(
-            f"Initializing kv connector with config: {kv_connector_config}")
+        logger.info(
+            "Initializing KV connector: module=%s worker=%s scheduler=%s",
+            kv_connector_config.connector_module,
+            kv_connector_config.connector_worker_class,
+            kv_connector_config.connector_scheduler_class,
+        )
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0126e6f and aa1b9a0.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/pyexecutor/py_executor_creator.py (8 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.py: Code must target Python 3.8+
Indent Python code with 4 spaces; do not use tabs
Preserve module namespaces when importing; import modules/packages and access members via the module (e.g., from package.subpackage import foo; foo.SomeClass())
Python file names should be snake_case
Python class names should be PascalCase
Python functions/methods and local variables should be snake_case; variables beginning with a number should be prefixed with k_ (e.g., k_99th_percentile)
Global variables should be UPPER_SNAKE_CASE prefixed with G_ (e.g., G_MY_GLOBAL); constants should be UPPER_SNAKE_CASE
Avoid shadowing variables from outer scopes; initialize all externally visible members in init
Prefer docstrings for interfaces used outside a file; comments should be reserved for in-function or file-local interfaces
Use Google-style docstrings for classes and functions; attributes and variables may be documented inline with trailing string literals
Avoid reflection when simpler, explicit code suffices (e.g., avoid dict(**locals()) patterns)
In try/except, catch the narrowest exceptions possible
For duck-typing patterns, keep the try body minimal and move logic to else to avoid masking unrelated failures

Files:

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

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Prepend the NVIDIA copyright header (current year) to all source files (.cpp, .h, .cu, .py, etc.)

Files:

  • tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
🧠 Learnings (1)
📚 Learning: 2025-08-26T09:37:10.463Z
Learnt from: jiaganc
PR: NVIDIA/TensorRT-LLM#7031
File: tensorrt_llm/bench/dataclasses/configuration.py:90-104
Timestamp: 2025-08-26T09:37:10.463Z
Learning: In TensorRT-LLM, the `get_pytorch_perf_config()` method returns `self.pytorch_config` which can contain default `cuda_graph_config` values, so `llm_args` may already have this config before the extra options processing.

Applied to files:

  • tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
🪛 Ruff (0.12.2)
tensorrt_llm/_torch/pyexecutor/py_executor_creator.py

408-408: Line too long (131 > 120)

(E501)

⏰ 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
🔇 Additional comments (10)
tensorrt_llm/_torch/pyexecutor/py_executor_creator.py (10)

3-4: LGTM: required imports for connector initialization.


19-19: LGTM: KvCacheConnectorConfig import.


34-34: LGTM: KvCacheConnectorManager import.


415-421: LGTM: instantiate connector scheduler only on rank 0.

This satisfies the manager invariant and avoids cross-rank assertions.


439-445: LGTM: pass KvCacheConnectorManager into KvCacheCreator.

Plumbs connector into KV manager build path.


449-449: LGTM: estimation path integrates with connector-aware managers.


485-487: LGTM: avoid activating connector during estimation.

Passing None during estimating prevents premature hooks.


503-504: LGTM: finalize manager build post-estimation.


530-531: LGTM: connector attached for the final executor.


215-217: Audit completed: no internal call sites found
Default kv_connector_config=None preserves backward compatibility.

@pcastonguay
Copy link
Collaborator

@Shixiaowei02 could you approve this MR? It's a duplicate of #6488, which was moved to a new branch since John Thompson is no longer at Nvidia.

@pcastonguay
Copy link
Collaborator

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #16885 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #16885 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #12682 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: 3

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between aa1b9a0 and e5e5114.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/pyexecutor/py_executor.py (10 hunks)
  • tensorrt_llm/executor/worker.py (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-26T09:37:10.463Z
Learnt from: jiaganc
PR: NVIDIA/TensorRT-LLM#7031
File: tensorrt_llm/bench/dataclasses/configuration.py:90-104
Timestamp: 2025-08-26T09:37:10.463Z
Learning: In TensorRT-LLM, the `get_pytorch_perf_config()` method returns `self.pytorch_config` which can contain default `cuda_graph_config` values, so `llm_args` may already have this config before the extra options processing.

Applied to files:

  • tensorrt_llm/executor/worker.py
🧬 Code graph analysis (1)
tensorrt_llm/executor/worker.py (1)
tensorrt_llm/llmapi/llm_args.py (1)
  • KvCacheConnectorConfig (407-419)
⏰ 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
🔇 Additional comments (3)
tensorrt_llm/executor/worker.py (3)

21-21: Consolidated import looks good.

Single import of KvCacheConnectorConfig, PybindMirror, TorchLlmArgs resolves the prior duplication.


135-135: create_py_executor signature includes kv_connector_config
The function create_py_executor in tensorrt_llm/_torch/pyexecutor/py_executor_creator.py defines the kv_connector_config parameter, so supplying this kwarg is supported.


689-689: No action required: kv_connector_config already defaults to None, preserving backward compatibility.

@pcastonguay
Copy link
Collaborator

/bot skip --comment "CI passes before automatic merge of main"

@yuanjingx87
Copy link
Collaborator

/bot reuse-pipeline

@tensorrt-cicd
Copy link
Collaborator

PR_Github #16920 [ reuse-pipeline ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #16920 [ reuse-pipeline ] completed with state FAILURE
Can't reuse PR_Github #16885 with status: SUCCESS

@pcastonguay
Copy link
Collaborator

/bot skip --comment "Getting ridiculous..."

@tensorrt-cicd
Copy link
Collaborator

PR_Github #16928 [ skip ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #16928 [ skip ] completed with state SUCCESS
Release Check Pipeline #1847 failed

@chzblych
Copy link
Collaborator

/bot skip --comment "Previously passed"

@chzblych chzblych enabled auto-merge (squash) August 29, 2025 02:41
@tensorrt-cicd
Copy link
Collaborator

PR_Github #16932 [ skip ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #16932 [ skip ] completed with state SUCCESS
Skipping testing for commit e5e5114

@chzblych chzblych merged commit ce580ce into NVIDIA:main Aug 29, 2025
7 checks passed
@juney-nvidia juney-nvidia removed the Community want to contribute PRs initiated from Community label Aug 29, 2025
chang-l pushed a commit to chang-l/TensorRT-LLM that referenced this pull request Sep 2, 2025
Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: richardhuo-nv <[email protected]>
Co-authored-by: jthomson04 <[email protected]>
Co-authored-by: Iman Tabrizian <[email protected]>
Co-authored-by: Sharan Chetlur <[email protected]>
@yoo-kumaneko
Copy link

yoo-kumaneko commented Sep 4, 2025

See https://docs.google.com/document/d/104jQ_Qhx5-rb1d-8ZBSN-jYQESaRjNJVhJoT3X7_KGw/edit?tab=t.0#heading=h.dh5skq4lgud6 for details.

@richardhuo-nv This document is restricted. Could you make it publicly readable?

@richardhuo-nv
Copy link
Contributor Author

See https://docs.google.com/document/d/104jQ_Qhx5-rb1d-8ZBSN-jYQESaRjNJVhJoT3X7_KGw/edit?tab=t.0#heading=h.dh5skq4lgud6 for details.

@richardhuo-nv This document is restricted. Could you make it publicly readable?

I don't own this doc either. Let me try to generate a snapshot of the doc.

@richardhuo-nv
Copy link
Contributor Author

See https://docs.google.com/document/d/104jQ_Qhx5-rb1d-8ZBSN-jYQESaRjNJVhJoT3X7_KGw/edit?tab=t.0#heading=h.dh5skq4lgud6 for details.

@richardhuo-nv This document is restricted. Could you make it publicly readable?

https://drive.google.com/file/d/1L_Dave6C1ullxJNifmBBzw6kjWMvKO54/view?usp=sharing
I exported as pdf for publicly readable. Thanks!

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.