-
Notifications
You must be signed in to change notification settings - Fork 6
Add launcher to allow launching worker from router #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zhaochenyang20
merged 9 commits into
zhaochenyang20:main
from
dreamyang-liu:feat/launcher
Feb 23, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f0e7748
Add launcher to allow launching worker from router
dreamyang-liu d815ee7
add example to readme and remove unused cli argument
dreamyang-liu 7023eb8
fix readme
dreamyang-liu 9afe1e4
Fix worker_urls
dreamyang-liu f501d83
fix lint
zhaochenyang20 0cf41be
fix the conflicts between isort and black
zhaochenyang20 37346a1
address comments
dreamyang-liu 4cb19a7
adds mocked port for unit tests
zhaochenyang20 b7052a2
fix conf
zhaochenyang20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| pip install -e . | ||
| ``` | ||
|
|
||
| Run tests: | ||
| Run CPU only tests: | ||
|
|
||
| ```bash | ||
| pip install pytest | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| launcher: | ||
| model: Qwen/Qwen-Image | ||
|
|
||
| num_workers: 8 | ||
| num_gpus_per_worker: 1 | ||
| worker_host: "127.0.0.1" | ||
| worker_base_port: 10090 | ||
|
|
||
| worker_extra_args: "--dit-cpu-offload false --text-encoder-cpu-offload false" | ||
|
dreamyang-liu marked this conversation as resolved.
|
||
|
|
||
| wait_timeout: 600 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| """Launcher backends for spinning up SGLang diffusion workers. | ||
|
|
||
| Right now only supports local backend, which launches workers as local subprocesses. | ||
| We leave this module for future extensions on slurm or kubernetes. | ||
| """ | ||
|
|
||
| from sglang_diffusion_routing.launcher.backend import ( | ||
| LaunchedWorker, | ||
| LauncherBackend, | ||
| WorkerLaunchResult, | ||
| ) | ||
| from sglang_diffusion_routing.launcher.config import ( | ||
| create_backend, | ||
| load_launcher_config, | ||
| ) | ||
| from sglang_diffusion_routing.launcher.local import LocalLauncher, LocalLauncherConfig | ||
|
|
||
| __all__ = [ | ||
| "LaunchedWorker", | ||
| "LauncherBackend", | ||
| "LocalLauncher", | ||
| "LocalLauncherConfig", | ||
| "WorkerLaunchResult", | ||
| "create_backend", | ||
| "load_launcher_config", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """Abstract base class and shared data types for launcher backends.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import subprocess | ||
| from abc import ABC, abstractmethod | ||
| from collections.abc import Callable | ||
| from dataclasses import dataclass, field | ||
|
|
||
|
|
||
| @dataclass | ||
| class LaunchedWorker: | ||
| """A worker managed by a launcher backend.""" | ||
|
|
||
| url: str | ||
| process: subprocess.Popen | ||
|
|
||
|
|
||
| @dataclass | ||
| class WorkerLaunchResult: | ||
| """Aggregated result of launching worker subprocesses.""" | ||
|
|
||
| workers: list[LaunchedWorker] = field(default_factory=list) | ||
| all_processes: list[subprocess.Popen] = field(default_factory=list) | ||
|
|
||
| @property | ||
| def urls(self) -> list[str]: | ||
| return [w.url for w in self.workers] | ||
|
|
||
|
|
||
| class LauncherBackend(ABC): | ||
| """Interface for launching and managing SGLang diffusion workers. | ||
|
|
||
| Each backend exposes the same lifecycle: | ||
| launch → wait_ready_and_register → shutdown. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def launch(self) -> list[str]: | ||
| """Launch workers and return their base URLs.""" | ||
|
|
||
| @abstractmethod | ||
| def wait_ready_and_register( | ||
| self, | ||
| register_func: Callable[[str], None], | ||
| timeout: int, | ||
| log_prefix: str = "[launcher]", | ||
| ) -> None: | ||
| """Wait for workers to become healthy and register each via register_func.""" | ||
|
|
||
| @abstractmethod | ||
| def shutdown(self) -> None: | ||
| """Clean up all managed workers.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """YAML configuration loading and backend factory.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import yaml | ||
| from omegaconf import DictConfig, OmegaConf | ||
|
|
||
| from sglang_diffusion_routing.launcher.backend import LauncherBackend | ||
| from sglang_diffusion_routing.launcher.local import LocalLauncher, LocalLauncherConfig | ||
|
|
||
| SCHEMA_REGISTRY: dict[str, type] = { | ||
| "local": LocalLauncherConfig, | ||
| } | ||
|
|
||
| BACKEND_REGISTRY: dict[str, type[LauncherBackend]] = { | ||
| "local": LocalLauncher, | ||
| } | ||
|
|
||
|
|
||
| def load_launcher_config(config_path: str) -> DictConfig: | ||
| """Read a YAML config file and return a validated OmegaConf config. | ||
|
|
||
| 1. Parse the YAML and extract the launcher mapping. | ||
| 2. Read the backend key to select the structured schema. | ||
| 3. Merge the YAML values onto the schema defaults. | ||
| """ | ||
| path = Path(config_path) | ||
| if not path.is_file(): | ||
| raise FileNotFoundError(f"Config file not found: {config_path}") | ||
|
|
||
| with path.open() as f: | ||
| raw = yaml.safe_load(f) | ||
|
|
||
| if not isinstance(raw, dict) or "launcher" not in raw: | ||
| raise ValueError( | ||
| f"Config file must contain a top-level 'launcher' key: {config_path}" | ||
| ) | ||
|
|
||
| launcher_raw = raw["launcher"] | ||
| if not isinstance(launcher_raw, dict): | ||
| raise ValueError("'launcher' must be a dictionary") | ||
|
|
||
| backend_name = launcher_raw.get("backend", "local") | ||
| schema_cls = SCHEMA_REGISTRY.get(backend_name) | ||
| if schema_cls is None: | ||
| available = ", ".join(sorted(SCHEMA_REGISTRY)) | ||
| raise ValueError( | ||
| f"Unknown launcher backend: {backend_name!r}. " | ||
| f"Available backends: {available}" | ||
| ) | ||
|
|
||
| schema = OmegaConf.structured(schema_cls) | ||
| yaml_cfg = OmegaConf.create(launcher_raw) | ||
| merged = OmegaConf.merge(schema, yaml_cfg) | ||
| return merged | ||
|
|
||
|
|
||
| def create_backend(config: DictConfig) -> LauncherBackend: | ||
| """Instantiate a LauncherBackend from a validated config.""" | ||
| backend_name = config.backend | ||
| cls = BACKEND_REGISTRY.get(backend_name) | ||
| if cls is None: | ||
| available = ", ".join(sorted(BACKEND_REGISTRY)) | ||
| raise ValueError( | ||
| f"Unknown launcher backend: {backend_name!r}. " | ||
| f"Available backends: {available}" | ||
| ) | ||
| return cls(config) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.