-
Notifications
You must be signed in to change notification settings - Fork 6
Add Acknowledgment To the Team mates #20
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,15 +1,19 @@ | ||||||
| # sglang-diffusion-routing | ||||||
| # SGLang Diffusion Router | ||||||
|
|
||||||
| A lightweight router for SGLang diffusion workers. | ||||||
| A lightweight router for SGLang diffusion workers used in RL systems. | ||||||
|
|
||||||
| It provides worker registration, load balancing, health checking, and request proxying for diffusion generation APIs. | ||||||
| It provides worker registration, load balancing, health checking, refit weights and request proxying for diffusion generation APIs. | ||||||
|
|
||||||
| ## Highlights | ||||||
| ## API Reference | ||||||
|
|
||||||
| - `least-request` routing by default, with `round-robin` and `random`. | ||||||
| - Background health checks with quarantine after repeated failures. | ||||||
| - Router APIs for worker registration, health inspection, and proxy forwarding. | ||||||
| - `update_weights_from_disk` broadcast to all healthy workers. | ||||||
| - `POST /add_worker`: add worker via query (`?url=`) or JSON body. | ||||||
| - `GET /list_workers`: list registered workers. | ||||||
| - `GET /health`: aggregated router health. | ||||||
| - `GET /health_workers`: per-worker health and active request counts. | ||||||
| - `POST /generate`: forwards to worker `/v1/images/generations`. | ||||||
| - `POST /generate_video`: forwards to worker `/v1/videos`; rejects image-only workers (`T2I`/`I2I`/`TI2I`) with `400`. | ||||||
| - `POST /update_weights_from_disk`: broadcast to all healthy workers. | ||||||
| - `GET|POST|PUT|DELETE /{path}`: catch-all proxy forwarding. | ||||||
|
|
||||||
| ## Installation | ||||||
|
|
||||||
|
|
@@ -37,8 +41,6 @@ cd .. | |||||
|
|
||||||
| ## Quick Start | ||||||
|
|
||||||
| ### Start diffusion workers | ||||||
|
|
||||||
| ```bash | ||||||
| # If connect to HuggingFace is not allowed | ||||||
| # You can set the environment variable SGLANG_USE_MODELSCOPE=TRUE | ||||||
|
|
@@ -56,75 +58,15 @@ CUDA_VISIBLE_DEVICES=1 sglang serve \ | |||||
| --num-gpus 1 \ | ||||||
| --host 127.0.0.1 \ | ||||||
| --port 30002 | ||||||
| ``` | ||||||
|
|
||||||
| ### Start the router | ||||||
|
|
||||||
| 1. Script entry | ||||||
|
|
||||||
| ```bash | ||||||
| sglang-d-router --port 30081 \ | ||||||
| --worker-urls http://localhost:30000 http://localhost:30002 | ||||||
| ``` | ||||||
|
|
||||||
| 2. Module entry | ||||||
|
|
||||||
| ```bash | ||||||
| python -m sglang_diffusion_routing --port 30081 \ | ||||||
| --worker-urls http://localhost:30000 http://localhost:30002 | ||||||
| ``` | ||||||
|
|
||||||
| 3. Or start empty and add workers later: | ||||||
|
|
||||||
| ```bash | ||||||
| sglang-d-router --port 30081 | ||||||
| curl -X POST "http://localhost:30081/add_worker?url=http://localhost:30000" | ||||||
| curl -X POST "http://localhost:30081/add_worker?url=http://localhost:30002" | ||||||
| ``` | ||||||
|
|
||||||
| ### Test the router | ||||||
| ## Demonstrative Examples | ||||||
|
|
||||||
| ```bash | ||||||
| # Check router health | ||||||
| curl http://localhost:30081/health | ||||||
|
|
||||||
| # List registered workers | ||||||
| curl http://localhost:30081/list_workers | ||||||
|
|
||||||
| # Image generation request (returns base64-encoded image) | ||||||
| curl -X POST http://localhost:30081/generate \ | ||||||
| -H "Content-Type: application/json" \ | ||||||
| -d '{ | ||||||
| "model": "Qwen/Qwen-Image", | ||||||
| "prompt": "a cute cat", | ||||||
| "num_images": 1, | ||||||
| "response_format": "b64_json" | ||||||
| }' | ||||||
|
|
||||||
| # Decode and save the image locally | ||||||
| curl -s -X POST http://localhost:30081/generate \ | ||||||
| -H "Content-Type: application/json" \ | ||||||
| -d '{ | ||||||
| "model": "Qwen/Qwen-Image", | ||||||
| "prompt": "a cute cat", | ||||||
| "num_images": 1, | ||||||
| "response_format": "b64_json" | ||||||
| }' | python3 -c " | ||||||
| import sys, json, base64 | ||||||
| resp = json.load(sys.stdin) | ||||||
| img = base64.b64decode(resp['data'][0]['b64_json']) | ||||||
| with open('output.png', 'wb') as f: | ||||||
| f.write(img) | ||||||
| print('Saved to output.png') | ||||||
| " | ||||||
|
|
||||||
|
|
||||||
| curl -X POST http://localhost:30081/update_weights_from_disk \ | ||||||
| -H "Content-Type: application/json" \ | ||||||
| -d '{"model_path": "Qwen/Qwen-Image-2512"}' | ||||||
| ``` | ||||||
|
|
||||||
| ### Python requests examples | ||||||
| ### With Python Requests | ||||||
|
|
||||||
| ```python | ||||||
| import requests | ||||||
|
|
@@ -166,44 +108,60 @@ print(resp.json()) | |||||
| # Check per-worker health and load | ||||||
| resp = requests.get(f"{ROUTER}/health_workers") | ||||||
| print(resp.json()) | ||||||
|
|
||||||
| # Update weights from disk | ||||||
| resp = requests.post(f"{ROUTER}/update_weights_from_disk", json={ | ||||||
| "model_path": "Qwen/Qwen-Image-2512", | ||||||
| }) | ||||||
| print(resp.json()) | ||||||
| ``` | ||||||
|
|
||||||
| ## Router API | ||||||
| ### With Curl | ||||||
|
|
||||||
| - `POST /add_worker`: add worker via query (`?url=`) or JSON body. | ||||||
| - `GET /list_workers`: list registered workers. | ||||||
| - `GET /health`: aggregated router health. | ||||||
| - `GET /health_workers`: per-worker health and active request counts. | ||||||
| - `POST /generate`: forwards to worker `/v1/images/generations`. | ||||||
| - `POST /generate_video`: forwards to worker `/v1/videos`; rejects image-only workers (`T2I`/`I2I`/`TI2I`) with `400`. | ||||||
| - `POST /update_weights_from_disk`: broadcast to healthy workers. | ||||||
| - `GET|POST|PUT|DELETE /{path}`: catch-all proxy forwarding. | ||||||
| - `POST /update_weights_from_disk`: broadcast to all healthy workers. | ||||||
| ```bash | ||||||
| # Check router health | ||||||
| curl http://localhost:30081/health | ||||||
|
|
||||||
| # List registered workers | ||||||
| curl http://localhost:30081/list_workers | ||||||
|
|
||||||
| # Image generation request (returns base64-encoded image) | ||||||
| curl -X POST http://localhost:30081/generate \ | ||||||
| -H "Content-Type: application/json" \ | ||||||
| -d '{ | ||||||
| "model": "Qwen/Qwen-Image", | ||||||
| "prompt": "a cute cat", | ||||||
| "num_images": 1, | ||||||
| "response_format": "b64_json" | ||||||
| }' | ||||||
|
|
||||||
| ## Project Layout | ||||||
|
|
||||||
| ```text | ||||||
| . | ||||||
| ├── docs/ | ||||||
| │ └── update_weights_from_disk.md | ||||||
| ├── src/sglang_diffusion_routing/ | ||||||
| │ ├── cli/ | ||||||
| │ └── router/ | ||||||
| ├── tests/ | ||||||
| │ ├── benchmarks/ | ||||||
| │ │ └── diffusion_router/ | ||||||
| │ │ ├── bench_router.py | ||||||
| │ │ └── bench_routing_algorithms.py | ||||||
| │ └── unit/ | ||||||
| ├── pyproject.toml | ||||||
| └── README.md | ||||||
| # Decode and save the image locally | ||||||
| curl -s -X POST http://localhost:30081/generate \ | ||||||
| -H "Content-Type: application/json" \ | ||||||
| -d '{ | ||||||
| "model": "Qwen/Qwen-Image", | ||||||
| "prompt": "a cute cat", | ||||||
| "num_images": 1, | ||||||
| "response_format": "b64_json" | ||||||
| }' | python3 -c " | ||||||
| import sys, json, base64 | ||||||
| resp = json.load(sys.stdin) | ||||||
| img = base64.b64decode(resp['data'][0]['b64_json']) | ||||||
| with open('output.png', 'wb') as f: | ||||||
| f.write(img) | ||||||
| print('Saved to output.png') | ||||||
| " | ||||||
|
|
||||||
|
|
||||||
| curl -X POST http://localhost:30081/update_weights_from_disk \ | ||||||
| -H "Content-Type: application/json" \ | ||||||
| -d '{"model_path": "Qwen/Qwen-Image-2512"}' | ||||||
| ``` | ||||||
|
|
||||||
| ## Acknowledgment | ||||||
|
|
||||||
| This project is derived from [radixark/miles#544](https://github.com/radixark/miles/pull/544). Thanks to the original authors for their work. | ||||||
| This project is derived from [radixark/miles#544](https://github.com/radixark/miles/pull/544). Thanks to the original authors. | ||||||
|
|
||||||
| ## Notes | ||||||
| SGLang Diffusion RL team is responsible for the development and maintenance of this project. Our team mates in alphabetical order: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'team mates' is typically written as a single word: 'teammates'.
Suggested change
|
||||||
|
|
||||||
| - Quarantined workers are intentionally not auto-reintroduced. | ||||||
| - Router responses are fully buffered; streaming passthrough is not implemented. | ||||||
| Banghua Zhu, Chengliang Qian, Chenyang Zhao, Fenglin Yu, Hao Jin, Huapeng Zhou, Jiajun Li, Kangrui Du, Kun Lin, Mao Cheng, Mengyang Liu, Qiujiang Chen, Shenggui Li, Shirui Chen, Shuwen Wang, Xi Chen, Xiaole Guo, Ying Sheng, Yueming Yuan, Yuhao Yang, Yusheng Su, Zhiheng Ye | ||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The list of features uses gerunds (registration, balancing, checking, proxying). To maintain parallel structure and grammatical consistency, 'refit weights' should be changed to 'weight refitting'. Additionally, the Oxford comma used in the previous version should be restored for consistency.