Skip to content

Commit 0287aee

Browse files
slin1237ssssnow
authored andcommitted
[bugfix] fix router python parser for pd urls (#8644)
1 parent 83decc8 commit 0287aee

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

sgl-router/py_src/sglang_router/launch_router.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,11 @@ def add_cli_args(
145145
)
146146
parser.add_argument(
147147
f"--{prefix}prefill",
148-
nargs=2,
148+
nargs="+",
149149
action="append",
150-
metavar=("URL", "BOOTSTRAP_PORT"),
151-
help="Prefill server URL and bootstrap port. Can be specified multiple times. BOOTSTRAP_PORT can be 'none' for no bootstrap port.",
150+
help="Prefill server URL and optional bootstrap port. Can be specified multiple times. "
151+
"Format: --prefill URL [BOOTSTRAP_PORT]. "
152+
"BOOTSTRAP_PORT can be a port number, 'none', or omitted (defaults to none).",
152153
)
153154
parser.add_argument(
154155
f"--{prefix}decode",
@@ -389,24 +390,36 @@ def _parse_selector(selector_list):
389390
def _parse_prefill_urls(prefill_list):
390391
"""Parse prefill URLs from --prefill arguments.
391392
392-
Format: --prefill URL BOOTSTRAP_PORT
393-
Example: --prefill http://prefill1:8080 9000 --prefill http://prefill2:8080 none
393+
Format: --prefill URL [BOOTSTRAP_PORT]
394+
Example:
395+
--prefill http://prefill1:8080 9000 # With bootstrap port
396+
--prefill http://prefill2:8080 none # Explicitly no bootstrap port
397+
--prefill http://prefill3:8080 # Defaults to no bootstrap port
394398
"""
395399
if not prefill_list:
396400
return []
397401

398402
prefill_urls = []
399-
for url, bootstrap_port_str in prefill_list:
400-
# Handle 'none' as None
401-
if bootstrap_port_str.lower() == "none":
402-
bootstrap_port = None
403+
for prefill_args in prefill_list:
404+
405+
url = prefill_args[0]
406+
407+
# Handle optional bootstrap port
408+
if len(prefill_args) >= 2:
409+
bootstrap_port_str = prefill_args[1]
410+
# Handle 'none' as None
411+
if bootstrap_port_str.lower() == "none":
412+
bootstrap_port = None
413+
else:
414+
try:
415+
bootstrap_port = int(bootstrap_port_str)
416+
except ValueError:
417+
raise ValueError(
418+
f"Invalid bootstrap port: {bootstrap_port_str}. Must be a number or 'none'"
419+
)
403420
else:
404-
try:
405-
bootstrap_port = int(bootstrap_port_str)
406-
except ValueError:
407-
raise ValueError(
408-
f"Invalid bootstrap port: {bootstrap_port_str}. Must be a number or 'none'"
409-
)
421+
# No bootstrap port specified, default to None
422+
bootstrap_port = None
410423

411424
prefill_urls.append((url, bootstrap_port))
412425

@@ -578,13 +591,20 @@ def parse_router_args(args: List[str]) -> RouterArgs:
578591
579592
# PD disaggregated mode with same policy for both
580593
python -m sglang_router.launch_router --pd-disaggregation \\
581-
--prefill http://prefill1:8000 9000 --prefill http://prefill2:8000 none \\
594+
--prefill http://prefill1:8000 9000 --prefill http://prefill2:8000 \\
582595
--decode http://decode1:8001 --decode http://decode2:8001 \\
583596
--policy cache_aware
584597
598+
# PD mode with optional bootstrap ports
599+
python -m sglang_router.launch_router --pd-disaggregation \\
600+
--prefill http://prefill1:8000 9000 \\ # With bootstrap port
601+
--prefill http://prefill2:8000 none \\ # Explicitly no bootstrap port
602+
--prefill http://prefill3:8000 \\ # Defaults to no bootstrap port
603+
--decode http://decode1:8001 --decode http://decode2:8001
604+
585605
# PD mode with different policies for prefill and decode
586606
python -m sglang_router.launch_router --pd-disaggregation \\
587-
--prefill http://prefill1:8000 9000 --prefill http://prefill2:8000 none \\
607+
--prefill http://prefill1:8000 --prefill http://prefill2:8000 \\
588608
--decode http://decode1:8001 --decode http://decode2:8001 \\
589609
--prefill-policy cache_aware --decode-policy power_of_two
590610

0 commit comments

Comments
 (0)