Skip to content

Conversation

@ixlmar
Copy link
Collaborator

@ixlmar ixlmar commented Nov 5, 2025

Description

This exposes functionality existing in the backend (see #5997) in the OpenAI API.

Test Coverage

Extended existing tests to cover PyTorch backend.

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

  • Update tava architecture diagram if there is a significant design change in PR.

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

Summary by CodeRabbit

  • Bug Fixes

    • Removed PyTorch backend constraint that prevented multiple response generation.
    • Added support for multiple responses with beam search configurations.
  • Tests

    • Enhanced test coverage for beam search functionality with multiple responses and batch completions.

@ixlmar
Copy link
Collaborator Author

ixlmar commented Nov 5, 2025

/bot run

@ixlmar ixlmar requested a review from stnie November 5, 2025 19:45
@tensorrt-cicd
Copy link
Collaborator

PR_Github #23673 [ run ] triggered by Bot. Commit: 7d2dfc7

@ixlmar ixlmar marked this pull request as ready for review November 5, 2025 19:54
@ixlmar ixlmar requested a review from a team as a code owner November 5, 2025 19:54
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 5, 2025

📝 Walkthrough

Walkthrough

The changes remove PyTorch backend enforcement for multiple responses and refactor beam search testing infrastructure. A runtime guard in check_multiple_response is removed, and dedicated beam search server/client fixtures are introduced in test files to enable independent configuration and testing.

Changes

Cohort / File(s) Summary
PyTorch enforcement removal
tensorrt_llm/serve/chat_utils.py
Removes the ValueError check that prevented n > 1 with PyTorch backend; function body now passes without enforcement.
Chat API test infrastructure
tests/unittest/llmapi/apps/_test_openai_chat.py
Adds server_with_beam_search and client_with_beam_search fixtures; updates base server fixture to set kv_cache_free_gpu_memory_fraction to 0.2; removes backend parameter from test_multiple_responses; adds test_multiple_responses_and_beam_search (parameterized) and test_multiple_responses_with_beam_search tests.
Completions API test infrastructure
tests/unittest/llmapi/apps/_test_openai_completions.py
Adds server_with_beam_search and async_client_with_beam_search fixtures; removes conditional beam width configuration for TRT backend from base server fixture; updates test_batch_completions_beam_search to use new beam search client fixture.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Verify the removal of PyTorch-specific enforcement in check_multiple_response aligns with the intended behavior change and doesn't introduce unexpected regressions.
  • Confirm beam search fixture configurations are consistent across both test files (particularly kv_cache_free_gpu_memory_fraction and max_beam_width values).
  • Validate that test parameterization changes and fixture wiring in both test files preserve test coverage and produce expected outcomes.

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: enabling n > 1 in OpenAI API with PyTorch backend, directly matching the primary feature in the changeset.
Description check ✅ Passed The description provides a brief explanation (exposes backend functionality in OpenAI API), mentions test coverage (extended tests for PyTorch backend), and includes a completed checklist; however, it lacks specific details about what was changed and why.
✨ 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 (3)
tensorrt_llm/serve/chat_utils.py (1)

202-203: Document or deprecate the no-op function.

The check_multiple_response function is now a no-op but remains in the codebase. Consider adding a docstring explaining that the PyTorch backend restriction for n > 1 has been lifted, or mark this function as deprecated if it's retained solely for API compatibility.

Apply this diff to add documentation:

 def check_multiple_response(n: int, backend: Optional[str]):
+    """Check multiple response configuration.
+    
+    Note: PyTorch backend now supports n > 1 (multiple responses).
+    This function is retained for API compatibility but performs no validation.
+    """
     pass
tests/unittest/llmapi/apps/_test_openai_completions.py (2)

43-53: Consider extracting shared beam search fixture logic.

The server_with_beam_search fixture follows a similar pattern in both _test_openai_completions.py and _test_openai_chat.py. Consider extracting the common beam search server configuration to a shared utility module to reduce duplication.

For example, create a shared factory function in openai_server.py:

def create_beam_search_server(model_name: str, backend: str, 
                              num_postprocess_workers: int,
                              extra_options: dict = None):
    """Create a server configured for beam search testing."""
    model_path = get_model_path(model_name)
    args = ["--backend", f"{backend}"]
    args.extend(["--kv_cache_free_gpu_memory_fraction", "0.2"])
    args.extend(["--max_beam_width", "2"])
    args.extend(["--num_postprocess_workers", f"{num_postprocess_workers}"])
    return RemoteOpenAIServer(model_path, args)

167-186: Remove unused backend parameter.

The backend parameter is no longer used in the test body since the PyTorch restriction for beam search has been removed. The test now runs successfully on both backends using the beam-search-enabled server.

Apply this diff to remove the unused parameter:

 async def test_batch_completions_beam_search(
-        async_client_with_beam_search: openai.AsyncOpenAI, model_name, prompts,
-        backend):
+        async_client_with_beam_search: openai.AsyncOpenAI, model_name, prompts):
     # test beam search
📜 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 c2fe686 and 7d2dfc7.

📒 Files selected for processing (3)
  • tensorrt_llm/serve/chat_utils.py (1 hunks)
  • tests/unittest/llmapi/apps/_test_openai_chat.py (5 hunks)
  • tests/unittest/llmapi/apps/_test_openai_completions.py (3 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:

  • tests/unittest/llmapi/apps/_test_openai_completions.py
  • tensorrt_llm/serve/chat_utils.py
  • tests/unittest/llmapi/apps/_test_openai_chat.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/unittest/llmapi/apps/_test_openai_completions.py
  • tensorrt_llm/serve/chat_utils.py
  • tests/unittest/llmapi/apps/_test_openai_chat.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/unittest/llmapi/apps/_test_openai_completions.py
  • tensorrt_llm/serve/chat_utils.py
  • tests/unittest/llmapi/apps/_test_openai_chat.py
🧠 Learnings (4)
📓 Common learnings
Learnt from: moraxu
Repo: NVIDIA/TensorRT-LLM PR: 6303
File: tests/integration/test_lists/qa/examples_test_list.txt:494-494
Timestamp: 2025-07-28T17:06:08.621Z
Learning: In TensorRT-LLM testing, it's common to have both CLI flow tests (test_cli_flow.py) and PyTorch API tests (test_llm_api_pytorch.py) for the same model. These serve different purposes: CLI flow tests validate the traditional command-line workflow, while PyTorch API tests validate the newer LLM API backend. Both are legitimate and should coexist.
📚 Learning: 2025-08-19T12:45:11.997Z
Learnt from: amitz-nv
Repo: NVIDIA/TensorRT-LLM PR: 7033
File: tensorrt_llm/_torch/pyexecutor/model_engine.py:0-0
Timestamp: 2025-08-19T12:45:11.997Z
Learning: In tensorrt_llm/_torch/pyexecutor/model_engine.py, DoRA (Delta Orthogonal Rank Adaptation) functionality was removed from the PyTorch flow to eliminate issues with inverted DoRA detection logic. The original is_dora condition was checking if scaling_vec_pointer == 0, which was potentially incorrect.

Applied to files:

  • tensorrt_llm/serve/chat_utils.py
📚 Learning: 2025-08-19T12:45:35.429Z
Learnt from: amitz-nv
Repo: NVIDIA/TensorRT-LLM PR: 7033
File: tensorrt_llm/_torch/pyexecutor/model_engine.py:2086-2092
Timestamp: 2025-08-19T12:45:35.429Z
Learning: DoRA (Delta Orthogonal Rank Adaptation) functionality has been removed from the PyTorch flow in tensorrt_llm/_torch/pyexecutor/model_engine.py. The is_dora field is computed but not used downstream in the PyTorch flow, so converting it to a tensor would be wasteful overhead.

Applied to files:

  • tensorrt_llm/serve/chat_utils.py
📚 Learning: 2025-08-08T04:10:19.038Z
Learnt from: djns99
Repo: NVIDIA/TensorRT-LLM PR: 6728
File: cpp/tensorrt_llm/plugins/mixtureOfExperts/mixtureOfExpertsPlugin.cpp:966-966
Timestamp: 2025-08-08T04:10:19.038Z
Learning: TensorRT plugins currently don't support padding functionality, and TensorRT is not getting new features (in maintenance mode). This means that duplicating parameters like mExpertHiddenSize in function calls, even with TODO comments, can be acceptable as pragmatic solutions within these constraints.

Applied to files:

  • tensorrt_llm/serve/chat_utils.py
🧬 Code graph analysis (2)
tests/unittest/llmapi/apps/_test_openai_completions.py (2)
tests/unittest/llmapi/apps/_test_openai_chat.py (4)
  • num_postprocess_workers (33-34)
  • server_with_beam_search (84-98)
  • model_name (21-22)
  • backend (26-27)
tests/unittest/llmapi/apps/openai_server.py (2)
  • RemoteOpenAIServer (17-118)
  • get_async_client (115-118)
tests/unittest/llmapi/apps/_test_openai_chat.py (4)
tests/unittest/llmapi/apps/_test_openai_completions.py (6)
  • server_with_beam_search (44-53)
  • model_name (16-17)
  • backend (21-22)
  • num_postprocess_workers (28-29)
  • client (57-58)
  • server (33-40)
tests/integration/defs/stress_test/stress_test.py (2)
  • model_name (110-112)
  • get_model_path (310-312)
tests/unittest/llmapi/apps/openai_server.py (2)
  • RemoteOpenAIServer (17-118)
  • get_client (109-113)
tensorrt_llm/_torch/pyexecutor/model_engine.py (1)
  • use_beam_search (418-419)
🪛 Ruff (0.14.3)
tests/unittest/llmapi/apps/_test_openai_completions.py

169-169: Unused function argument: backend

(ARG001)

🔇 Additional comments (6)
tests/unittest/llmapi/apps/_test_openai_completions.py (1)

36-40: LGTM!

Adding kv_cache_free_gpu_memory_fraction to the base server fixture ensures proper resource management when multiple servers coexist during testing.

tests/unittest/llmapi/apps/_test_openai_chat.py (5)

71-72: LGTM!

Adding kv_cache_free_gpu_memory_fraction to the base server fixture ensures proper resource management when multiple test servers coexist.


83-98: Beam search fixture enables dedicated test coverage.

The new server_with_beam_search fixture properly configures the server with max_beam_width=2 to enable beam search testing. This approach allows independent testing of beam search functionality without affecting the base server configuration.

Note: This fixture follows the same pattern as in _test_openai_completions.py. Consider the earlier suggestion to extract common logic to a shared utility.


204-221: LGTM!

Removing the backend parameter correctly reflects that n > 1 (multiple responses) now works on both TRT and PyTorch backends. The test validates the feature with n=2 and best_of=4.


264-286: LGTM!

The new test validates that beam search with multiple responses (n=2) works correctly when using a beam-search-enabled server. The assertion confirms that beam search produces different outputs as expected.


224-251: Correct the skip message to accurately reflect PyTorch backend's lack of beam search support.

The skip message "Mixing beam search and regular requests is not supported in PyTorch backend" is misleading. PyTorch's TorchSampler implementation only supports max_beam_width = 1 as a fundamental limitation, not a mixing issue. The server is already configured with max_beam_width=1 for the PyTorch backend, making beam search requests impossible regardless of mixing.

Change the skip condition message to:

pytest.skip("PyTorch backend does not support beam search (max_beam_width > 1)")

This accurately reflects that beam search is unsupported entirely in PyTorch, not constrained by mixing scenarios.

Likely an incorrect or invalid review comment.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23673 [ run ] completed with state SUCCESS. Commit: 7d2dfc7
/LLM/release-1.1/L0_MergeRequest_PR pipeline #437 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

@ixlmar ixlmar force-pushed the feat/openai-multiple-beam branch from 7d2dfc7 to 8172864 Compare November 6, 2025 08:51
@ixlmar
Copy link
Collaborator Author

ixlmar commented Nov 6, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23727 [ run ] triggered by Bot. Commit: 8172864

@ixlmar ixlmar changed the base branch from release/1.1 to main November 6, 2025 09:44
@ixlmar ixlmar requested review from a team as code owners November 6, 2025 09:44
@ixlmar ixlmar removed request for a team November 6, 2025 09:59
@ixlmar ixlmar marked this pull request as ready for review November 6, 2025 09:59
@ixlmar
Copy link
Collaborator Author

ixlmar commented Nov 6, 2025

/bot run

@ixlmar ixlmar enabled auto-merge (squash) November 6, 2025 10:04
@tensorrt-cicd
Copy link
Collaborator

PR_Github #23735 [ run ] triggered by Bot. Commit: 3c7ad49

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23727 [ run ] completed with state ABORTED. Commit: 8172864
LLM/release-1.1/L0_MergeRequest_PR #442 (Blue Ocean) completed with status: ABORTED

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23735 [ run ] completed with state SUCCESS. Commit: 3c7ad49
/LLM/main/L0_MergeRequest_PR pipeline #17865 completed with status: 'FAILURE'

@ixlmar
Copy link
Collaborator Author

ixlmar commented Nov 6, 2025

/bot run --stage-list "A10-Pybind"

@ixlmar ixlmar force-pushed the feat/openai-multiple-beam branch from 3c7ad49 to bb9cda1 Compare November 6, 2025 11:37
@ixlmar
Copy link
Collaborator Author

ixlmar commented Nov 6, 2025

/bot run --stage-list "A10-Pybind"

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23745 [ run ] triggered by Bot. Commit: bb9cda1

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23746 [ run ] triggered by Bot. Commit: bb9cda1

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23745 [ run ] completed with state ABORTED. Commit: bb9cda1

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23746 [ run ] completed with state SUCCESS. Commit: bb9cda1
/LLM/main/L0_MergeRequest_PR pipeline #17873 (Partly Tested) completed with status: 'SUCCESS'

@ixlmar
Copy link
Collaborator Author

ixlmar commented Nov 6, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23748 [ run ] triggered by Bot. Commit: bb9cda1

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23748 [ run ] completed with state SUCCESS. Commit: bb9cda1
/LLM/main/L0_MergeRequest_PR pipeline #17875 completed with status: 'FAILURE'

@ixlmar
Copy link
Collaborator Author

ixlmar commented Nov 6, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23753 [ run ] triggered by Bot. Commit: bb9cda1

@ixlmar
Copy link
Collaborator Author

ixlmar commented Nov 7, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23834 [ run ] triggered by Bot. Commit: bb9cda1

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23753 [ run ] completed with state ABORTED. Commit: bb9cda1
/LLM/main/L0_MergeRequest_PR pipeline #17879 completed with status: 'FAILURE'

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23834 [ run ] completed with state SUCCESS. Commit: bb9cda1
/LLM/main/L0_MergeRequest_PR pipeline #17945 completed with status: 'SUCCESS'

@ixlmar ixlmar merged commit 533add5 into NVIDIA:main Nov 8, 2025
5 checks passed
@ixlmar ixlmar deleted the feat/openai-multiple-beam branch November 10, 2025 08:20
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