Skip to content

Commit 64a7dfb

Browse files
committed
[TRTLLM-17271][refactor] Point the fleet worker command and the process-guard path at the moved modules, and retarget the disaggregated CLI tests
The fleet worker process now imports _run_fleet_worker from tensorrt_llm.commands.serve_cli._disagg_fleet: commands/serve.py re-exports no private name, so the old command string stops working. The MPI leader resolves the process guard one directory higher, because its module sits one directory deeper; the result is the same tensorrt_llm/llmapi/_llmapi_process_guard.py. The three new modules get the SPDX header and a docstring. Tests patch each name on the module that looks it up: the disaggregated launcher telemetry tests, the leader lifecycle tests, the context-only settings tests, the unified draft KV gate test, the listener policy tests and the coordinator Unix-socket tests import tensorrt_llm.commands.serve_cli.disaggregated and ._disagg_fleet, and the socket patches target the socket module, where the shared bind helper creates its sockets. The shim identity table gains the two lazily re-exported names, whose FutureWarning says "a future release". The CLI wiring tests cover the disaggregated subcommands: the dispatch of `disaggregated` by topology, the remote-client path of `disaggregated_mpi_worker`, the server launcher's keyword arguments and the fleet worker command. Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
1 parent fbe0c58 commit 64a7dfb

12 files changed

Lines changed: 412 additions & 108 deletions

‎tensorrt_llm/commands/serve.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import os
2222
import signal
2323
import socket
24-
import subprocess # nosec B404
2524
import sys
2625
import tempfile
2726
import warnings

‎tensorrt_llm/commands/serve_cli/_disagg_fleet.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
45
# you may not use this file except in compliance with the License.
56
# You may obtain a copy of the License at
67
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8+
# http://www.apache.org/licenses/LICENSE-2.0
89
#
910
# Unless required by applicable law or agreed to in writing, software
1011
# distributed under the License is distributed on an "AS IS" BASIS,
1112
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1213
# See the License for the specific language governing permissions and
1314
# limitations under the License.
15+
"""Fleet and coordinator processes of `trtllm-serve disaggregated`, and the
16+
environment variables the launchers pass to the processes they start."""
1417

1518
import asyncio
1619
import atexit
@@ -82,8 +85,8 @@ def _launch_disagg_fleet(disagg_cfg, config_file, metadata_server_config_file,
8285

8386
cmd = [
8487
sys.executable, "-c",
85-
"from tensorrt_llm.commands.serve import _run_fleet_worker; "
86-
"_run_fleet_worker()"
88+
"from tensorrt_llm.commands.serve_cli._disagg_fleet import "
89+
"_run_fleet_worker; _run_fleet_worker()"
8790
]
8891
logger.info(
8992
f"Launching disagg fleet: {num_workers} SO_REUSEPORT workers on "

‎tensorrt_llm/commands/serve_cli/_telemetry.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
45
# you may not use this file except in compliance with the License.
56
# You may obtain a copy of the License at
67
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8+
# http://www.apache.org/licenses/LICENSE-2.0
89
#
910
# Unless required by applicable law or agreed to in writing, software
1011
# distributed under the License is distributed on an "AS IS" BASIS,
1112
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1213
# See the License for the specific language governing permissions and
1314
# limitations under the License.
15+
"""Telemetry glue shared by the trtllm-serve subcommands.
16+
17+
The command-group telemetry used by every TRT-LLM command is
18+
tensorrt_llm/commands/_telemetry.py.
19+
"""
1420

1521
from tensorrt_llm.usage import (TerminalOutcome, get_observed_signal,
1622
record_termination_observation)

‎tensorrt_llm/commands/serve_cli/disaggregated.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
45
# you may not use this file except in compliance with the License.
56
# You may obtain a copy of the License at
67
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8+
# http://www.apache.org/licenses/LICENSE-2.0
89
#
910
# Unless required by applicable law or agreed to in writing, software
1011
# distributed under the License is distributed on an "AS IS" BASIS,
1112
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1213
# See the License for the specific language governing permissions and
1314
# limitations under the License.
15+
"""The trtllm-serve disaggregated and disaggregated_mpi_worker subcommands."""
1416

1517
import gc
1618
import os
@@ -469,7 +471,7 @@ def _launch_disaggregated_leader(sub_comm, instance_idx: int, config_file: str,
469471
# The Proxy will create a RemoteMpiSessionClient as mpi_session in LLM
470472
# class.
471473
guard_path = Path(
472-
__file__).resolve().parents[1] / "llmapi" / "_llmapi_process_guard.py"
474+
__file__).resolve().parents[2] / "llmapi" / "_llmapi_process_guard.py"
473475
command = [
474476
sys.executable, "-S",
475477
str(guard_path), "--parent-pid",

‎tests/unittest/_torch/pyexecutor/kv_cache/test_dflash_unified_kv_gate.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class _StopLauncher(Exception):
237237

238238
def _launch_from_disagg_config(monkeypatch, tmp_path, context_servers, generation_servers):
239239
"""Run the real disaggregated_mpi_worker up to the rank-communicator split."""
240-
from tensorrt_llm.commands import serve
240+
from tensorrt_llm.commands.serve_cli import disaggregated as serve
241241

242242
config = tmp_path / "disagg.yaml"
243243
config.write_text(

‎tests/unittest/disaggregated/test_coordinator_uds.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import pytest
3333

34-
from tensorrt_llm.commands import serve
34+
from tensorrt_llm.commands.serve_cli import _disagg_fleet as fleet
3535
from tensorrt_llm.serve import disagg_coordinator
3636

3737
pytestmark = pytest.mark.cpu_only
@@ -107,10 +107,10 @@ def __init__(self, monkeypatch: pytest.MonkeyPatch):
107107
self._done = threading.Event()
108108
monkeypatch.setenv("TRTLLM_NO_USAGE_STATS", "1")
109109
monkeypatch.setenv(
110-
serve.DisaggWorkerEnvs.TLLM_DISAGG_COORDINATOR_PORT, str(self.coord_port)
110+
fleet.DisaggWorkerEnvs.TLLM_DISAGG_COORDINATOR_PORT, str(self.coord_port)
111111
)
112112
monkeypatch.setattr(disagg_coordinator, "DisaggCoordinatorService", _StubCoordinatorService)
113-
monkeypatch.setattr(serve, "_launch_disagg_fleet", self._launch_fleet)
113+
monkeypatch.setattr(fleet, "_launch_disagg_fleet", self._launch_fleet)
114114
disagg_cfg = SimpleNamespace(
115115
hostname="127.0.0.1",
116116
port=self.public_port,
@@ -127,7 +127,7 @@ def _launch_fleet(self, *args):
127127

128128
def _serve(self, disagg_cfg):
129129
try:
130-
serve._serve_coordinator_and_fleet(disagg_cfg, "disagg.yaml", None, None, 180, 180, 2)
130+
fleet._serve_coordinator_and_fleet(disagg_cfg, "disagg.yaml", None, None, 180, 180, 2)
131131
except BaseException as e: # noqa: BLE001 - reported by the test thread
132132
self.errors.append(e)
133133

@@ -172,7 +172,7 @@ def short_temp_root(monkeypatch):
172172
def test_coordinator_unix_socket_is_in_new_owner_only_directory(
173173
monkeypatch, short_temp_root, umask
174174
):
175-
monkeypatch.delenv(serve.DisaggWorkerEnvs.TLLM_DISAGG_COORDINATOR_UDS, raising=False)
175+
monkeypatch.delenv(fleet.DisaggWorkerEnvs.TLLM_DISAGG_COORDINATOR_UDS, raising=False)
176176
run = _CoordinatorRun(monkeypatch)
177177
old_umask = os.umask(umask)
178178
try:
@@ -199,7 +199,7 @@ def test_coordinator_unix_socket_is_in_new_owner_only_directory(
199199

200200

201201
def test_coordinator_tcp_transport_creates_no_socket_directory(monkeypatch):
202-
monkeypatch.setenv(serve.DisaggWorkerEnvs.TLLM_DISAGG_COORDINATOR_UDS, "0")
202+
monkeypatch.setenv(fleet.DisaggWorkerEnvs.TLLM_DISAGG_COORDINATOR_UDS, "0")
203203
run = _CoordinatorRun(monkeypatch)
204204
name_prefix = f"trtllm_disagg_coord_{run.public_port}"
205205

@@ -226,9 +226,9 @@ def test_coordinator_socket_directory_fits_unix_socket_address(monkeypatch, tmp_
226226
long_tmpdir.mkdir()
227227
monkeypatch.setattr(tempfile, "tempdir", str(long_tmpdir))
228228

229-
uds_dir = serve._make_coordinator_uds_dir(8000)
229+
uds_dir = fleet._make_coordinator_uds_dir(8000)
230230
try:
231-
uds_path = os.path.join(uds_dir.name, serve._COORDINATOR_UDS_NAME)
231+
uds_path = os.path.join(uds_dir.name, fleet._COORDINATOR_UDS_NAME)
232232
assert os.path.dirname(uds_dir.name) == "/tmp"
233233
assert stat.S_IMODE(os.stat(uds_dir.name).st_mode) == 0o700
234234
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:

‎tests/unittest/llmapi/test_disagg_leader_lifecycle.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def test_disaggregated_leader_cleanup_timeout_retains_guard(
282282
monkeypatch: pytest.MonkeyPatch, outcome: str
283283
) -> None:
284284
"""A delayed guard remains alive to finish cleanup without masking the server error."""
285-
from tensorrt_llm.commands import serve
285+
from tensorrt_llm.commands.serve_cli import disaggregated as serve
286286
from tensorrt_llm.llmapi import mgmn_leader_node
287287

288288
child = mock.MagicMock(pid=12345)
@@ -337,6 +337,6 @@ def run_server(_comm: object) -> None:
337337
elif mode == "proxy":
338338
sys.exit(_run_proxy(directory, scenario))
339339
elif mode == "leader":
340-
from tensorrt_llm.commands import serve
340+
from tensorrt_llm.commands.serve_cli import disaggregated as serve
341341

342342
sys.exit(_run_leader(serve, directory, scenario))

0 commit comments

Comments
 (0)