Skip to content

Commit 600bcd5

Browse files
committed
[TRTLLM-17267][test] Let the multi-frontend tests re-enact the composition root with the tokenize serving object
Both tests build a partial OpenAIServer and register its routes the way the constructor does. The constructor now puts the tokenize serving object on app.state and attaches the role's routers after the local table, so the re-enactments do the same; the tokenize router refuses to attach without its serving object. Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
1 parent 64538b3 commit 600bcd5

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

‎tests/unittest/llmapi/test_serve_multi_frontend_helpers.py‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
from tensorrt_llm.serve import _frontend_processes, openai_server
3838
from tensorrt_llm.serve._base.routing import ServerCapabilities, attach_routers
3939
from tensorrt_llm.serve._frontend_processes import _watch_attached_frontends
40+
from tensorrt_llm.serve.api.openai.tokenize import api_router as tokenize_router
41+
from tensorrt_llm.serve.api.openai.tokenize.serving import TokenizeServing
4042
from tensorrt_llm.serve.api.ops.system.serving import SystemServing
4143
from tensorrt_llm.serve.multi_frontend import (
4244
FORWARDED_ROUTES,
@@ -113,13 +115,19 @@ async def lifespan(_: FastAPI):
113115
server._enable_runtime_control_endpoints = False
114116
server.resource_governor = None
115117
server._launcher_forwarder = forwarder
116-
# The order OpenAIServer.__init__ registers them in: the system router
117-
# (/health, /version, /v1/models) first, then the launcher forwarding
118-
# routes, then the local table.
118+
# The order OpenAIServer.__init__ registers them in: the launcher forwarding
119+
# routes, then the local table, then the routers of the role (the system
120+
# router with /health, /version and /v1/models, and the tokenize router),
121+
# which read their serving objects from app.state.
119122
server.app.state.ops_serving_system = SystemServing(model="m", health_probe=lambda: True)
120-
attach_routers(server.app, ServerCapabilities.for_role(None))
123+
setattr(
124+
server.app.state,
125+
tokenize_router.APP_STATE_KEY,
126+
TokenizeServing(model="m", tokenizer=None),
127+
)
121128
server._register_launcher_forwarding_routes()
122129
server.register_routes()
130+
attach_routers(server.app, ServerCapabilities.for_role(None))
123131
return server
124132

125133

‎tests/unittest/llmapi/test_serve_multi_frontend_route_gate.py‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
from test_common.serve.routes import effective_routes
2929

3030
from tensorrt_llm.serve._base.routing import ServerCapabilities, attach_routers
31+
from tensorrt_llm.serve.api.openai.tokenize import api_router as tokenize_router
32+
from tensorrt_llm.serve.api.openai.tokenize.serving import TokenizeServing
3133
from tensorrt_llm.serve.api.ops.system.serving import SystemServing
3234
from tensorrt_llm.serve.multi_frontend import FORWARDED_ROUTES
3335
from tensorrt_llm.serve.openai_server import OpenAIServer
@@ -76,11 +78,18 @@ def _llm_server_routes() -> list[tuple[str, str]]:
7678
server._enable_rl_control_endpoints = True
7779
server._enable_runtime_control_endpoints = True
7880
server.resource_governor = None
79-
# As OpenAIServer.__init__ does: the system router (/health, /version,
80-
# /v1/models) is attached for every role before the role's own table.
81+
# As OpenAIServer.__init__ does: the serving objects the routers read go on
82+
# app.state, the role's own table is registered, then the routers of the role
83+
# (the system router with /health, /version and /v1/models, and the tokenize
84+
# router) are attached.
8185
server.app.state.ops_serving_system = SystemServing(model="m", health_probe=lambda: True)
82-
attach_routers(server.app, ServerCapabilities.for_role(None))
86+
setattr(
87+
server.app.state,
88+
tokenize_router.APP_STATE_KEY,
89+
TokenizeServing(model="m", tokenizer=None),
90+
)
8391
server.register_routes()
92+
attach_routers(server.app, ServerCapabilities.for_role(None))
8493
# effective_routes walks included routers, which FastAPI 0.139 keeps as
8594
# objects without .path or .methods in app.routes.
8695
return sorted(

0 commit comments

Comments
 (0)