Repository navigation
fix(serve): use correct argparse attr for sglang tp_size - #665
Conversation
SglangWorkerLauncher._get_tp_size was reading `args.tp_size` but sglang's ServerArgs.add_cli_args registers --tensor-parallel-size as the primary flag (with --tp-size as alias), so argparse stores the value as `args.tensor_parallel_size`. This caused _get_tp_size to always return the default of 1, setting CUDA_VISIBLE_DEVICES to a single GPU regardless of the --tp-size value passed on the CLI. Also rewrites the gpu_env tests to go through parse_serve_args so that CLI flag → attribute name mismatches are caught by tests. Signed-off-by: Chang Su <chang.s.su@oracle.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughswitched Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
Summary of ChangesHello, 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 a critical bug affecting multi-GPU tensor parallelism with the sglang backend in the Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a bug in SglangWorkerLauncher where the tensor parallel size was always defaulting to 1 due to reading the wrong attribute from the argparse namespace. The fix aligns sglang's behavior with vllm by using tensor_parallel_size. Furthermore, the pull request significantly improves the test suite by replacing brittle unit tests that used fabricated Namespace objects with more robust integration-style tests that parse command-line arguments. This ensures that mismatches between CLI flags and their corresponding attribute names are caught by tests, preventing similar issues in the future. The changes are correct and the test improvements are excellent.
The sglang/vllm integration tests called parse_serve_args without mocking _import_backend_args, causing failures in environments where sglang/vllm are not installed (including CI unit test job). Mock the backend arg adders to simulate the --tensor-parallel-size and --tp-size flags that each backend would register. Signed-off-by: Chang Su <chang.s.su@oracle.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b596264d0e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Description
Problem
SglangWorkerLauncher._get_tp_sizereadsargs.tp_size, but sglang'sServerArgs.add_cli_argsregisters--tensor-parallel-sizeas the primary flag (with--tp-sizeas alias). Argparse derives the dest from the first flag name, storing the value asargs.tensor_parallel_size. This means_get_tp_sizealways returns the default1, causingCUDA_VISIBLE_DEVICESto be set to a single GPU — regardless of what--tp-sizeor--tensor-parallel-sizevalue is passed on the CLI.This results in
CUDA error: invalid device ordinalwhen running multi-GPU TP withsmg serve --backend sglang --tp-size N.Solution
SglangWorkerLauncher._get_tp_sizeto readargs.tensor_parallel_size(matchingVllmWorkerLauncherwhich already does this correctly).parse_serve_args(integration-style) so CLI flag → attribute name mismatches are caught by tests, rather than fabricatingargparse.Namespaceobjects with arbitrary attribute names.Changes
bindings/python/src/smg/serve.py: FixSglangWorkerLauncher._get_tp_sizeto readtensor_parallel_sizeinstead oftp_size.bindings/python/tests/test_serve.py: Add integration tests that parse CLI args throughparse_serve_argsbefore checkinggpu_envoutput for sglang, vllm, and trtllm. Update existing unit tests to use the correct attribute name.Test Plan
test_sglang_tp_from_cli,test_vllm_tp_from_cli,test_trtllm_tp_from_cliverify that--tp-size 4on the CLI producesCUDA_VISIBLE_DEVICES=0,1,2,3.test_sglang_tp_from_clifails on the old code becauseparse_serve_argsstores the value astensor_parallel_size, nottp_size.Checklist
cargo +nightly fmtpassescargo clippy --all-targets --all-features -- -D warningspassesSummary by CodeRabbit
Changes
Tests