-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[TRTLLM-8598][feat] enable n > 1 in OpenAI API with PyTorch backend #8951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
/bot run |
|
PR_Github #23673 [ run ] triggered by Bot. Commit: |
📝 WalkthroughWalkthroughThe changes remove PyTorch backend enforcement for multiple responses and refactor beam search testing infrastructure. A runtime guard in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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_responsefunction is now a no-op but remains in the codebase. Consider adding a docstring explaining that the PyTorch backend restriction forn > 1has 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. + """ passtests/unittest/llmapi/apps/_test_openai_completions.py (2)
43-53: Consider extracting shared beam search fixture logic.The
server_with_beam_searchfixture follows a similar pattern in both_test_openai_completions.pyand_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 unusedbackendparameter.The
backendparameter 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
📒 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.pytensorrt_llm/serve/chat_utils.pytests/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.pytensorrt_llm/serve/chat_utils.pytests/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.pytensorrt_llm/serve/chat_utils.pytests/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_fractionto 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_fractionto 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_searchfixture properly configures the server withmax_beam_width=2to 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
backendparameter correctly reflects thatn > 1(multiple responses) now works on both TRT and PyTorch backends. The test validates the feature withn=2andbest_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 = 1as a fundamental limitation, not a mixing issue. The server is already configured withmax_beam_width=1for 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.
|
PR_Github #23673 [ run ] completed with state |
7d2dfc7 to
8172864
Compare
|
/bot run |
|
PR_Github #23727 [ run ] triggered by Bot. Commit: |
|
/bot run |
|
PR_Github #23735 [ run ] triggered by Bot. Commit: |
|
PR_Github #23727 [ run ] completed with state |
|
PR_Github #23735 [ run ] completed with state |
Signed-off-by: ixlmar <[email protected]>
|
/bot run --stage-list "A10-Pybind" |
3c7ad49 to
bb9cda1
Compare
|
/bot run --stage-list "A10-Pybind" |
|
PR_Github #23745 [ run ] triggered by Bot. Commit: |
|
PR_Github #23746 [ run ] triggered by Bot. Commit: |
|
PR_Github #23745 [ run ] completed with state |
|
PR_Github #23746 [ run ] completed with state |
|
/bot run |
|
PR_Github #23748 [ run ] triggered by Bot. Commit: |
|
PR_Github #23748 [ run ] completed with state |
|
/bot run |
|
PR_Github #23753 [ run ] triggered by Bot. Commit: |
|
/bot run |
|
PR_Github #23834 [ run ] triggered by Bot. Commit: |
|
PR_Github #23753 [ run ] completed with state |
|
PR_Github #23834 [ run ] completed with state |
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 thestage-listparameter 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.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip 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-pipelineReuse 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
Tests