-
Notifications
You must be signed in to change notification settings - Fork 311
feat: add SGLang rollout backend, part1 #1580
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
Closed
Closed
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
d9cf489
sglang support:initial commit
PrinsYin 3eace5f
sglang:manually set cuda visible to let localran=0 to manage gpus of …
PrinsYin 6fbbbb7
sglang: add sglang setup in grpo.py, add find available port to set u…
PrinsYin 242612c
sglang: add shutdown
PrinsYin a3d8ad6
sglang server: fix gpu allocation when tp =1
PrinsYin 88971e3
generate only first request
PrinsYin db8b07b
fix : choose the correct gpu using base gpu id
PrinsYin dd0e54f
asyncio to roolout all saples
PrinsYin 21c54e3
fix new event loop for rollout
PrinsYin 5e24fab
added mem_fraction
PrinsYin 50189a9
modified build_sampling_paras and stop token handling
PrinsYin ec35b6b
temp: prevent server overlaod with semaphore
PrinsYin f099caa
sglang: refactor, move async loop position
PrinsYin a03eba8
sglang: fix total length in generate
PrinsYin e08cfd6
sglang: env setup
PrinsYin ccc66f6
from tensor:
PrinsYin 2ce928b
sglang refit: fix sglang import
PrinsYin 4aa1e74
fix: match fsdp ranks correctly with sglang
PrinsYin 9098077
flush cache before update begins
PrinsYin 9900a33
Fix SGLang compatibility: add hasattr checks for vLLM-specific methods
PrinsYin 5cb78e3
sglang: modified config (increase mem_fration, enable wandb)
PrinsYin 03d9d0c
refactor(grpo): extract init logic for generation backends
PrinsYin 7ca9776
refactor SGLangConfig
PrinsYin f1c26dd
refactor: generalize logger metrics for all generation backends
PrinsYin 255dcc6
refactor sglang config loading to make it consistent with other backendw
PrinsYin ee01f91
resolved ai comments
PrinsYin e25e573
changed print to using loging
PrinsYin e93699f
Merge branch 'main' into sglang_server
PrinsYin 85d6a92
Update nemo_rl/models/generation/sglang/sglang_worker.py
PrinsYin be1ae27
Merge branch 'main' into sglang_server
PrinsYin ede624f
fix comments about config defaults
PrinsYin 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 |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| defaults: grpo_math_1B.yaml | ||
|
|
||
| grpo: | ||
| val_batch_size: 128 | ||
|
|
||
| policy: | ||
| generation: | ||
| backend: "sglang" | ||
| sglang_cfg: | ||
| # SGLang specific configuration | ||
| model_path: ${policy.model_name} | ||
| gpus_per_server: 1 | ||
| dtype: ${policy.precision} | ||
| context_length: 512 # Maximum context length | ||
| allow_auto_truncate: true | ||
| enable_memory_saver: false | ||
| dp_size: 1 | ||
| pp_size: 1 | ||
| ep_size: 1 | ||
| max_running_requests: null | ||
| mem_fraction_static: 0.7 | ||
| skip_server_warmup: true | ||
|
|
||
| logger: | ||
| wandb_enabled: true |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,23 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OR WARRANTIES OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| from nemo_rl.models.generation.sglang.config import SGLangConfig | ||
| from nemo_rl.models.generation.sglang.sglang_generation import SGLangGeneration | ||
| from nemo_rl.models.generation.sglang.sglang_worker import SGLangGenerationWorker | ||
|
|
||
| __all__ = [ | ||
| "SGLangConfig", | ||
| "SGLangGeneration", | ||
| "SGLangGenerationWorker", | ||
| ] | ||
|
|
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,98 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from typing import Any, NotRequired, TypedDict | ||
|
|
||
| from nemo_rl.models.generation.interfaces import GenerationConfig | ||
|
|
||
|
|
||
| class SglangSpecificArgs(TypedDict): | ||
| """SGLang-specific configuration arguments. | ||
|
|
||
| Most fields below map directly to SGLang's ServerArgs (see: | ||
| https://github.com/sgl-project/sglang/blob/main/python/sglang/srt/server_args.py). | ||
| """ | ||
| model_path: NotRequired[str] | ||
| gpus_per_server: NotRequired[int] | ||
| random_seed: NotRequired[int] | ||
| skip_tokenizer_init: NotRequired[bool] | ||
| disable_cuda_graph: NotRequired[bool] | ||
| disable_radix_cache: NotRequired[bool] | ||
| disable_cuda_graph_padding: NotRequired[bool] | ||
| enable_nccl_nvls: NotRequired[bool] | ||
| disable_outlines_disk_cache: NotRequired[bool] | ||
| disable_custom_all_reduce: NotRequired[bool] | ||
| disable_overlap_schedule: NotRequired[bool] | ||
| enable_mixed_chunk: NotRequired[bool] | ||
| enable_dp_attention: NotRequired[bool] | ||
| enable_ep_moe: NotRequired[bool] | ||
| enable_torch_compile: NotRequired[bool] | ||
| torch_compile_max_bs: NotRequired[int] | ||
| cuda_graph_max_bs: NotRequired[int | None] | ||
| cuda_graph_bs: NotRequired[list[int] | None] | ||
| torchao_config: NotRequired[str] | ||
| enable_nan_detection: NotRequired[bool] | ||
| enable_p2p_check: NotRequired[bool] | ||
| triton_attention_reduce_in_fp32: NotRequired[bool] | ||
| triton_attention_num_kv_splits: NotRequired[int] | ||
| num_continuous_decode_steps: NotRequired[int] | ||
| enable_memory_saver: NotRequired[bool] | ||
| allow_auto_truncate: NotRequired[bool] | ||
| attention_backend: NotRequired[str | None] | ||
| enable_multimodal: NotRequired[bool] | ||
| sampling_backend: NotRequired[str | None] | ||
| context_length: NotRequired[int | None] | ||
| mem_fraction_static: NotRequired[float | None] | ||
| max_running_requests: NotRequired[int | None] | ||
| chunked_prefill_size: NotRequired[int | None] | ||
| max_prefill_tokens: NotRequired[int] | ||
| schedule_policy: NotRequired[str] | ||
| schedule_conservativeness: NotRequired[float] | ||
| cpu_offload_gb: NotRequired[int] | ||
| dtype: NotRequired[str] | ||
| kv_cache_dtype: NotRequired[str] | ||
| dp_size: NotRequired[int] # only used for dp attention | ||
| pp_size: NotRequired[int] # pipeline parallel size | ||
| ep_size: NotRequired[int] | ||
| # lora | ||
| enable_lora: NotRequired[bool | None] | ||
| max_lora_rank: NotRequired[int | None] | ||
| lora_target_modules: NotRequired[list[str] | None] | ||
| lora_paths: NotRequired[list[str] | None] | ||
| max_loaded_loras: NotRequired[int] | ||
| max_loras_per_batch: NotRequired[int] | ||
| lora_backend: NotRequired[str] | ||
| # logging | ||
| log_level: NotRequired[str] | ||
| log_level_http: NotRequired[str | None] | ||
| log_requests: NotRequired[bool] | ||
| log_requests_level: NotRequired[int] | ||
| show_time_cost: NotRequired[bool] | ||
| enable_metrics: NotRequired[bool] # Exports Prometheus-like metrics | ||
| # The interval (in decoding iterations) to log throughput | ||
| # and update prometheus metrics | ||
| decode_log_interval: NotRequired[int] | ||
| # Extra loader arguments | ||
| enable_multithread_load: NotRequired[bool] | ||
| enable_fast_load: NotRequired[bool] | ||
| # Server warmup | ||
| skip_server_warmup: NotRequired[bool] | ||
|
|
||
|
|
||
| class SGLangConfig(GenerationConfig): | ||
| """Configuration for SGLang runtime.""" | ||
| sglang_cfg: SglangSpecificArgs | ||
| sglang_kwargs: NotRequired[dict[str, Any]] | ||
|
|
||
|
|
Oops, something went wrong.
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.