Skip to content

Commit b3e662b

Browse files
paolo328RichardWGeLee-Qzhaochenyang20
committed
add gptoss grpo example script (#3212)
### What does this PR do? > Add **concise** overview of what this PR aims to achieve or accomplish. Reference related GitHub issues and PRs that help with the review. Adding a script to run gpt-oss 20B model with VeRL. ### Checklist Before Starting - [ ] Search for similar PRs. Paste at least one query link here: ... - [ ] 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. ### 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. - [x] 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: RichardW <richard.junwang@bytedance.com> Co-authored-by: GeLee-Q <leege233@gmail.com> Co-authored-by: zhaochenyang20 <zhaochen20@outlook.com>
1 parent 055ca7f commit b3e662b

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/bin/bash
2+
3+
# install flashinfer
4+
cd $HOME
5+
git clone https://github.com/flashinfer-ai/flashinfer.git --recursive
6+
cd flashinfer
7+
python -m pip install -v .
8+
9+
# install sglang
10+
cd $HOME
11+
git fetch origin pull/9379/head:fix_weight_loading
12+
cd $HOME/sglang
13+
git checkout fix_weight_loading
14+
pip install --upgrade pip
15+
pip install -e "python[all]"
16+
17+
pip install peft
18+
pip install transformers -U
19+
pip install https://github.com/Dao-AILab/flash-attention/releases/download/v2.8.3/flash_attn-2.8.3+cu12torch2.8cxx11abiTRUE-cp311-cp311-linux_x86_64.whl
20+
pip install numpy==1.26.4
21+
22+
23+
cat > get_model.py << EOF
24+
import torch
25+
from transformers import AutoModelForCausalLM, AutoTokenizer, Mxfp4Config
26+
27+
model_id = "openai/gpt-oss-20b"
28+
output_dir = "$HOME/models/gpt-oss-20b-bf16"
29+
30+
quantization_config = Mxfp4Config(dequantize=True)
31+
model_kwargs = dict(
32+
attn_implementation="eager",
33+
torch_dtype=torch.bfloat16,
34+
quantization_config=quantization_config,
35+
use_cache=False,
36+
device_map="auto",
37+
)
38+
39+
model = AutoModelForCausalLM.from_pretrained(model_id, **model_kwargs)
40+
41+
# Patch config with custom attribute before saving
42+
model.config.attn_implementation = "eager"
43+
44+
model.save_pretrained(output_dir)
45+
tokenizer = AutoTokenizer.from_pretrained(model_id)
46+
tokenizer.save_pretrained(output_dir)
47+
EOF
48+
49+
python get_model.py
50+
51+
52+
53+
model_dir=$HOME/models/gpt-oss-20b-bf16
54+
python3 -m verl.trainer.main_ppo \
55+
algorithm.adv_estimator=grpo \
56+
data.train_files="$gsm8k_train_path" \
57+
data.val_files="$gsm8k_test_path" \
58+
data.train_batch_size=1024 \
59+
data.max_prompt_length=1024 \
60+
data.max_response_length=1024 \
61+
data.filter_overlong_prompts=True \
62+
data.truncation='error' \
63+
actor_rollout_ref.model.path=${model_dir} \
64+
actor_rollout_ref.actor.optim.lr=1e-6 \
65+
actor_rollout_ref.model.use_remove_padding=True \
66+
actor_rollout_ref.actor.ppo_mini_batch_size=256 \
67+
actor_rollout_ref.actor.ppo_micro_batch_size_per_gpu=32 \
68+
actor_rollout_ref.actor.use_kl_loss=True \
69+
actor_rollout_ref.actor.kl_loss_coef=0.001 \
70+
actor_rollout_ref.actor.kl_loss_type=low_var_kl \
71+
actor_rollout_ref.actor.entropy_coeff=0 \
72+
actor_rollout_ref.model.enable_gradient_checkpointing=True \
73+
actor_rollout_ref.actor.fsdp_config.param_offload=False \
74+
actor_rollout_ref.actor.fsdp_config.optimizer_offload=False \
75+
+actor_rollout_ref.actor.fsdp_config.model_dtype=bfloat16 \
76+
actor_rollout_ref.rollout.log_prob_micro_batch_size_per_gpu=32 \
77+
actor_rollout_ref.rollout.tensor_model_parallel_size=2 \
78+
actor_rollout_ref.rollout.name=sglang \
79+
actor_rollout_ref.rollout.engine_kwargs.sglang.attention_backend=triton \
80+
actor_rollout_ref.rollout.gpu_memory_utilization=0.6 \
81+
actor_rollout_ref.rollout.n=5 \
82+
actor_rollout_ref.rollout.load_format=safetensors \
83+
actor_rollout_ref.ref.log_prob_micro_batch_size_per_gpu=32 \
84+
actor_rollout_ref.ref.fsdp_config.param_offload=True \
85+
algorithm.use_kl_in_reward=False \
86+
trainer.critic_warmup=0 \
87+
trainer.logger='["console","wandb"]' \
88+
trainer.project_name='verl_grpo_example_gsm8k_math' \
89+
trainer.experiment_name='oai_oss_20b_function_rm' \
90+
trainer.n_gpus_per_node=8 \
91+
trainer.nnodes=1 \
92+
trainer.save_freq=50 \
93+
trainer.test_freq=10 \
94+
trainer.total_epochs=15 $@

0 commit comments

Comments
 (0)