Skip to content

Conversation

@jthomson04
Copy link
Collaborator

@jthomson04 jthomson04 commented Oct 29, 2025

Fixes two separate issues:

  • When multiple requests performing async saving with the kv connector finish at the same iteration, their KV cache may not be deallocated.
  • The kv transfer timeout is broken

Summary by CodeRabbit

  • Bug Fixes

    • Fixed request completion handling to ensure all finished requests receive proper cleanup and state updates simultaneously. Previously, only the first completed request in a batch would be fully processed, leaving others with incomplete cleanup procedures.
  • Tests

    • Added comprehensive test coverage for multi-request scenarios, including concurrent request processing with caching and advanced scheduling patterns.

Description

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.

@jthomson04 jthomson04 requested a review from a team as a code owner October 29, 2025 04:45
@jthomson04
Copy link
Collaborator Author

/bot run

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

📝 Walkthrough

Walkthrough

Modified request termination loop in the KV connector executor to process all finished requests instead of breaking after the first one, and updated the test suite with refactored LLM constructor logic and a new multi-request connector test.

Changes

Cohort / File(s) Summary
KV Connector Executor Loop
tensorrt_llm/_torch/pyexecutor/py_executor.py
Removed break statement in _kv_connector_terminate_requests loop, allowing completion logic (block unpinning, state updates) to execute for all finished requests in a single call instead of only the first one.
Test Suite Updates
tests/integration/defs/llmapi/test_llm_api_connector.py
Refactored LLM constructor invocation to centralize default keyword arguments before merging with caller-provided kwargs. Added new test function test_connector_multi_request covering multi-request scenarios with KV cache behavior and overlap scheduling.

Sequence Diagram(s)

sequenceDiagram
    rect rgb(240, 248, 255)
    note over py_executor: Before: Early Exit
    py_executor->>py_executor: Process finished_request[0]
    py_executor->>py_executor: break (exit loop)
    note over py_executor: Remaining requests unprocessed
    end
    
    rect rgb(245, 245, 220)
    note over py_executor: After: Process All
    py_executor->>py_executor: Process finished_request[0]
    py_executor->>py_executor: continue (next iteration)
    py_executor->>py_executor: Process finished_request[1]
    py_executor->>py_executor: continue (next iteration)
    py_executor->>py_executor: ... (all requests processed)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • py_executor.py: The removal of the break statement represents a behavioral change to request termination logic. Review should verify that processing all requests in a single loop iteration is the intended behavior and doesn't introduce race conditions or state management issues with concurrent requests.
  • test_llm_api_connector.py: The new test_connector_multi_request test needs careful inspection to ensure mocks and side effects accurately reflect multi-request scheduling and KV cache handling; verify alignment with the executor behavior change.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ⚠️ Warning The PR description is incomplete and lacks required sections from the template including detailed explanation of issues, solutions, and test coverage. Complete the 'Description' and 'Test Coverage' sections with details about the KV cache clearing issues, the solutions implemented, and specific tests validating the fixes.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title follows the required template format with [None] for no ticket and [fix] for the type. It clearly summarizes the main change from the raw summary: fixing KV cache clearing in the KV Connector API. The change removes a break statement in _kv_connector_terminate_requests to process all finished requests instead of terminating after the first one, and the title accurately reflects this fix at a high level. The phrasing is concise and specific enough that a developer reviewing the history would understand this addresses a KV cache cleanup issue with the Connector API.
✨ 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: 0

🧹 Nitpick comments (2)
tests/integration/defs/llmapi/test_llm_api_connector.py (2)

405-426: Good test coverage for multi-request KV cache cleanup.

This test effectively validates the PR fix by exercising the scenario where multiple requests must finish in the same iteration and have their KV cache freed before a subsequent large request can proceed.

Test logic:

  • First batch: 2 requests consuming ~103 tokens total
  • Third request: 110 tokens, would fail without proper cleanup (max_tokens=120)

The mock setup with side_effect echoing finished requests is a clean approach to simulate async save behavior.

Consider adding explicit assertions to strengthen the regression test:

     # The KV cache of both prior requests should be freed, allowing the third request to run.
     model.generate([2] * 110, sampling_params=sampling_params)
+    
+    # Verify both prior requests were marked as finished
+    assert scheduler.request_finished.call_count == 3

1-1: Consider updating copyright year to include 2025.

The copyright header currently shows "2022-2024" but modifications are being made in 2025. Per coding guidelines, consider updating to "2022-2025".

-# SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
📜 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 5f737b8 and 1de3035.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/pyexecutor/py_executor.py (0 hunks)
  • tests/integration/defs/llmapi/test_llm_api_connector.py (2 hunks)
💤 Files with no reviewable changes (1)
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
🧰 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:

  • tests/integration/defs/llmapi/test_llm_api_connector.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:

  • tests/integration/defs/llmapi/test_llm_api_connector.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:

  • tests/integration/defs/llmapi/test_llm_api_connector.py
🧬 Code graph analysis (1)
tests/integration/defs/llmapi/test_llm_api_connector.py (3)
tensorrt_llm/llmapi/llm_args.py (1)
  • KvCacheConfig (1246-1390)
tensorrt_llm/llmapi/llm.py (2)
  • LLM (1103-1119)
  • generate (259-341)
tensorrt_llm/_torch/pyexecutor/kv_cache_connector.py (6)
  • get_num_new_matched_tokens (196-210)
  • get_num_new_matched_tokens (412-436)
  • request_finished (213-224)
  • request_finished (483-507)
  • get_finished (158-174)
  • get_finished (509-558)
🪛 Ruff (0.14.2)
tests/integration/defs/llmapi/test_llm_api_connector.py

406-406: Unused function argument: enforce_single_worker

(ARG001)

⏰ 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 (2)
tests/integration/defs/llmapi/test_llm_api_connector.py (2)

44-54: LGTM! Clean refactoring to centralize test defaults.

The refactored model_fn now uses a default_kwargs dictionary merged with user-provided overrides, making the test fixture more maintainable and explicit about default parameters. The merge pattern {**default_kwargs, **kwargs} correctly gives precedence to user-provided values.


406-406: Static analysis false positive: fixture has side effects.

The enforce_single_worker parameter is a pytest fixture that sets the environment variable TLLM_WORKER_USE_SINGLE_PROCESS via monkeypatch (defined at line 60). Fixtures with side effects don't require explicit references in the function body.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22839 [ run ] triggered by Bot. Commit: 1de3035

@tensorrt-cicd
Copy link
Collaborator

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

@jthomson04
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22912 [ run ] triggered by Bot. Commit: 8092b45

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22912 [ run ] completed with state SUCCESS. Commit: 8092b45
/LLM/main/L0_MergeRequest_PR pipeline #17281 completed with status: 'FAILURE'

@jthomson04
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23078 [ run ] triggered by Bot. Commit: 444cdc0

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23078 [ run ] completed with state FAILURE. Commit: 444cdc0
/LLM/main/L0_MergeRequest_PR pipeline #17403 completed with status: 'FAILURE'

@jthomson04
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23081 [ run ] triggered by Bot. Commit: 2078933

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23081 [ run ] completed with state FAILURE. Commit: 2078933
/LLM/main/L0_MergeRequest_PR pipeline #17406 completed with status: 'FAILURE'

@jthomson04
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23209 [ run ] triggered by Bot. Commit: 53d4000

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23209 [ run ] completed with state SUCCESS. Commit: 53d4000
/LLM/main/L0_MergeRequest_PR pipeline #17494 completed with status: 'FAILURE'

@jthomson04 jthomson04 force-pushed the jthomson04/fix-connector-multi-request branch from 0abc0ce to cffba0c Compare November 3, 2025 00:41
@jthomson04
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23327 [ run ] triggered by Bot. Commit: cffba0c

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23327 [ run ] completed with state FAILURE. Commit: cffba0c
/LLM/main/L0_MergeRequest_PR pipeline #17576 completed with status: 'FAILURE'

@jthomson04
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23409 [ run ] triggered by Bot. Commit: 8cdfc43

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23409 [ run ] completed with state FAILURE. Commit: 8cdfc43
/LLM/main/L0_MergeRequest_PR pipeline #17630 completed with status: 'FAILURE'

@jthomson04
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23411 [ run ] triggered by Bot. Commit: b32cb5a

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23528 [ run ] completed with state SUCCESS. Commit: d47ef3b
/LLM/main/L0_MergeRequest_PR pipeline #17708 completed with status: 'FAILURE'

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23532 [ kill ] triggered by Bot. Commit: d47ef3b

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23532 [ kill ] completed with state SUCCESS. Commit: d47ef3b
Successfully killed previous jobs for commit d47ef3b

@jthomson04 jthomson04 force-pushed the jthomson04/fix-connector-multi-request branch from d47ef3b to 97573b8 Compare November 4, 2025 18:52
@jthomson04
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23537 [ run ] triggered by Bot. Commit: 06ae5df

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23537 [ run ] completed with state SUCCESS. Commit: 06ae5df
/LLM/main/L0_MergeRequest_PR pipeline #17713 completed with status: 'FAILURE'

@jthomson04
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23586 [ run ] triggered by Bot. Commit: 2525fa4

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23586 [ run ] completed with state SUCCESS. Commit: 2525fa4
/LLM/main/L0_MergeRequest_PR pipeline #17748 completed with status: 'FAILURE'

@jthomson04
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23667 [ run ] triggered by Bot. Commit: a593217

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23667 [ run ] completed with state SUCCESS. Commit: a593217
/LLM/main/L0_MergeRequest_PR pipeline #17806 completed with status: 'FAILURE'

@jthomson04
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23679 [ run ] triggered by Bot. Commit: df5aad3

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23679 [ run ] completed with state SUCCESS. Commit: df5aad3
/LLM/main/L0_MergeRequest_PR pipeline #17815 completed with status: 'FAILURE'

@jthomson04
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23693 [ run ] triggered by Bot. Commit: e47b861

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23693 [ run ] completed with state SUCCESS. Commit: e47b861
/LLM/main/L0_MergeRequest_PR pipeline #17826 completed with status: 'FAILURE'

@jthomson04 jthomson04 enabled auto-merge (squash) November 6, 2025 06:48
@jthomson04
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23711 [ run ] triggered by Bot. Commit: 136525b

@tensorrt-cicd
Copy link
Collaborator

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

@jthomson04 jthomson04 merged commit fcae852 into NVIDIA:main Nov 6, 2025
5 checks passed
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.

3 participants