Skip to content

[#15327][feat] Add per-request priority support to OpenAI chat/completions#15329

Open
sopwg612 wants to merge 13 commits into
NVIDIA:mainfrom
deepinfra:feat/openai-request-priority
Open

[#15327][feat] Add per-request priority support to OpenAI chat/completions#15329
sopwg612 wants to merge 13 commits into
NVIDIA:mainfrom
deepinfra:feat/openai-request-priority

Conversation

@sopwg612

@sopwg612 sopwg612 commented Jun 12, 2026

Copy link
Copy Markdown

Description

Closes #15327.

The LLM API already supports per-request scheduling priority (generate_async(..., priority=...), range [0, 1], default DEFAULT_REQUEST_PRIORITY), honored by the PyTorch backend when the engine runs with scheduler_config.waiting_queue_policy=priority. This PR exposes it through the trtllm-serve OpenAI frontend:

  • Add an optional priority: float extra param (ge=0.0, le=1.0, default None) to ChatCompletionRequest and CompletionRequest in tensorrt_llm/serve/openai_protocol.py.
  • Forward it to generate_async in openai_chat and openai_completion in tensorrt_llm/serve/openai_server.py, falling back to DEFAULT_REQUEST_PRIORITY when unset.

Behavior is unchanged for clients that don't send the field, and under the default FCFS waiting-queue policy the value is accepted and ignored, so the change is backward-compatible. Out-of-range values are rejected with a 422 by Pydantic validation.

Validated on a 4xGB300 deployment at 160-way saturation: priority 1.0 requests saw p50 TTFT 0.947s vs 2.857s for priority 0.0, with an equal-priority control showing no gap.

Test Coverage

  • Pydantic field validation (range, default) is exercised by any request-construction path; out-of-range values return 422.
  • End-to-end scheduling behavior requires a saturated GPU deployment with waiting_queue_policy=priority (numbers above). Happy to add an acceptance test modeled on tests/unittest/llmapi/apps/_test_openai_cache_salt.py if reviewers want one.

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)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

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

Summary by CodeRabbit

  • New Features
    • Added optional request priority parameter for both text and chat completions, enabling fine-grained request prioritization with values between 0.0 and 1.0. Requests without an explicit priority default to standard handling.

…completions

Expose the executor's per-request scheduling priority through the OpenAI
frontend: accept 'priority' (float in [0,1], higher served first, default
DEFAULT_REQUEST_PRIORITY) on ChatCompletionRequest and CompletionRequest,
and forward it to generate_async in openai_chat and openai_completion.

Only honored when scheduler_config.waiting_queue_policy=priority; the
default FCFS waiting queue ignores it. Validated on a 4xB300 deployment
at 160-way saturation: HIGH(1.0) p50 TTFT 0.947s vs LOW(0.0) 2.857s,
with an equal-priority control showing no gap.

Signed-off-by: Sihan Wang <sihan@deepinfra.com>
@sopwg612
sopwg612 requested a review from a team as a code owner June 12, 2026 23:36
@sopwg612
sopwg612 requested a review from syuoni June 12, 2026 23:36
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

TensorRT-LLM's OpenAI-compatible API now accepts an optional priority request parameter on chat completions and text completions endpoints. The priority (float in [0.0, 1.0]) is forwarded to the underlying LLM generation calls, defaulting to DEFAULT_REQUEST_PRIORITY when omitted. Both request protocol definitions and server-side wiring are updated together.

Changes

Request Priority Feature

Layer / File(s) Summary
Request protocol: priority field
tensorrt_llm/serve/openai_protocol.py
Optional priority: Optional[float] field with [0.0, 1.0] range validation added to CompletionRequest and ChatCompletionRequest.
Server wiring: priority forwarding
tensorrt_llm/serve/openai_server.py
Imports DEFAULT_REQUEST_PRIORITY and passes request.priority (or default) to generate_async in both chat and completion handlers.

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding per-request priority support to OpenAI chat/completions endpoints.
Description check ✅ Passed The PR description is comprehensive and covers motivation, implementation details, test coverage, backward compatibility, and validation results. It follows the required template sections.
Linked Issues check ✅ Passed All objectives from issue #15327 are met: optional priority parameter added to request objects, forwarded to generate_async with proper defaults, validation in place, and backward compatibility maintained.
Out of Scope Changes check ✅ Passed All changes align with the scope of issue #15327: adding priority support to OpenAI protocol and server files. No unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

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

⚠️ Outside diff range comments (1)
tensorrt_llm/serve/openai_server.py (1)

1294-1307: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Forward priority on the Harmony chat path as well.

openai_chat and openai_completion now propagate request.priority, but the Harmony variant of /v1/chat/completions (chat_harmony, Line 1752 onward) still calls generate_async without priority. This makes scheduling behavior path-dependent for the same API surface.

Suggested fix
             promise = self.generator.generate_async(
                 inputs=harmony_tokens,
                 sampling_params=sampling_params,
                 _postproc_params=postproc_params
                 if self.postproc_worker_enabled else None,
                 streaming=bool(request.stream),
                 lora_request=request.lora_request,
                 scheduling_params=scheduling_params,
                 disaggregated_params=disaggregated_params,
                 trace_headers=trace_headers,
+                priority=request.priority
+                if request.priority is not None else DEFAULT_REQUEST_PRIORITY,
             )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/serve/openai_server.py` around lines 1294 - 1307, The Harmony
chat path (chat_harmony) calls self.generator.generate_async without passing the
priority, causing inconsistent scheduling; update chat_harmony to forward
priority exactly like the other paths by adding the priority argument to the
generate_async call (use request.priority if not None else
DEFAULT_REQUEST_PRIORITY) so the call signature matches the
openai_chat/openai_completion usage and scheduling is consistent across
handlers.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@tensorrt_llm/serve/openai_server.py`:
- Around line 1294-1307: The Harmony chat path (chat_harmony) calls
self.generator.generate_async without passing the priority, causing inconsistent
scheduling; update chat_harmony to forward priority exactly like the other paths
by adding the priority argument to the generate_async call (use request.priority
if not None else DEFAULT_REQUEST_PRIORITY) so the call signature matches the
openai_chat/openai_completion usage and scheduling is consistent across
handlers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 86f2ada7-fd57-4dcc-99ed-dec6398c9bce

📥 Commits

Reviewing files that changed from the base of the PR and between c2b7cd9 and 62da9a8.

📒 Files selected for processing (2)
  • tensorrt_llm/serve/openai_protocol.py
  • tensorrt_llm/serve/openai_server.py

Keep /v1/chat/completions behavior consistent between the standard and
Harmony handlers: chat_harmony now forwards request.priority to
generate_async the same way openai_chat and openai_completion do.

Signed-off-by: Sihan Wang <sihan@deepinfra.com>
@sopwg612

Copy link
Copy Markdown
Author

A note for the maintainer who triages this: this PR is api-compatible. It only adds an optional priority field (default None, falling back to DEFAULT_REQUEST_PRIORITY) to ChatCompletionRequest / CompletionRequest and forwards it to generate_async. Existing clients that don't send the field are unaffected, and under the default FCFS waiting-queue policy the value is accepted and ignored, so there is no behavior change without explicit opt-in.

I don't have permission to set labels on this repo — could you please add the api-compatible label and trigger CI (/bot run) when you get a chance? Happy to add an acceptance test or address any review feedback. Thanks!

@syuoni syuoni left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thanks for the contribution.

@sopwg612

Copy link
Copy Markdown
Author

@syuoni could you launch the bot run for the blossom-ci check?

@sopwg612
sopwg612 requested a review from syuoni July 10, 2026 20:04
Resolve conflicts in serve/openai_protocol.py and serve/openai_server.py:
keep both the new upstream conversation_params field/kwarg and this PR's
priority field/kwarg on CompletionRequest/ChatCompletionRequest and the
generate_async call sites.

Signed-off-by: Sihan Wang <sihan@deepinfra.com>
@sopwg612

Copy link
Copy Markdown
Author

@syuoni

@sopwg612
sopwg612 requested a review from a team as a code owner July 14, 2026 18:42
@tongyuantongyu

Copy link
Copy Markdown
Member

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59356 [ run ] triggered by Bot. Commit: a185950 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59356 [ run ] completed with state SUCCESS. Commit: a185950
/LLM/main/L0_MergeRequest_PR pipeline #47832 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@tongyuantongyu

Copy link
Copy Markdown
Member

@sopwg612 Please fix the following test:

unittest/api_stability/test_serve_api.py:220: in test_live_fields_are_in_yaml

sopwg612 added 2 commits July 15, 2026 10:18
…eference

The api_stability test test_live_fields_are_in_yaml requires every live
Pydantic field on a gated request model to be declared in
trtllm_serve_api.yaml. Add the priority extension field to
CompletionRequest and ChatCompletionRequest (kind: extension,
status: prototype, default: null, required: false).

Signed-off-by: Sihan Wang <sihan@deepinfra.com>
@sopwg612
sopwg612 requested a review from a team as a code owner July 15, 2026 17:22
@sopwg612
sopwg612 requested a review from QiJune July 15, 2026 17:22
@sopwg612

Copy link
Copy Markdown
Author

@tongyuantongyu Thanks! Fixed in 09a26a6: the priority field was a new gated field on CompletionRequest/ChatCompletionRequest that wasn't declared in tests/unittest/api_stability/references/trtllm_serve_api.yaml. I've added it to both models as kind: extension, status: prototype, default: null, required: false, matching the sibling conversation_params entry. Could you re-trigger /bot run when you have a moment?

@sopwg612
sopwg612 requested a review from tongyuantongyu July 15, 2026 18:56
@tongyuantongyu

Copy link
Copy Markdown
Member

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59686 [ run ] triggered by Bot. Commit: 09a26a6 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59686 [ run ] completed with state SUCCESS. Commit: 09a26a6
/LLM/main/L0_MergeRequest_PR pipeline #48118 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@sopwg612

Copy link
Copy Markdown
Author

@tongyuantongyu Thanks for running CI again. The test_live_fields_are_in_yaml failure from the previous run is fixed in 09a26a6 (verified: the priority rows pass all the serve api_stability checks). Pipeline #48118 on 09a26a6 reports FAILURE, but the build stage (PR_Github #59686) succeeded, so it looks like a different test failed downstream.

Unfortunately I can't view the failure details — both the CI report and the failure-analysis page are on NVIDIA-internal hosts I can't reach. Could you share the failing test name(s) and error output from pipeline #48118? Once I can see what's failing I'll fix it right away. If it looks like an unrelated flake, a re-run might also clear it. Thanks!

@tongyuantongyu

Copy link
Copy Markdown
Member

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59848 [ run ] triggered by Bot. Commit: f46b135 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59848 [ run ] completed with state FAILURE. Commit: f46b135
/LLM/main/L0_MergeRequest_PR pipeline #48254 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@tongyuantongyu

Copy link
Copy Markdown
Member

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59934 [ run ] triggered by Bot. Commit: f46b135 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59934 [ run ] completed with state FAILURE. Commit: f46b135
/LLM/main/L0_MergeRequest_PR pipeline #48340 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

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.

[Feature]: Expose per-request scheduling priority in the trtllm-serve OpenAI frontend

4 participants