Skip to content

fix parameters pass through for trtllm - #509

Merged
slin1237 merged 2 commits into
mainfrom
wei/fix-trtllm
Feb 23, 2026
Merged

slin1237 merged 2 commits into
mainfrom
wei/fix-trtllm

Conversation

@gongwei-130

@gongwei-130 gongwei-130 commented Feb 22, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Problem

TensorRT-LLM doesn't provide a centralized argument manager like vLLM's EngineArgs. It is not feasible to add them all manually.

https://github.com/lightseekorg/smg/blob/main/bindings/python/src/smg/serve.py#L469-L486

The are two pass to passing args
Pass 1: serve + router args only; unknown tokens become backend_args
Pass 2: full parser with backend-specific args;

pass 2 would fail with trtllm since trtllm doesn't provide a centralized argument manager.

Fix:

At pass 2, change to use parse_known_args, best effort to recognize args, if not, just ignore it for trtllm.

Solution

Changes

Test Plan

Checklist
  • cargo +nightly fmt passes
  • cargo clippy --all-targets --all-features -- -D warnings passes
  • (Optional) Documentation updated

Summary by CodeRabbit

  • Bug Fixes
    • Renamed TensorRT-LLM CLI flag for tensor-parallel size from --tp-size to --tp_size.
    • Updated CLI parsing so TensorRT-LLM backend receives its backend-specific options unchanged.
    • Stricter validation now rejects unknown backend-specific flags for non-TensorRT-LLM backends.

@github-actions github-actions Bot added the python-bindings Python bindings changes label Feb 22, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @gongwei-130, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue with parameter passing for the TensorRT-LLM backend, which lacked a centralized argument manager. The core change involves adapting the argument parsing strategy to use parse_known_args specifically for trtllm, preventing failures when encountering unknown arguments. Additionally, it refines the TensorRT-LLM specific command-line options for better usability.

Highlights

  • TensorRT-LLM Argument Handling: Modified the argument parsing mechanism for the TensorRT-LLM backend to use parse_known_args, allowing it to gracefully handle unrecognized arguments instead of failing.
  • TensorRT-LLM CLI Options Refinement: Updated the command-line interface for TensorRT-LLM by removing the --config argument and renaming --tp-size to --tp_size for consistency.
Changelog
  • bindings/python/src/smg/serve.py
    • Changed parser.parse_args to parser.parse_known_args when the backend is trtllm.
    • Removed the --config argument from _add_trtllm_stub_args.
    • Renamed the --tp-size argument to --tp_size in _add_trtllm_stub_args.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@coderabbitai

coderabbitai Bot commented Feb 22, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Updated CLI parsing in bindings/python/src/smg/serve.py: the TensorRT-LLM tensor-parallel flag was changed from --tp-size to --tp_size, the separate --config stub was removed, and the trtllm backend's second-pass parsing now uses parse_known_args so backend-specific tokens are preserved in backend_args. Tests updated accordingly.

Changes

Cohort / File(s) Summary
Serve parsing logic
bindings/python/src/smg/serve.py
Replaced --tp-size stub with --tp_size; removed standalone --config stub; for backend == "trtllm" the second-pass parse uses parse_known_args so backend-only tokens (e.g., --config) are kept in backend_args.
Tests updated
bindings/python/tests/test_serve.py
Updated tests to use parse_known_args in relevant assertions so --config (and similar backend-specific flags) appear in backend_args; adjusted unknown-flag handling test to use a backend that rejects unknown flags in pass 2.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • CatherineSue
  • key4ng
  • slin1237

Poem

🐰 I hopped through flags both dash and snake,
parse_known_args lets backend tokens wake,
Model path kept, config gently stored,
Tests hop along as parsing is restored,
A tiny rabbit cheer for flags we make.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix parameters pass through for trtllm' directly addresses the main change: enabling proper parameter passing for the trtllm backend by switching to parse_known_args.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch wei/fix-trtllm

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@mergify

mergify Bot commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Hi @gongwei-130, the DCO sign-off check has failed. All commits must include a Signed-off-by line.

To fix existing commits:

# Sign off the last N commits (replace N with the number of unsigned commits)
git rebase HEAD~N --signoff
git push --force-with-lease

To sign off future commits automatically:

  • Use git commit -s every time, or
  • VSCode: enable Git: Always Sign Off in Settings
  • PyCharm: enable Sign-off commit in the Commit tool window

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request addresses the challenge of passing parameters to TensorRT-LLM by switching to parse_known_args for the trtllm backend. This allows the system to recognize known arguments and ignore unknown ones, which is necessary because TensorRT-LLM lacks a centralized argument manager like vLLM's EngineArgs. Additionally, the --config argument has been removed from _add_trtllm_stub_args as it was not being used directly as a CLI argument for trtllm and the --tp-size argument was renamed to --tp_size for consistency. These changes improve the flexibility and robustness of argument parsing for the trtllm backend. All comments are valid and align with the provided rules.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 30ea60920d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

required=False,
help="Config file path (YAML, optional - must contain tensor_parallel_size if provided)",
)
group.add_argument("--tp_size", type=int, help="Tensor parallel size (overrides config file)")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore --tp-size flag spelling for TensorRT-LLM

Changing the stub flag from --tp-size to --tp_size breaks existing CLI usage and silently drops TP size in the orchestrator path: users passing --tp-size now leave args.tp_size unset, so TrtllmWorkerLauncher._get_tp_size() falls back to defaults while the raw token is only forwarded in backend_args. In multi-worker runs this mis-sizes CUDA_VISIBLE_DEVICES and can cause incorrect GPU allocation or worker startup failures.

Useful? React with 👍 / 👎.

Comment on lines +479 to +480
if backend == "trtllm":
args, _ = parser.parse_known_args(argv)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep --config in parsed args before TP sizing

Using parse_known_args for trtllm while no longer defining --config means config is discarded from args, but _get_tp_size() depends on args.config to read tensor parallel size from YAML. As a result, launches that specify TP only via --config now default to TP=1 for GPU env assignment, which can overlap GPUs across data-parallel workers and break startup.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
bindings/python/src/smg/serve.py (1)

357-367: ⚠️ Potential issue | 🟠 Major

--config is never registered — the YAML tp_size fallback in _get_tp_size is unreachable dead code

TrtllmWorkerLauncher._get_tp_size reads getattr(args, "config", None) at line 189 to find the YAML config path, but --config is never added to any parser (_add_trtllm_stub_args, add_serve_args, or RouterArgs). Even after switching to parse_known_args in pass 2, --config is still not in the trtllm parser, so argparse silently drops it into _ and args.config remains None. The entire if config_path: block (lines 190–202) is therefore permanently unreachable.

The downstream impact is silent: a user who passes --config model.yaml expecting the YAML's tensor_parallel_size to drive CUDA_VISIBLE_DEVICES will instead get tp_size=1, leading to wrong GPU assignment for multi-GPU workers.

Fix: add --config to the stub so it is parsed into args.config.

🐛 Proposed fix
 def _add_trtllm_stub_args(parser: argparse.ArgumentParser) -> None:
     group = parser.add_argument_group("TensorRT-LLM Options")
     group.add_argument("--model", type=str, help="Model path (HuggingFace ID or local path)")
     group.add_argument("--tp_size", type=int, help="Tensor parallel size (overrides config file)")
+    group.add_argument(
+        "--config",
+        type=str,
+        default=None,
+        help="Path to TensorRT-LLM YAML config file (used to read tensor_parallel_size)",
+    )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bindings/python/src/smg/serve.py` around lines 357 - 367, The trt-llm CLI
never registers --config so TrtllmWorkerLauncher._get_tp_size never sees
args.config; update _add_trtllm_stub_args to register the config option by
adding a group.add_argument("--config", type=str, help="Path to YAML config
file") (alongside existing --model and --tp_size) so argparse will populate
args.config and allow _get_tp_size to read tensor_parallel_size from the YAML.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bindings/python/src/smg/serve.py`:
- Around line 479-483: When backend == "trtllm" the call to
parser.parse_known_args(argv) drops unknown tokens into the discard variable `_`
without feedback; update the branch handling parse_known_args to detect if `_`
is non-empty and emit a debug/warn log listing those discarded tokens (include
context like the backend and argv), so callers see misspelled flags; keep
existing behavior of returning backend, args, backend_args and do not change the
parse logic otherwise (refer to parser.parse_known_args, the `_` discard
variable, args, and the backend == "trtllm" branch).

---

Outside diff comments:
In `@bindings/python/src/smg/serve.py`:
- Around line 357-367: The trt-llm CLI never registers --config so
TrtllmWorkerLauncher._get_tp_size never sees args.config; update
_add_trtllm_stub_args to register the config option by adding a
group.add_argument("--config", type=str, help="Path to YAML config file")
(alongside existing --model and --tp_size) so argparse will populate args.config
and allow _get_tp_size to read tensor_parallel_size from the YAML.

Comment on lines +479 to 483
if backend == "trtllm":
args, _ = parser.parse_known_args(argv)
else:
args = parser.parse_args(argv)
return backend, args, backend_args

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Log the discarded tokens from parse_known_args to aid diagnosis

Unknown args in pass 2 are silently dropped into _. A user who misspells a serve-level flag (e.g., --tp-size instead of --tp_size) will get no feedback: pass 2 silently ignores it, args.tp_size stays None, and GPU assignment defaults to 1. Adding a debug log of the discarded tokens makes this easier to catch.

♻️ Proposed change
     if backend == "trtllm":
-        args, _ = parser.parse_known_args(argv)
+        args, unknown = parser.parse_known_args(argv)
+        if unknown:
+            logger.debug(
+                "trtllm: ignoring unrecognized args in pass-2 parse (will be forwarded via backend_args): %s",
+                unknown,
+            )
     else:
         args = parser.parse_args(argv)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bindings/python/src/smg/serve.py` around lines 479 - 483, When backend ==
"trtllm" the call to parser.parse_known_args(argv) drops unknown tokens into the
discard variable `_` without feedback; update the branch handling
parse_known_args to detect if `_` is non-empty and emit a debug/warn log listing
those discarded tokens (include context like the backend and argv), so callers
see misspelled flags; keep existing behavior of returning backend, args,
backend_args and do not change the parse logic otherwise (refer to
parser.parse_known_args, the `_` discard variable, args, and the backend ==
"trtllm" branch).

Signed-off-by: gongwei-130 <weigong28@gmail.com>
@github-actions github-actions Bot added the tests Test changes label Feb 23, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2ebedd33fd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


args = parser.parse_args(argv)
if backend == "trtllm":
args, _ = parser.parse_known_args(argv)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject unknown non-backend flags in trtllm parsing

Using parse_known_args here and dropping the unknown list makes typos in SMG-owned CLI flags silently bypass validation for trtllm. In that case the mistyped option falls back to defaults in args (for example, a misspelled worker port flag keeps worker_base_port=31000) and is forwarded as backend passthrough, which can break worker startup if TensorRT-LLM does not recognize it.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
bindings/python/src/smg/serve.py (1)

357-367: ⚠️ Potential issue | 🟠 Major

Removing --config from stub args breaks the config-based tp_size fallback

_add_trtllm_stub_args no longer registers --config, and pass 2 now uses parse_known_args which drops --config into _. Consequently args.config is always None in the CLI flow, making the config-YAML path in _get_tp_size (Lines 189–202) permanently unreachable. A user relying on the config file for tp_size will silently get tp_size=1 instead of the correct value — wrong CUDA_VISIBLE_DEVICES assignment and potential misallocation across workers.

The docstring on Line 362 ("TP size is read from the config file, not passed as CLI argument") is now incorrect on both counts: --tp_size is a CLI argument, and the config path is dead.

The docstring on Line 171 ("Priority: args.tp_size > args.tensor_parallel_size > config file > default(1)") should also be updated.

Simplest fix: re-add --config to the stub args so pass 2 populates args.config while backend_args (from pass 1) still carries it through to the worker command:

🐛 Proposed fix
 def _add_trtllm_stub_args(parser: argparse.ArgumentParser) -> None:
     """Add TensorRT-LLM specific arguments.

     Note: TensorRT-LLM doesn't provide a centralized argument manager like
     vLLM's EngineArgs. We manually add the most commonly used arguments.
-    TP size is read from the config file, not passed as CLI argument.
+    --tp_size overrides the value derived from --config; both can coexist.
     """
     group = parser.add_argument_group("TensorRT-LLM Options")
     group.add_argument("--model", type=str, help="Model path (HuggingFace ID or local path)")
     group.add_argument("--tp_size", type=int, help="Tensor parallel size (overrides config file)")
+    group.add_argument("--config", type=str, help="Path to TensorRT-LLM config YAML")

Also fix the stale comment on Line 177:

-        # Try --tp-size argument first
+        # Try --tp_size argument first
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bindings/python/src/smg/serve.py` around lines 357 - 367, The
_add_trtllm_stub_args function removed registration of --config which causes
parse_known_args to drop the flag and makes _get_tp_size never read config;
re-add a --config (str) argument to the TensorRT-LLM argument group so
args.config is populated in the CLI flow, ensure _add_trtllm_stub_args still
registers --tp_size, and update the function docstring and the priority comment
referenced by _get_tp_size to reflect that --tp_size is a CLI argument and that
priority is args.tp_size > args.tensor_parallel_size > config file > default(1);
keep parse_known_args usage but ensure backend_args still forwards config to
workers.
bindings/python/tests/test_serve.py (1)

543-598: 🛠️ Refactor suggestion | 🟠 Major

Config-based tp_size tests bypass the CLI integration, masking the broken flow

All tests in this block call _get_tp_size with a hand-crafted argparse.Namespace(config=str(config_file)). They pass regardless of whether the CLI flow actually populates args.config — which it does not (see the issue raised on serve.py Lines 357–367). Consider adding an integration-level assertion in TestParseServeArgs.test_trtllm_basic to make this gap visible:

# Currently args.config is None because --config is not in stub args;
# if config-based tp_size inference is intended, this assertion should hold:
assert args.config == "/tmp/config.yml"  # will fail until --config is re-added to stub args
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bindings/python/tests/test_serve.py` around lines 543 - 598, Tests call
TrtllmWorkerLauncher._get_tp_size directly with a synthetic
argparse.Namespace(config=...), bypassing the CLI parsing and hiding that the
CLI stub in TestParseServeArgs.test_trtllm_basic does not populate args.config;
add an integration-level check in TestParseServeArgs.test_trtllm_basic (or
update the CLI stub used there) to assert args.config is set to the expected
config path so the suite will fail if --config isn’t wired up, or alternatively
update the CLI stub to include the --config argument so _get_tp_size behavior
through the real parse flow is exercised (refer to _get_tp_size and
TestParseServeArgs.test_trtllm_basic to locate the code).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@bindings/python/src/smg/serve.py`:
- Around line 357-367: The _add_trtllm_stub_args function removed registration
of --config which causes parse_known_args to drop the flag and makes
_get_tp_size never read config; re-add a --config (str) argument to the
TensorRT-LLM argument group so args.config is populated in the CLI flow, ensure
_add_trtllm_stub_args still registers --tp_size, and update the function
docstring and the priority comment referenced by _get_tp_size to reflect that
--tp_size is a CLI argument and that priority is args.tp_size >
args.tensor_parallel_size > config file > default(1); keep parse_known_args
usage but ensure backend_args still forwards config to workers.

In `@bindings/python/tests/test_serve.py`:
- Around line 543-598: Tests call TrtllmWorkerLauncher._get_tp_size directly
with a synthetic argparse.Namespace(config=...), bypassing the CLI parsing and
hiding that the CLI stub in TestParseServeArgs.test_trtllm_basic does not
populate args.config; add an integration-level check in
TestParseServeArgs.test_trtllm_basic (or update the CLI stub used there) to
assert args.config is set to the expected config path so the suite will fail if
--config isn’t wired up, or alternatively update the CLI stub to include the
--config argument so _get_tp_size behavior through the real parse flow is
exercised (refer to _get_tp_size and TestParseServeArgs.test_trtllm_basic to
locate the code).

---

Duplicate comments:
In `@bindings/python/src/smg/serve.py`:
- Around line 479-481: The parse_known_args call discards unrecognized tokens
(second return value) which should be logged for observability: change the line
using parser.parse_known_args(argv) in the branch where backend == "trtllm" to
capture the discarded tokens (e.g., args, discarded =
parser.parse_known_args(argv)), and if discarded is non-empty, emit a log (use
the existing logger in this module, e.g., logger.warning or process_logger.warn)
that includes the discarded tokens and contextual info (like backend and argv)
so operators can see which args were ignored.

Signed-off-by: gongwei-130 <weigong28@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b866556de9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +479 to +480
if backend == "trtllm":
args, _ = parser.parse_known_args(argv)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve --config in parsed trtllm args

Using parse_known_args for the trtllm pass-2 parse here means options that are no longer declared (notably --config after this change) are silently dropped from args. TrtllmWorkerLauncher._get_tp_size() relies on args.config to read tensor-parallel size from YAML before computing CUDA_VISIBLE_DEVICES, so runs that set TP only via config now fall back to tp=1, which can assign overlapping GPUs and fail multi-worker startup.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ebedd3 and b866556.

📒 Files selected for processing (1)
  • bindings/python/tests/test_serve.py
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bindings/python/tests/test_serve.py`:
- Around line 307-310: The test currently exits during backend import (via
_import_backend_args) instead of during pass-2 parsing; fix by stubbing/mocking
_import_backend_args in test_unknown_arg_rejected_in_pass2 so it does nothing
(e.g., monkeypatch _import_backend_args to a no-op or return None), call
parse_serve_args(["--backend", "sglang", "--totally-unknown-flag"]), and assert
it raises SystemExit from the full parser; keep the test name but ensure it no
longer duplicates test_sglang_explicit_exits by verifying the unknown-flag
rejection rather than import failure.
- Around line 158-166: Add a test that verifies the trtllm stub parser accepts
and returns the --tp_size flag: update or add a test in TestAddTrtllmStubArgs
that calls _add_trtllm_stub_args (or uses _import_backend_args for "trtllm") to
build an argparse.Parser, then call parser.parse_known_args with
["--model","/path/to/model","--tp_size","4"] (or similar) and assert args.model
and that the parsed value or backend_args reflect the tp_size as expected;
reference _add_trtllm_stub_args, TestAddTrtllmStubArgs,
TrtllmWorkerLauncher._get_tp_size and parser.parse_known_args to locate the
relevant code to modify.

Comment on lines 158 to +166
def test_trtllm_adds_model_arg(self):
parser = argparse.ArgumentParser()
_import_backend_args("trtllm", parser)
args = parser.parse_args(["--model", "/path/to/model", "--config", "/path/to/config.yml"])
args, backend_args = parser.parse_known_args(
["--model", "/path/to/model", "--config", "/path/to/config.yml"]
)
assert args.model == "/path/to/model"
assert args.config == "/path/to/config.yml"
assert "--config" in backend_args
assert "/path/to/config.yml" in backend_args

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find the serve.py file and examine the implementations

echo "=== Looking for serve.py ==="
fd -t f "serve.py" bindings/python

echo ""
echo "=== Finding _add_trtllm_stub_args ==="
rg -A 20 "def _add_trtllm_stub_args" bindings/python

echo ""
echo "=== Finding _get_tp_size ==="
rg -A 10 "def _get_tp_size" bindings/python

Repository: lightseekorg/smg

Length of output: 5081


🏁 Script executed:

#!/bin/bash
# Get the full TrtllmWorkerLauncher._get_tp_size implementation
echo "=== Full TrtllmWorkerLauncher._get_tp_size ==="
rg -A 30 "class TrtllmWorkerLauncher" bindings/python/src/smg/serve.py | grep -A 30 "_get_tp_size"

echo ""
echo "=== Check if args.config is referenced in TrtllmWorkerLauncher._get_tp_size ==="
sed -n '/class TrtllmWorkerLauncher/,/^class /p' bindings/python/src/smg/serve.py | grep -A 25 "def _get_tp_size" | head -30

Repository: lightseekorg/smg

Length of output: 2147


🏁 Script executed:

#!/bin/bash
# Search for tp_size coverage in tests
echo "=== Searching for tp_size in test file ==="
rg "tp_size" bindings/python/tests/test_serve.py

echo ""
echo "=== Full TestAddTrtllmStubArgs test ==="
sed -n '/class TestAddTrtllmStubArgs/,/^class /p' bindings/python/tests/test_serve.py | head -30

Repository: lightseekorg/smg

Length of output: 2537


Correctly reflects --config removal from stub; --tp_size stub argument lacks direct test coverage.

The switch to parse_known_args and the backend_args assertions accurately exercise the new behavior where --config is no longer a stub argument. However, _add_trtllm_stub_args does add --tp_size as a new argument, yet TestAddTrtllmStubArgs (lines 183-196) lacks a test for it—only testing --model. The _get_tp_size() method is thoroughly tested elsewhere, but the stub argument parser itself should verify that --tp_size can be parsed correctly, following the existing pattern of test_adds_model_arg.

Note: TrtllmWorkerLauncher._get_tp_size safely accesses args.config via getattr(args, "config", None), so the removal of --config from stub args does not cause breakage; it simply falls back to the default.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bindings/python/tests/test_serve.py` around lines 158 - 166, Add a test that
verifies the trtllm stub parser accepts and returns the --tp_size flag: update
or add a test in TestAddTrtllmStubArgs that calls _add_trtllm_stub_args (or uses
_import_backend_args for "trtllm") to build an argparse.Parser, then call
parser.parse_known_args with ["--model","/path/to/model","--tp_size","4"] (or
similar) and assert args.model and that the parsed value or backend_args reflect
the tp_size as expected; reference _add_trtllm_stub_args, TestAddTrtllmStubArgs,
TrtllmWorkerLauncher._get_tp_size and parser.parse_known_args to locate the
relevant code to modify.

Comment on lines 307 to +310
def test_unknown_arg_rejected_in_pass2(self):
"""Unknown args should be rejected by the full parser in pass 2."""
with pytest.raises(SystemExit):
parse_serve_args(["--backend", "trtllm", "--totally-unknown-flag"])
parse_serve_args(["--backend", "sglang", "--totally-unknown-flag"])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

test_unknown_arg_rejected_in_pass2 exits for the wrong reason and duplicates test_sglang_explicit_exits.

Using "sglang" as the backend causes _import_backend_args("sglang", parser) to call parser.error(...) (import failure) and raise SystemExit(2) before pass-2 parsing runs at all. The --totally-unknown-flag token is never evaluated, so the test does not verify what its docstring claims. It is also functionally identical to test_sglang_explicit_exits (lines 267-270), adding no incremental coverage.

The previous "trtllm" backend was also wrong post-PR: trtllm now uses parse_known_args, so the unknown flag would be silently swallowed, not rejected.

To genuinely test pass-2 unknown-arg rejection, mock _import_backend_args so a non-trtllm backend does not error on import:

🛠️ Suggested fix
 def test_unknown_arg_rejected_in_pass2(self):
     """Unknown args should be rejected by the full parser in pass 2."""
-    with pytest.raises(SystemExit):
-        parse_serve_args(["--backend", "sglang", "--totally-unknown-flag"])
+    # Patch _import_backend_args so the backend loads successfully, letting
+    # pass-2 parse_args be the one to reject the unknown flag.
+    with patch("smg.serve._import_backend_args"):
+        with pytest.raises(SystemExit):
+            parse_serve_args(["--backend", "sglang", "--totally-unknown-flag"])
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bindings/python/tests/test_serve.py` around lines 307 - 310, The test
currently exits during backend import (via _import_backend_args) instead of
during pass-2 parsing; fix by stubbing/mocking _import_backend_args in
test_unknown_arg_rejected_in_pass2 so it does nothing (e.g., monkeypatch
_import_backend_args to a no-op or return None), call
parse_serve_args(["--backend", "sglang", "--totally-unknown-flag"]), and assert
it raises SystemExit from the full parser; keep the test name but ensure it no
longer duplicates test_sglang_explicit_exits by verifying the unknown-flag
rejection rather than import failure.

@slin1237
slin1237 merged commit fbbb99b into main Feb 23, 2026
22 checks passed
@slin1237
slin1237 deleted the wei/fix-trtllm branch February 23, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python-bindings Python bindings changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants