Repository navigation
[None][feat] Responses: name the engine request behind each reply #21602
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
Open
JunyiXu-nv
wants to merge
7
commits into
NVIDIA:main
Choose a base branch
from
JunyiXu-nv:dev-junyix-feat-responses-engine-request-id
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+295
β4
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
51a80c0
[None][feat] Responses: name the engine request behind each reply
JunyiXu-nv 9c4c9dd
[None][chore] Merge main (a0ce6c8474) into dev-junyix-feat-responses-β¦
JunyiXu-nv 9e4727b
[None][chore] Merge main (f6405a5965) into dev-junyix-feat-responses-β¦
JunyiXu-nv ad9ce6d
[None][feat] Responses: address review of the engine request id header
JunyiXu-nv 4a5a584
[None][test] Responses: check the created event carries the request_id
JunyiXu-nv 592c71c
[None][chore] Merge main (38ab02f379) into dev-junyix-feat-responses-β¦
JunyiXu-nv a828f43
[None][chore] Merge main (748dc201e8) into dev-junyix-feat-responses-β¦
JunyiXu-nv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
tests/unittest/llmapi/apps/test_responses_engine_request_id.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """Offline tests for the engine request id header of /v1/responses replies. | ||
|
|
||
| A Responses reply is named with a random ``resp_`` id, so the header is what | ||
| ties it to the server's records of the request, which use the engine's id. | ||
| """ | ||
|
|
||
| from unittest.mock import AsyncMock | ||
|
|
||
| import pytest | ||
| from fastapi import FastAPI | ||
| from fastapi.testclient import TestClient | ||
|
|
||
| import tensorrt_llm.serve.openai_server as server_module | ||
| from tensorrt_llm.executor.result import CompletionOutput | ||
|
|
||
| from .openai_server_stub import make_stub_openai_server | ||
|
|
||
| pytestmark = pytest.mark.cpu_only | ||
|
|
||
| _HEADER = "x-trtllm-engine-request-id" | ||
|
|
||
|
|
||
| class _FinishedGeneration: | ||
| """A generation the engine finished in one step, under ``request_id``.""" | ||
|
|
||
| def __init__(self, request_id): | ||
| self.request_id = request_id | ||
| self.id = request_id | ||
| self.prompt_token_ids = [1, 2, 3] | ||
| self.cached_tokens = 0 | ||
| self.outputs = [ | ||
| CompletionOutput(index=0, text="Four.", token_ids=[4, 5], finish_reason="stop") | ||
| ] | ||
| self.finished = self._done = True | ||
| self.error = None | ||
| self._steps = [self] | ||
|
|
||
| async def aresult(self): | ||
| return self | ||
|
|
||
| def __await__(self): | ||
| return self.aresult().__await__() | ||
|
|
||
| def __aiter__(self): | ||
| return self | ||
|
|
||
| async def __anext__(self): | ||
| if not self._steps: | ||
| raise StopAsyncIteration | ||
| return self._steps.pop() | ||
|
|
||
|
|
||
| def _responses_client(tmp_path, monkeypatch, request_id): | ||
| """A client of /v1/responses on a server whose engine names its request ``request_id``.""" | ||
|
|
||
| async def preprocess(**kwargs): | ||
| return [1, 2, 3], kwargs["request"].to_sampling_params() | ||
|
|
||
| monkeypatch.setattr(server_module, "responses_api_request_preprocess", preprocess) | ||
| model_config = type("ModelConfig", (), {"model_type": "qwen3", "vocab_size": 1024})() | ||
| server = make_stub_openai_server( | ||
| tmp_path, | ||
| "test-model", | ||
| model_config, | ||
| lambda **kwargs: _FinishedGeneration(request_id), | ||
| ) | ||
| server.await_disconnected = AsyncMock() | ||
| server._extract_metrics = AsyncMock() | ||
| app = FastAPI() | ||
| app.add_api_route("/v1/responses", server.openai_responses, methods=["POST"]) | ||
| return TestClient(app) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("stream", [False, True], ids=["non_streaming", "streaming"]) | ||
| def test_a_reply_names_its_engine_request_in_a_header(tmp_path, monkeypatch, stream): | ||
| """The header carries the engine's id for the request.""" | ||
| client = _responses_client(tmp_path, monkeypatch, request_id=42) | ||
| body = {"model": "test-model", "input": "What is 2 + 2?", "stream": stream} | ||
|
|
||
| reply = client.post("/v1/responses", json=body) | ||
|
|
||
| assert reply.status_code == 200, reply.text | ||
| assert reply.headers.get(_HEADER) == "42" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.