Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
ef18b0ed
Unverified
Commit
ef18b0ed
authored
Jan 19, 2025
by
Byron Hsu
Committed by
GitHub
Jan 19, 2025
Browse files
[router] Allow empty worker list for sglang.launch_router (#2979)
parent
53cc91e5
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
46 additions
and
17 deletions
+46
-17
.github/workflows/pr-test-rust.yml
.github/workflows/pr-test-rust.yml
+2
-2
scripts/ci_install_rust.sh
scripts/ci_install_rust.sh
+8
-3
sgl-router/README.md
sgl-router/README.md
+10
-0
sgl-router/py_src/sglang_router/launch_router.py
sgl-router/py_src/sglang_router/launch_router.py
+3
-3
sgl-router/py_src/sglang_router/launch_server.py
sgl-router/py_src/sglang_router/launch_server.py
+1
-1
sgl-router/py_src/sglang_router/version.py
sgl-router/py_src/sglang_router/version.py
+1
-1
sgl-router/py_test/test_launch_router.py
sgl-router/py_test/test_launch_router.py
+20
-6
sgl-router/pyproject.toml
sgl-router/pyproject.toml
+1
-1
No files found.
.github/workflows/pr-test-rust.yml
View file @
ef18b0ed
...
@@ -40,7 +40,7 @@ jobs:
...
@@ -40,7 +40,7 @@ jobs:
cd sgl-router/
cd sgl-router/
cargo test
cargo test
e2e-
rust
:
e2e-
python
:
if
:
github.repository == 'sgl-project/sglang' || github.event_name == 'pull_request'
if
:
github.repository == 'sgl-project/sglang' || github.event_name == 'pull_request'
runs-on
:
2-gpu-runner
runs-on
:
2-gpu-runner
steps
:
steps
:
...
@@ -65,7 +65,7 @@ jobs:
...
@@ -65,7 +65,7 @@ jobs:
python3 run_suite.py
python3 run_suite.py
finish
:
finish
:
needs
:
[
unit-test-rust
,
e2e-
rust
]
needs
:
[
unit-test-rust
,
e2e-
python
]
runs-on
:
ubuntu-latest
runs-on
:
ubuntu-latest
steps
:
steps
:
-
name
:
Finish
-
name
:
Finish
...
...
scripts/ci_install_rust.sh
View file @
ef18b0ed
#!/bin/bash
#!/bin/bash
set
-euxo
pipefail
set
-euxo
pipefail
# these are required for actix
# Check if sudo is available
apt-get update
if
command
-v
sudo
>
/dev/null 2>&1
;
then
apt-get
install
-y
libssl-dev pkg-config
sudo
apt-get update
sudo
apt-get
install
-y
libssl-dev pkg-config
else
apt-get update
apt-get
install
-y
libssl-dev pkg-config
fi
# Install rustup (Rust installer and version manager)
# Install rustup (Rust installer and version manager)
curl
--proto
'=https'
--tlsv1
.2
-sSf
https://sh.rustup.rs | sh
-s
--
-y
curl
--proto
'=https'
--tlsv1
.2
-sSf
https://sh.rustup.rs | sh
-s
--
-y
...
...
sgl-router/README.md
View file @
ef18b0ed
...
@@ -67,6 +67,16 @@ $ pip install -e .
...
@@ -67,6 +67,16 @@ $ pip install -e .
**Note:**
When modifying Rust code, you must rebuild the wheel for changes to take effect.
**Note:**
When modifying Rust code, you must rebuild the wheel for changes to take effect.
### Troubleshooting
1.
If rust analyzer is not working in VSCode, set
`rust-analyzer.linkedProjects`
to the absolute path of
`Cargo.toml`
in your repo. For example:
```
json
{
"rust-analyzer.linkedProjects"
:
[
"/workspaces/sglang/sgl-router/Cargo.toml"
]
}
```
### CI/CD Setup
### CI/CD Setup
The continuous integration pipeline consists of three main steps:
The continuous integration pipeline consists of three main steps:
...
...
sgl-router/py_src/sglang_router/launch_router.py
View file @
ef18b0ed
...
@@ -27,7 +27,7 @@ def setup_logger():
...
@@ -27,7 +27,7 @@ def setup_logger():
@
dataclasses
.
dataclass
@
dataclasses
.
dataclass
class
RouterArgs
:
class
RouterArgs
:
# Worker configuration
# Worker configuration
worker_urls
:
List
[
str
]
worker_urls
:
List
[
str
]
=
dataclasses
.
field
(
default_factory
=
list
)
host
:
str
=
"127.0.0.1"
host
:
str
=
"127.0.0.1"
port
:
int
=
30000
port
:
int
=
30000
...
@@ -141,8 +141,9 @@ class RouterArgs:
...
@@ -141,8 +141,9 @@ class RouterArgs:
use_router_prefix: If True, look for arguments with 'router-' prefix
use_router_prefix: If True, look for arguments with 'router-' prefix
"""
"""
prefix
=
"router_"
if
use_router_prefix
else
""
prefix
=
"router_"
if
use_router_prefix
else
""
worker_urls
=
args
.
worker_urls
if
args
.
worker_urls
is
not
None
else
[]
return
cls
(
return
cls
(
worker_urls
=
args
.
worker_urls
,
worker_urls
=
worker_urls
,
host
=
args
.
host
,
host
=
args
.
host
,
port
=
args
.
port
,
port
=
args
.
port
,
policy
=
getattr
(
args
,
f
"
{
prefix
}
policy"
),
policy
=
getattr
(
args
,
f
"
{
prefix
}
policy"
),
...
@@ -237,7 +238,6 @@ Examples:
...
@@ -237,7 +238,6 @@ Examples:
def
main
()
->
None
:
def
main
()
->
None
:
logger
=
setup_logger
()
router_args
=
parse_router_args
(
sys
.
argv
[
1
:])
router_args
=
parse_router_args
(
sys
.
argv
[
1
:])
router
=
launch_router
(
router_args
)
router
=
launch_router
(
router_args
)
...
...
sgl-router/py_src/sglang_router/launch_server.py
View file @
ef18b0ed
...
@@ -23,7 +23,7 @@ def setup_logger():
...
@@ -23,7 +23,7 @@ def setup_logger():
logger
.
setLevel
(
logging
.
INFO
)
logger
.
setLevel
(
logging
.
INFO
)
formatter
=
logging
.
Formatter
(
formatter
=
logging
.
Formatter
(
"[Router (Python)] %(asctime)s - %(levelname)s - %(message)s"
,
"[Router (Python)] %(asctime)s - %(levelname)s - %(message)s
- %(filename)s:%(lineno)d
"
,
datefmt
=
"%Y-%m-%d %H:%M:%S"
,
datefmt
=
"%Y-%m-%d %H:%M:%S"
,
)
)
...
...
sgl-router/py_src/sglang_router/version.py
View file @
ef18b0ed
__version__
=
"0.1.
1
"
__version__
=
"0.1.
2
"
sgl-router/py_test/test_launch_router.py
View file @
ef18b0ed
...
@@ -22,11 +22,9 @@ def terminate_process(process: multiprocessing.Process, timeout: float = 1.0) ->
...
@@ -22,11 +22,9 @@ def terminate_process(process: multiprocessing.Process, timeout: float = 1.0) ->
class
TestLaunchRouter
(
unittest
.
TestCase
):
class
TestLaunchRouter
(
unittest
.
TestCase
):
def
test_launch_router_no_exception
(
self
):
def
setUp
(
self
):
"""Set up default arguments for router tests."""
# Create SimpleNamespace with default arguments
self
.
default_args
=
SimpleNamespace
(
args
=
SimpleNamespace
(
worker_urls
=
[
"http://localhost:8000"
],
host
=
"127.0.0.1"
,
host
=
"127.0.0.1"
,
port
=
30000
,
port
=
30000
,
policy
=
"cache_aware"
,
policy
=
"cache_aware"
,
...
@@ -39,6 +37,15 @@ class TestLaunchRouter(unittest.TestCase):
...
@@ -39,6 +37,15 @@ class TestLaunchRouter(unittest.TestCase):
verbose
=
False
,
verbose
=
False
,
)
)
def
create_router_args
(
self
,
**
kwargs
):
"""Create router arguments by updating default args with provided kwargs."""
args_dict
=
vars
(
self
.
default_args
).
copy
()
args_dict
.
update
(
kwargs
)
return
SimpleNamespace
(
**
args_dict
)
def
run_router_process
(
self
,
args
):
"""Run router in a separate process and verify it starts successfully."""
def
run_router
():
def
run_router
():
try
:
try
:
from
sglang_router.launch_router
import
launch_router
from
sglang_router.launch_router
import
launch_router
...
@@ -51,7 +58,6 @@ class TestLaunchRouter(unittest.TestCase):
...
@@ -51,7 +58,6 @@ class TestLaunchRouter(unittest.TestCase):
print
(
e
)
print
(
e
)
return
1
return
1
# Start router in separate process
process
=
multiprocessing
.
Process
(
target
=
run_router
)
process
=
multiprocessing
.
Process
(
target
=
run_router
)
try
:
try
:
process
.
start
()
process
.
start
()
...
@@ -62,6 +68,14 @@ class TestLaunchRouter(unittest.TestCase):
...
@@ -62,6 +68,14 @@ class TestLaunchRouter(unittest.TestCase):
finally
:
finally
:
terminate_process
(
process
)
terminate_process
(
process
)
def
test_launch_router_common
(
self
):
args
=
self
.
create_router_args
(
worker_urls
=
[
"http://localhost:8000"
])
self
.
run_router_process
(
args
)
def
test_launch_router_with_empty_worker_urls
(
self
):
args
=
self
.
create_router_args
(
worker_urls
=
[])
self
.
run_router_process
(
args
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
sgl-router/pyproject.toml
View file @
ef18b0ed
...
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
...
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
[project]
name
=
"sglang-router"
name
=
"sglang-router"
version
=
"0.1.
1
"
version
=
"0.1.
2
"
description
=
"SGLang router is a standalone module implemented in Rust to achieve data parallelism across SGLang instances."
description
=
"SGLang router is a standalone module implemented in Rust to achieve data parallelism across SGLang instances."
authors
=
[
{name
=
"Byron Hsu"
,
email
=
"byronhsu1230@gmail.com"
}
]
authors
=
[
{name
=
"Byron Hsu"
,
email
=
"byronhsu1230@gmail.com"
}
]
requires-python
=
">=3.8"
requires-python
=
">=3.8"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment