Skip to content

Commit d1d1f03

Browse files
jsfanfanfanjsfanfanfanAniZpZ
authored
[sglang] fix: HTTP server startup issues for Prometheus and Grafana integration (verl-project#4408)
### What does this PR do? > Resolve the issue that Prometheus and Grafana cannot monitor relevant metrics during rollout using SGLang. ### Problems When using SGLang as the rollout engine, the HTTP server fails to start properly. As a result, Prometheus cannot scrape metrics and Grafana is unable to display them. ### Details Set the **warmup_thread_args** property: Configure app.warmup_thread_args before starting the server to satisfy SGLang’s lifespan requirements. Skip server warmup: Enable **skip_server_warmup=True** to avoid connection issues caused by the warmup thread. Since the model is already loaded in _launch_subprocesses, no additional warmup is required. Add **Prometheus middleware** early: Manually call add_prometheus_middleware before invoking run_unvicorn to ensure that the /metrics endpoint is available immediately when the server starts. ### Checklist Before Starting - [ ] Search for similar PRs. Paste at least one query link here: verl-project#4088 - [ ] Format the PR title as `[{modules}] {type}: {description}` (This will be checked by the CI) - `{modules}` include `fsdp`, `megatron`, `sglang`, `vllm`, `rollout`, `trainer`, `ci`, `training_utils`, `recipe`, `hardware`, `deployment`, `ray`, `worker`, `single_controller`, `misc`, `perf`, `model`, `algo`, `env`, `tool`, `ckpt`, `doc`, `data` - If this PR involves multiple modules, separate them with `,` like `[megatron, fsdp, doc]` - `{type}` is in `feat`, `fix`, `refactor`, `chore`, `test` - If this PR breaks any API (CLI arguments, config, function signature, etc.), add `[BREAKING]` to the beginning of the title. - Example: `[BREAKING][fsdp, megatron] feat: dynamic batching` ### Test > For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc. <img width="595" height="246" alt="截屏2025-12-04 下午3 00 59" src="https://github.com/user-attachments/assets/3aed1690-172c-4857-b880-5af5371646bf" /> <img width="595" height="246" alt="截屏2025-12-04 下午3 01 05" src="https://github.com/user-attachments/assets/517077d7-7c96-4ac9-a2c5-0f06ea6701b3" /> ### API and Usage Example > Demonstrate how the API changes if any, and provide usage example(s) if possible. ```python # Add code snippet or script demonstrating how to use this ``` ### Design & Code Changes > Demonstrate the high-level design if this PR is complex, and list the specific changes. ### Checklist Before Submitting > [!IMPORTANT] > Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review. - [ ] Read the [Contribute Guide](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md). - [ ] Apply [pre-commit checks](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md#code-linting-and-formatting): `pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=always` - [ ] Add / Update [the documentation](https://github.com/volcengine/verl/tree/main/docs). - [ ] Add unit or end-to-end test(s) to [the CI workflow](https://github.com/volcengine/verl/tree/main/.github/workflows) to cover all the code. If not feasible, explain why: ... - [ ] Once your PR is ready for CI, send a message in [the `ci-request` channel](https://verl-project.slack.com/archives/C091TCESWB1) in [the `verl` Slack workspace](https://join.slack.com/t/verl-project/shared_invite/zt-3855yhg8g-CTkqXu~hKojPCmo7k_yXTQ). (If not accessible, please try [the Feishu group (飞书群)](https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=772jd4f1-cd91-441e-a820-498c6614126a).) --------- Co-authored-by: jsfanfanfan <2981866535@qq.com> Co-authored-by: AniZpZ <aniz1905@gmail.com>
1 parent fd893c7 commit d1d1f03

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

docs/advance/grafana_prometheus.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22

33
**Author:** `https://github.com/meituan-search`
44

5-
Last updated: 11/12/2025.
5+
Last updated: 12/05/2025.
66

77
Monitor the rollout computation process using Prometheus and Grafana when using verl to enhance system observability and facilitate further performance optimization.
88

99
We provide an additional training monitoring capability, leveraging Prometheus and Grafana to display rollout information during training and enhance system observability to facilitate further performance optimization.
1010

1111
The system automatically configures Prometheus to scrape metrics from rollout servers, eliminating manual configuration steps.
12-
13-
> Note: SGLang integration is currently under development and debugging. Some features may not
14-
> work as expected and the implementation is subject to change. Please use with caution
15-
> in production environments.
16-
1712

1813

1914
## Overview

verl/workers/rollout/sglang_rollout/async_sglang_server.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,21 @@ async def launch_server(self, master_address: str = None, master_port: int = Non
194194
)
195195
)
196196
app.is_single_tokenizer_mode = True
197-
app.server_args = server_args
198-
app.warmup_thread_args = (server_args, None, None)
197+
198+
# Set warmup_thread_args to avoid AttributeError in lifespan function
199+
app.warmup_thread_args = (
200+
server_args,
201+
None,
202+
None,
203+
)
204+
205+
# Manually add Prometheus middleware before starting server
206+
# This ensures /metrics endpoint is available immediately
207+
if server_args.enable_metrics:
208+
from sglang.srt.utils.common import add_prometheus_middleware
209+
210+
add_prometheus_middleware(app)
211+
199212
self._server_port, self._server_task = await run_unvicorn(app, server_args, self._server_address)
200213
self.tokenizer_manager.server_status = ServerStatus.Up
201214

0 commit comments

Comments
 (0)