Skip to content

[TRTLLM-17273][chore] Remove dead code in trtllm-serve ahead of the module moves - #21176

Open
JunyiXu-nv wants to merge 1 commit into
NVIDIA:mainfrom
JunyiXu-nv:dev-junyix-feat-serve-delete-dead-code
Open

JunyiXu-nv wants to merge 1 commit into
NVIDIA:mainfrom
JunyiXu-nv:dev-junyix-feat-serve-delete-dead-code

Conversation

@JunyiXu-nv

@JunyiXu-nv JunyiXu-nv commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

  • The PR removes PrefixBlockSet, ServerState.is_healthy, build_disagg_routers’s is_delegating_client parameter, OpenAIServer._vocab_size, and commented-out Harmony code. Callers must no longer rely on the removed API members.
  • SERVER_TIMING_HEADER now has one definition in _perf_metrics_schema.py. perf_metrics.py and visual_gen_metrics.py re-export it, preserving the reported import paths.
  • The build_config change removes explicit CLI scalar checks that previously triggered inclusion in llm_args. The objectives report that llm_args.pop("build_config", None) remains to preserve handling of stale YAML keys.
  • Review severity counts are unavailable. The supplied evidence does not include current review findings.

QA Engineer Review

The Harmony parsing test was modified. It no longer checks OpenAIServer._vocab_size when no tokenizer is configured. It retains the assertion that converting logit_bias with vocab_size=None raises ValueError. The test is listed in tests/integration/test_lists/test-db/l0_cpu.yml under TestStripIncompleteMessagesReporting. Coverage verdict: needs follow-up. The supplied validation reports one teardown-timing-race failure in the disaggregated run, with 1263 passed, 1 skipped, and 2 xfailed; it also reports that the failure passed in another full-suite run and twice in isolation.

Per-File QA Perspective

  • tensorrt_llm/commands/serve.py: Check that removing explicit build-config scalar checks does not change intended llm_args construction. Stale YAML handling reportedly remains.
  • tensorrt_llm/serve/_perf_metrics_schema.py: Check that the shared SERVER_TIMING_HEADER remains "Server-Timing" and is available through both server metrics modules.
  • tensorrt_llm/serve/disagg_coordinator.py: Check coordinator and client router construction after removing the is_delegating_client arguments.
  • tensorrt_llm/serve/harmony_adapter.py: Only commented-out code was removed; no executable behavior change is reported.
  • tensorrt_llm/serve/openai_server.py: Verify callers do not depend on the removed _vocab_size property.
  • tensorrt_llm/serve/perf_metrics.py: Check that the existing import path still provides SERVER_TIMING_HEADER.
  • tensorrt_llm/serve/router.py: Check callers against the updated build_disagg_routers signature. The ServerState.is_healthy method was also removed.
  • tensorrt_llm/serve/router_utils.py: Verify no callers depend on the removed PrefixBlockSet class or its exports.
  • tensorrt_llm/serve/visual_gen_metrics.py: Check that the existing import path still provides SERVER_TIMING_HEADER.
  • tests/unittest/llmapi/apps/test_harmony_parsing.py: The test removes the _vocab_size check and retains the logit_bias error assertion. The test is listed in tests/integration/test_lists/test-db/l0_cpu.yml.

Description

Dead code deleted ahead of the trtllm-serve module moves (epic TRTLLM-17056, task TRTLLM-17273): a move PR copies code verbatim, so anything dead would be carried into the new files and cleaned up there with worse history. This PR deletes six dead items, each proven below on the base commit, keeps a single definition of SERVER_TIMING_HEADER, and (optional seventh item, flagged for reviewers) deletes the OpenAIServer._vocab_size property that only one test read.

Part of the trtllm-serve refactor: cleanup before the moves.

# Item deleted Proof it is dead (command on the base commit, f6c4125)
1 PrefixBlockSet (serve/router_utils.py), its __all__ entry, and the then-unused List import git grep -n "PrefixBlockSet" -> exactly the definition (router_utils.py:90) and the __all__ entry (:86); no caller, test, or doc
2 is_delegating_client parameter of build_disagg_routers (serve/router.py), its docstring sentence, the del, and both keyword call sites in serve/disagg_coordinator.py git grep -n "is_delegating_client" -> only those six lines; the function ran del is_delegating_client before any use, so the callers' opposite values changed nothing. Both callers passed it by keyword: no positional call shifts
3 ServerState.is_healthy (serve/router.py) git grep -nE "\.is_healthy\b" and git grep -nE "['\"]is_healthy['\"]" -> both no hit (two pipe-free commands so the raw markdown stays copy-paste-correct; their union is the alternation \.is_healthy\b or quoted is_healthy); health polling goes through Router._check_server_health. ServerState._session and _base_url stay: KvCacheAwareServerState uses them
4 duplicate SERVER_TIMING_HEADER definitions (serve/perf_metrics.py:197, serve/visual_gen_metrics.py:12) git grep -n "SERVER_TIMING_HEADER = " -> exactly those two; the modules do not import each other
5 commented-out code in serve/harmony_adapter.py (:959-962, :1437-1438, :1442) comments only; the block at :959-962 is deleted, not restored: uncommented it raises UnboundLocalError (it reads function_name before its first assignment), and the recipient cleanup it wanted is done where function_name is assigned (str(msg_recipient).split("functions.")[-1]). The to-do comment at :650 stays
6 cli_derived_fields["build_config"] (commands/serve.py) the only caller passes keys of cli_maybe_overrides, which never contains build_config; build_config appears zero times in llmapi/llm_args.py, so it is not a TorchLlmArgs field; tests/unittest/llmapi/test_llm_args.py asserts "build_config" not in llm_args (:3619, :3644, :3704)
7 optional: OpenAIServer._vocab_size (serve/openai_server.py) git grep -nw "_vocab_size" -> the definition and one test read (tests/unittest/llmapi/apps/test_harmony_parsing.py:1564); no getattr string form anywhere. The test keeps its pytest.raises logit-bias assertion and drops the property read with its object.__new__(OpenAIServer) server; the file's OpenAIServer try-import goes with it (ten try-imported names remain)

The unused local vocab_size in openai_chat stays: evaluating it is the first self.tokenizer.tokenizer dereference, so deleting it changes the answer of a server without a tokenizer.

SERVER_TIMING_HEADER now lives in serve/_perf_metrics_schema.py, a leaf module importing only typing and typing_extensions, and is re-exported by both old modules, so from tensorrt_llm.serve.perf_metrics import SERVER_TIMING_HEADER and from tensorrt_llm.serve.visual_gen_metrics import SERVER_TIMING_HEADER keep working. Keeping either existing definition instead would couple the two serving paths: the LLM server would import the VisualGen metrics module or VisualGen serving (and the published client serve/scripts/benchmark_visual_gen.py) would load perf_metrics.py and, through it, tensorrt_llm.llmapi.disagg_utils. Note for a later move of visual_gen_metrics.py: both modules use the imported name themselves today, which keeps the formatters from stripping the import; a moved module should add SERVER_TIMING_HEADER to its __all__.

Coordination with in-flight PRs: #21062 and #13400 edit openai_server.py in the region of the deleted _vocab_size property (one inserts methods below it, one refactors it into a delegate that still has no production reader); #17439 appends tests directly after the edited test in test_harmony_parsing.py; #20843 has a disagg_coordinator.py hunk whose context includes the rewritten comment; #20739, #19197 and #20280 touch the two metrics files on other lines. Whichever side lands second rebases; none of these changes the deadness of any item. For #17056 and #16909 the whole-PR diff is not fetchable through gh pr diff; their per-file openai_server.py patches (files API) contain no _vocab_size reference, so the worst case is a textual rebase conflict near the deleted helper — deadness unaffected.

Out of scope, on purpose: DisaggPerfMetricsCollector(max_requests) looks dead (del max_requests) but is not — deleting the parameter would make the disagg config's top-level perf_metrics_max_requests fall through extract_disagg_cfg's **kwargs to the context and generation servers, where it is a real BaseLlmArgs field, silently configuring the workers; it needs its own PR together with the five YAML files in tests/integration/defs/disaggregated/test_configs/ that set the key. The five llm_args.pop("build_config", None) calls also stay: they still swallow stale YAML keys, and removing them is a behavior change.

Behavior

No behavior change.

Moves

No file moves; one constant moved to serve/_perf_metrics_schema.py with both old modules re-exporting it (the re-exports are plain imports that the modules themselves also use).

CI bookkeeping

  • Multi-GPU table: none (no file created, moved or deleted; the listed serve/openai_server.py, serve/router.py, serve/router_utils.py entries still match existing files)
  • CODEOWNERS: none
  • legacy-files.txt: none (every edited file keeps its path and group)
  • Test lists: none (no new test file; the one edited test keeps its registration)

Test Coverage

No new tests: each deleted item has no caller, and the existing tests cover every changed file (ran on this branch with the editable build at the base commit):

  • git grep -nE "PrefixBlockSet|is_delegating_client|async def is_healthy" -- tensorrt_llm tests -> empty; git grep -nw "_vocab_size" -- tensorrt_llm/serve tests/unittest/llmapi -> empty; git grep -n "SERVER_TIMING_HEADER = " -- tensorrt_llm -> one line (serve/_perf_metrics_schema.py); git grep -n '"build_config":' -- tensorrt_llm/commands -> empty
  • python -c "from tensorrt_llm.serve import perf_metrics, visual_gen_metrics, _perf_metrics_schema as s; assert perf_metrics.SERVER_TIMING_HEADER is visual_gen_metrics.SERVER_TIMING_HEADER is s.SERVER_TIMING_HEADER == 'Server-Timing'" -> passes
  • python -c "import tensorrt_llm.serve.scripts.benchmark_visual_gen" -> passes
  • pytest -m cpu_only tests/unittest/disaggregated -q -> 1263 passed, 1 skipped, 2 xfailed; the one failure, test_kv_transfer_fail_stop.py::test_openmpi_subcommunicator_abort_also_terminates_other_executor_in_job, is a teardown-timing race on a loaded box (asserts an mpirun worker is already reaped right after launcher exit): it passed in another full-suite run of the same commit and passes twice in isolation
  • pytest -m cpu_only tests/unittest/_torch/visual_gen/test_trtllm_serve_endpoints.py tests/unittest/llmapi/test_llm_args.py -q -k "serve_endpoints or non_default_or_required or build_config or Server" -> 160 passed, 451 deselected
  • LLM_MODELS_ROOT=... pytest -rs tests/unittest/llmapi/apps/test_harmony_parsing.py tests/unittest/llmapi/apps/test_harmony_channel_validation.py -> 79 passed, no "not importable" skip
  • pre-commit run --files <all ten files> twice -> clean both times
  • A differential property check of is_non_default_or_required (old vs new extracted sources over an exhaustive bounded input grid plus Hypothesis examples): identical everywhere except param_name == "build_config", where the only change is the deleted entry's branch; four planted bugs in the dict handling were each detected by the property
  • GPU (CI): the single-GPU disaggregated e2e block and the multi-GPU stages (three edited files are in the multi-GPU trigger table)

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why.
  • PR follows the coding guidelines.
  • Test coverage: listed above.
  • To be ticked by reviewers.

🤖 Generated with Claude Code

…odule moves

Delete code no production path uses, so the upcoming serve file moves do
not carry it along:

- PrefixBlockSet in serve/router_utils.py (never instantiated anywhere;
  the KV-cache-aware router keeps its own per-server set state) and the
  then-unused List import.
- ServerState.is_healthy in serve/router.py (health polling goes through
  Router._check_server_health; nothing calls the method).
- The is_delegating_client parameter of build_disagg_routers (the function
  deleted the value before any use; both callers passed it by keyword, so
  no positional call shifts).
- The commented-out block in
  HarmonyAdapter._parse_tool_call_from_harmony_message, deleted rather
  than restored: uncommented it would raise UnboundLocalError (it reads
  function_name before its first assignment), and the recipient cleanup it
  wanted is already done where function_name is assigned. Also two
  commented-out debug-log lines in
  stateful_stream_harmony_tokens_to_openai_deltas.
- The "build_config" entry of cli_derived_fields in commands/serve.py:
  is_non_default_or_required is never called with that name, and
  build_config is not a TorchLlmArgs field. The llm_args.pop("build_config")
  calls stay: removing them would change which stale YAML keys are
  swallowed.
- OpenAIServer._vocab_size, read by a single test and no production code;
  the test keeps its logit-bias assertion and drops the property read.

Keep a single definition of SERVER_TIMING_HEADER in the dependency-free
serve/_perf_metrics_schema.py, re-exported by serve/perf_metrics.py and
serve/visual_gen_metrics.py so both existing import paths keep working
and neither serving path has to import the other's metrics module.

No behavior change.

Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
@JunyiXu-nv
JunyiXu-nv requested a review from a team as a code owner October 28, 2026 07:09
@JunyiXu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81129 [ run ] triggered by Bot. Commit: f2a2999 Link to invocation

@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between ba16910 and f2a2999.

Files selected for processing: 10
  • tensorrt_llm/commands/serve.py
  • tensorrt_llm/serve/_perf_metrics_schema.py
  • tensorrt_llm/serve/disagg_coordinator.py
  • tensorrt_llm/serve/harmony_adapter.py
  • tensorrt_llm/serve/openai_server.py
  • tensorrt_llm/serve/perf_metrics.py
  • tensorrt_llm/serve/router.py
  • tensorrt_llm/serve/router_utils.py
  • tensorrt_llm/serve/visual_gen_metrics.py
  • tests/unittest/llmapi/apps/test_harmony_parsing.py
Files with no reviewable changes: 5
  • tensorrt_llm/serve/openai_server.py
  • tensorrt_llm/commands/serve.py
  • tensorrt_llm/serve/harmony_adapter.py
  • tensorrt_llm/serve/router.py
  • tests/unittest/llmapi/apps/test_harmony_parsing.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 9 remain after this review.

Walkthrough

The changes adjust CLI build-config inclusion, centralize the Server-Timing header constant, and remove router APIs, helper code, a private server property, and commented-out code.

Changes

CLI build-config selection

Layer / File(s) Summary
Build-config inclusion
tensorrt_llm/commands/serve.py
Explicit build-config scalar flags no longer automatically cause build_config to be included in llm_args. Other inclusion checks remain.

Shared timing header

Layer / File(s) Summary
Shared response-header constant
tensorrt_llm/serve/_perf_metrics_schema.py, tensorrt_llm/serve/perf_metrics.py, tensorrt_llm/serve/visual_gen_metrics.py
The shared schema defines SERVER_TIMING_HEADER. Both metrics modules import it instead of defining the constant locally.

Router API and helper removal

Layer / File(s) Summary
Disaggregated router construction
tensorrt_llm/serve/router.py, tensorrt_llm/serve/disagg_coordinator.py
build_disagg_routers no longer accepts is_delegating_client. Its coordinator call sites no longer pass that argument.
Router helper removal
tensorrt_llm/serve/router.py, tensorrt_llm/serve/router_utils.py
ServerState.is_healthy and PrefixBlockSet are removed.

Server and Harmony cleanup

Layer / File(s) Summary
Harmony adapter comment cleanup
tensorrt_llm/serve/harmony_adapter.py
Commented-out parsing and streaming code is removed. Executable logic remains unchanged.
Vocabulary-size property removal
tensorrt_llm/serve/openai_server.py, tests/unittest/llmapi/apps/test_harmony_parsing.py
OpenAIServer._vocab_size and its corresponding test assertion are removed. The test for logit-bias conversion without a tokenizer remains.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Possibly related PRs

  • NVIDIA/TensorRT-LLM#20877: Adds Server-Timing response data in serving and VisualGen paths, which shares the header contract centralized here.

Suggested reviewers: schetlur-nv

Merge Risk: Minimal · up to f2a29

The cleanup is mergeable with no identified integration or runtime risk requiring resolution.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the ticket, change type, and primary change: removing dead code from trtllm-serve before module moves.
Description check Passed The description includes the required Description, Test Coverage, and PR Checklist sections. It explains the purpose, scope, behavior impact, removed items, compatibility considerations, and validatio…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes the required Description, Test Coverage, and PR Checklist sections. It explains the purpose, scope, behavior impact, removed items, compatibility considerations, and validation results. It also reports the known test-race failure and its follow-up validation.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 5 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81129 [ run ] completed with state FAILURE. Commit: f2a2999
/LLM/main/L0_MergeRequest_PR pipeline #66833 completed with status: 'FAILURE'

CI Report

⚠️ Resource Maintenance — Test Coverage Reduced:

Resource maintenance in LLM/main/L0_Test-x86_64-Single-GPU #9581: L40S-PyTorch-2 is temporarily paused due to Kubernetes agent provisioning and node issues.
Affected stages:
L40S-PyTorch-2

⚠️ 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

@github-actions

Copy link
Copy Markdown

Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements.

@JunyiXu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81559 [ run ] triggered by Bot. Commit: f2a2999 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81559 [ run ] completed with state SUCCESS. Commit: f2a2999
/LLM/main/L0_MergeRequest_PR pipeline #67226 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

@JunyiXu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81625 [ run ] triggered by Bot. Commit: f2a2999 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81625 [ run ] completed with state SUCCESS. Commit: f2a2999
/LLM/main/L0_MergeRequest_PR pipeline #67290 completed with status: 'SUCCESS'

CI Report

Link to invocation

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants