Unverified Commit ef18b0ed authored by Byron Hsu's avatar Byron Hsu Committed by GitHub
Browse files

[router] Allow empty worker list for sglang.launch_router (#2979)

parent 53cc91e5
...@@ -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
......
#!/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
......
...@@ -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:
......
...@@ -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)
......
...@@ -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",
) )
......
__version__ = "0.1.1" __version__ = "0.1.2"
...@@ -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()
...@@ -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"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment