Repository navigation
[TRTLLM-14510][feat] BREAKING: serve: default num_serve_frontends to 8 with single-frontend fallback #19379
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
Merged
lancelly
merged 11 commits into
NVIDIA:main
from
lancelly:feat/serve-num-frontends-default-8
Oct 30, 2026
+335
−7
Merged
[TRTLLM-14510][feat] BREAKING: serve: default num_serve_frontends to 8 with single-frontend fallback #19379
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
45b1a29
[None][feat] serve: default num_serve_frontends to 8 with single-fron…
lancelly 03f7b47
[None][feat] serve: drop the dedicated CPU test file for the frontend…
lancelly 9fe82b6
[None][feat] serve: address review on the multi-frontend default
lancelly b908a38
[None][test] serve: trim the multi-frontend default tests and comments
lancelly 51cd675
[None][fix] serve: refuse a port another server uses before joining i…
lancelly bcddbc1
[None][doc] serve: update the multi-frontend notes for launcher-owned…
lancelly 1a9fc59
[None][feat] serve: keep the multi-frontend default with a metadata s…
lancelly b1f03f0
[None][test] serve: trim the multi-frontend default comments and tests
lancelly 441f2c9
[None][chore] serve: inline the num_serve_frontends default
lancelly bee9aff
[None][feat] serve: promote --num_serve_frontends to beta
lancelly 536975e
[None][test] serve: add a GPU test for 8 frontends on one engine
lancelly 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
107 changes: 107 additions & 0 deletions
107
tests/unittest/llmapi/apps/_test_openai_multi_frontend.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,107 @@ | ||
| # 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. | ||
| """trtllm-serve with 8 frontend processes on one engine. | ||
|
|
||
| Each connection may land on any frontend (SO_REUSEPORT), so every request opens | ||
| its own. Server-wide state must not depend on which frontend answers. | ||
| """ | ||
|
|
||
| import time | ||
| from concurrent.futures import ThreadPoolExecutor | ||
|
|
||
| import psutil | ||
| import pytest | ||
| import requests | ||
|
|
||
| from ..test_llm import get_model_path | ||
| from .openai_server import RemoteOpenAIServer | ||
|
|
||
| NUM_FRONTENDS = 8 | ||
| NUM_REQUESTS = 64 | ||
| NUM_STREAMS = 16 | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def model_path() -> str: | ||
| return get_model_path("Qwen3/Qwen3-0.6B") | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def server(model_path: str): | ||
| args = ["--backend", "pytorch", "--num_serve_frontends", str(NUM_FRONTENDS)] | ||
| extra_config = {"return_perf_metrics": True, "enable_iter_perf_stats": True} | ||
| with RemoteOpenAIServer(model_path, args, extra_config=extra_config) as server: | ||
| # /health answers once the first frontend listens. | ||
| deadline = time.monotonic() + 600 | ||
| while _listeners(server.port) < NUM_FRONTENDS: | ||
| assert time.monotonic() < deadline, _listeners(server.port) | ||
| time.sleep(1) | ||
| yield server | ||
|
|
||
|
|
||
| def _listeners(port: int) -> int: | ||
| return sum( | ||
| 1 | ||
| for c in psutil.net_connections("tcp") | ||
| if c.status == psutil.CONN_LISTEN and c.laddr and c.laddr.port == port | ||
| ) | ||
|
|
||
|
|
||
| def _finish_reason(server: RemoteOpenAIServer, model: str, i: int, stream: bool): | ||
| """Run one completion on a connection of its own.""" | ||
| with server.get_client() as client: | ||
| output = client.completions.create( | ||
| model=model, | ||
| prompt=f"Request {i}: the capital of France is", | ||
| max_tokens=16, | ||
| stream=stream, | ||
| ) | ||
| if stream: | ||
| choices = [chunk.choices[0] for chunk in output if chunk.choices] | ||
| else: | ||
| choices = output.choices | ||
| text = "".join(choice.text for choice in choices) | ||
| reasons = [choice.finish_reason for choice in choices if choice.finish_reason] | ||
| return reasons[-1] if text and reasons else None | ||
|
|
||
|
|
||
| def _success_total(server: RemoteOpenAIServer) -> float: | ||
| text = requests.get(server.url_for("prometheus", "metrics"), timeout=30).text | ||
| return sum( | ||
| float(line.rsplit(" ", 1)[1]) | ||
| for line in text.splitlines() | ||
| if line.startswith("trtllm_request_success_total") | ||
| ) | ||
|
|
||
|
|
||
| def test_frontends_share_one_engine(server: RemoteOpenAIServer, model_path: str): | ||
| with ThreadPoolExecutor(16) as pool: | ||
| finish_reasons = list( | ||
| pool.map( | ||
| lambda i: _finish_reason(server, model_path, i, stream=i >= NUM_REQUESTS), | ||
| range(NUM_REQUESTS + NUM_STREAMS), | ||
| ) | ||
| ) | ||
| assert all(finish_reasons), finish_reasons | ||
|
|
||
| # Only the launcher drains the engine's stats (every second), so the first | ||
| # poll gets all of them, whichever frontend answers. | ||
| time.sleep(3) | ||
| polls = [len(requests.get(server.url_for("metrics"), timeout=30).json()) for _ in range(16)] | ||
| assert polls[0] > 0 and not any(polls[1:]), polls | ||
|
|
||
| # Every scrape counts the requests of all frontends. | ||
| totals = [_success_total(server) for _ in range(NUM_FRONTENDS)] | ||
| assert totals == [NUM_REQUESTS + NUM_STREAMS] * NUM_FRONTENDS, totals |
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
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.