generated from fastai/nbdev_template
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[Feat] Suppport SGLang as rollout engine of GRPO trainer #3370
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 40 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
51ef1b1
Feature: Add SGLang support for GRPO Trainer
jhinpan bcbed19
Turn to the online server API Usage
jhinpan b1b92fc
add test and fix bugs in result parsing
Jayon02 ed115af
Pass First test with fixing _update_sglang_weights
jhinpan 941db60
Remove checkpoints from tracking and add to .gitignore
jhinpan e622ba9
config to run on single gpu successfully
ryang-max 9fba5f0
Merge branch 'main' into sglang-server
ryang-max 7de7ddb
Update code to align with vllm
ryang-max 029402e
Merge remote-tracking branch 'origin/main' into sglang-server
ryang-max 8debe2a
save model and update weight
ryang-max 26d34c3
save model only main process
ryang-max 69ebec8
A runnable update_from_tensor version
ryang-max 0fcdd83
fix performance issue
ryang-max 35e05f0
Merge branch 'main' into sglang-server
ryang-max 8d75a8f
resolve comment: help strings
renxinx ddf67e9
resolve comment: help strings
renxinx 6745e6b
Update trl/trainer/grpo_config.py
kashif 6887ed5
Update trl/trainer/grpo_config.py
kashif 4e020b4
Update trl/trainer/grpo_config.py
kashif 5787bfc
Update trl/trainer/grpo_config.py
kashif 4f8021a
Update trl/trainer/grpo_config.py
kashif f73e652
Update trl/trainer/grpo_config.py
kashif 62dc22e
Update trl/trainer/grpo_trainer.py
kashif 3a95d13
call raise_for_status
kashif f733428
remove duplicate
kashif e91e7d8
doc string
kashif 1f2fada
formatting
kashif 88ad6af
add sglang to extras
kashif 9a2db24
formatting
kashif e139430
import requests only when sglang is available
kashif 4693aa0
formatting
kashif cf2e1ff
undo formatting
kashif 0a079cc
undo formatting
kashif 9ddf9a0
more undo
kashif 45214e9
last one!
kashif ccbf97b
add initial docs
kashif fe94157
Merge branch 'main' into sglang-server
kashif 10af891
add sglang
kashif 829ae41
last one now
kashif f48c7e6
new line
kashif 2bcf24c
Merge branch 'main' into sglang-server
kashif a6158fa
delete test scripts
renxinx 6380ce5
Merge branch 'main' into sglang-server
renxinx 85d1906
Merge branch 'main' into sglang-server
kashif 865afb4
Update setup.cfg
kashif 6e94e53
Update setup.cfg
kashif 8e3697d
intiial sglang-serve cli script
kashif e7149a0
Update trl/trainer/grpo_trainer.py
ryang-max 94c1c9b
debug GRPO trainer
renxinx a665a17
change num_processes
renxinx 9e634d1
update how to run sglang
renxinx 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
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,56 @@ | ||
| # Copyright 2020-2025 The HuggingFace Team. 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. | ||
|
|
||
| import os | ||
|
|
||
| from datasets import load_dataset | ||
|
|
||
| from trl import GRPOConfig, GRPOTrainer | ||
|
|
||
|
|
||
|
|
||
| dataset = load_dataset("trl-lib/tldr", split="train[:1%]") | ||
|
|
||
| checkpoint_dir = os.path.join("/sgl-workspace/ryang/trl", "checkpoints/sgl") | ||
| os.makedirs(checkpoint_dir, exist_ok=True) | ||
|
|
||
|
|
||
| # Define the reward function, which rewards completions that are close to 20 characters | ||
| def reward_len(completions, **kwargs): | ||
| return [-abs(20 - len(completion)) for completion in completions] | ||
|
|
||
|
|
||
| training_args = GRPOConfig( | ||
| output_dir=os.path.join(checkpoint_dir, "Qwen2.5_output"), | ||
| logging_steps=10, | ||
| # report_to="wandb", | ||
| # use_vllm=True, | ||
| use_sglang=True, | ||
| sglang_device="cuda:1", | ||
| sglang_gpu_memory_utilization=0.9, | ||
| sglang_server_url="http://127.0.0.1:30000", | ||
| ) | ||
|
|
||
|
|
||
| trainer = GRPOTrainer( | ||
| model="Qwen/Qwen2-0.5B-Instruct", | ||
| reward_funcs=reward_len, | ||
| args=training_args, | ||
| train_dataset=dataset, | ||
| ) | ||
|
|
||
| training_args.checkpoint_path = checkpoint_dir # Set the checkpoint path for later use | ||
|
|
||
|
|
||
| trainer.train() |
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,17 @@ | ||
| compute_environment: LOCAL_MACHINE | ||
| debug: false | ||
| distributed_type: MULTI_GPU | ||
| downcast_bf16: 'no' | ||
| gpu_ids: all | ||
| machine_rank: 0 | ||
| main_training_function: main | ||
| mixed_precision: 'bf16' | ||
| num_machines: 1 | ||
| num_processes: 3 | ||
| rdzv_backend: static | ||
| same_network: true | ||
| tpu_env: [] | ||
| tpu_use_cluster: false | ||
| tpu_use_sudo: false | ||
| use_cpu: false | ||
| main_process_port: 29600 |
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,4 @@ | ||
| #!/bin/bash | ||
| export CUDA_VISIBLE_DEVICES=5,6,7 | ||
| export PYTHONPATH="/sgl-workspace/ryang/trl:$PYTHONPATH" | ||
| accelerate launch --config_file=trl/scripts/grpo_test/grpo_sgl_test.yaml trl/scripts/grpo_test/grpo_sgl_test.py |
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
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.
In the final version, the files in scripts should be removed