verl icon indicating copy to clipboard operation
verl copied to clipboard

[WIP][recipe, sglang] support sglang as rollout engine in fully async policy

Open AniZpZ opened this issue 1 year ago • 3 comments

What does this PR do?

Extend the fully async policy recipe by adding SGLang as an alternative rollout engine to vLLM when using FSDP

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.

# 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.

AniZpZ avatar Nov 19 '25 10:11 AniZpZ

Hi,I tried your PR and attempted to replace FSDP with Megatron, but I encountered this error. Have you come across it before? Traceback (most recent call last): File "verl/recipe/fully_async_policy/fully_async_main.py", line 292, in main run_ppo(config, task_runner_class=FullyAsyncTaskRunner) File "verl/verl/trainer/main_ppo.py", line 115, in run_ppo ray.get(runner.run.remote(config)) File "/usr/local/lib/python3.10/dist-packages/ray/_private/auto_init_hook.py", line 22, in auto_init_wrapper return fn(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/ray/_private/client_mode_hook.py", line 104, in wrapper return func(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/ray/_private/worker.py", line 2961, in get values, debugger_breakpoint = worker.get_objects( File "/usr/local/lib/python3.10/dist-packages/ray/_private/worker.py", line 1026, in get_objects raise value.as_instanceof_cause() ray.exceptions.RayTaskError(AttributeError): ray::FullyAsyncTaskRunner.run() (pid=381899, ip=10.92.240.81, actor_id=3eb5061ea7fd165c6fef1fb811000000, repr=<fully_async_main.FullyAsyncTaskRunner object at 0x7f221528f430>) File "verl/recipe/fully_async_policy/fully_async_main.py", line 138, in run self._run_training_loop() File "verl/recipe/fully_async_policy/fully_async_main.py", line 268, in _run_training_loop raise e File "verl/recipe/fully_async_policy/fully_async_main.py", line 262, in _run_training_loop ray.get(future) ray.exceptions.RayTaskError(AttributeError): ray::FullyAsyncTrainer.fit() (pid=382636, ip=10.92.240.81, actor_id=46571d273791a7f60ff7a86211000000, repr=<recipe.fully_async_policy.fully_async_trainer.FullyAsyncTrainer object at 0x7f1e26892f80>) File "verl/recipe/fully_async_policy/fully_async_trainer.py", line 270, in fit self._check_save_checkpoint(False, timing_raw) File "verl/recipe/fully_async_policy/ray_trainer.py", line 722, in _check_save_checkpoint self._save_checkpoint() File "verl/verl/trainer/ppo/ray_trainer.py", line 1024, in _save_checkpoint dataloader_state_dict = self.train_dataloader.state_dict() AttributeError: 'FullyAsyncTrainer' object has no attribute 'train_dataloader'

lizipao avatar Nov 21 '25 12:11 lizipao

Hi,I tried your PR and attempted to replace FSDP with Megatron, but I encountered this error. Have you come across it before? Traceback (most recent call last): File "verl/recipe/fully_async_policy/fully_async_main.py", line 292, in main run_ppo(config, task_runner_class=FullyAsyncTaskRunner) File "verl/verl/trainer/main_ppo.py", line 115, in run_ppo ray.get(runner.run.remote(config)) File "/usr/local/lib/python3.10/dist-packages/ray/_private/auto_init_hook.py", line 22, in auto_init_wrapper return fn(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/ray/_private/client_mode_hook.py", line 104, in wrapper return func(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/ray/_private/worker.py", line 2961, in get values, debugger_breakpoint = worker.get_objects( File "/usr/local/lib/python3.10/dist-packages/ray/_private/worker.py", line 1026, in get_objects raise value.as_instanceof_cause() ray.exceptions.RayTaskError(AttributeError): ray::FullyAsyncTaskRunner.run() (pid=381899, ip=10.92.240.81, actor_id=3eb5061ea7fd165c6fef1fb811000000, repr=<fully_async_main.FullyAsyncTaskRunner object at 0x7f221528f430>) File "verl/recipe/fully_async_policy/fully_async_main.py", line 138, in run self._run_training_loop() File "verl/recipe/fully_async_policy/fully_async_main.py", line 268, in _run_training_loop raise e File "verl/recipe/fully_async_policy/fully_async_main.py", line 262, in _run_training_loop ray.get(future) ray.exceptions.RayTaskError(AttributeError): ray::FullyAsyncTrainer.fit() (pid=382636, ip=10.92.240.81, actor_id=46571d273791a7f60ff7a86211000000, repr=<recipe.fully_async_policy.fully_async_trainer.FullyAsyncTrainer object at 0x7f1e26892f80>) File "verl/recipe/fully_async_policy/fully_async_trainer.py", line 270, in fit self._check_save_checkpoint(False, timing_raw) File "verl/recipe/fully_async_policy/ray_trainer.py", line 722, in _check_save_checkpoint self._save_checkpoint() File "verl/verl/trainer/ppo/ray_trainer.py", line 1024, in _save_checkpoint dataloader_state_dict = self.train_dataloader.state_dict() AttributeError: 'FullyAsyncTrainer' object has no attribute 'train_dataloader'

sry, i have not adapted ot for megatron and encounter the same issue yet.

AniZpZ avatar Nov 26 '25 13:11 AniZpZ

Hi,I tried your PR and attempted to replace FSDP with Megatron, but I encountered this error. Have you come across it before? Traceback (most recent call last): File "verl/recipe/fully_async_policy/fully_async_main.py", line 292, in main run_ppo(config, task_runner_class=FullyAsyncTaskRunner) File "verl/verl/trainer/main_ppo.py", line 115, in run_ppo ray.get(runner.run.remote(config)) File "/usr/local/lib/python3.10/dist-packages/ray/_private/auto_init_hook.py", line 22, in auto_init_wrapper return fn(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/ray/_private/client_mode_hook.py", line 104, in wrapper return func(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/ray/_private/worker.py", line 2961, in get values, debugger_breakpoint = worker.get_objects( File "/usr/local/lib/python3.10/dist-packages/ray/_private/worker.py", line 1026, in get_objects raise value.as_instanceof_cause() ray.exceptions.RayTaskError(AttributeError): ray::FullyAsyncTaskRunner.run() (pid=381899, ip=10.92.240.81, actor_id=3eb5061ea7fd165c6fef1fb811000000, repr=<fully_async_main.FullyAsyncTaskRunner object at 0x7f221528f430>) File "verl/recipe/fully_async_policy/fully_async_main.py", line 138, in run self._run_training_loop() File "verl/recipe/fully_async_policy/fully_async_main.py", line 268, in _run_training_loop raise e File "verl/recipe/fully_async_policy/fully_async_main.py", line 262, in _run_training_loop ray.get(future) ray.exceptions.RayTaskError(AttributeError): ray::FullyAsyncTrainer.fit() (pid=382636, ip=10.92.240.81, actor_id=46571d273791a7f60ff7a86211000000, repr=<recipe.fully_async_policy.fully_async_trainer.FullyAsyncTrainer object at 0x7f1e26892f80>) File "verl/recipe/fully_async_policy/fully_async_trainer.py", line 270, in fit self._check_save_checkpoint(False, timing_raw) File "verl/recipe/fully_async_policy/ray_trainer.py", line 722, in _check_save_checkpoint self._save_checkpoint() File "verl/verl/trainer/ppo/ray_trainer.py", line 1024, in _save_checkpoint dataloader_state_dict = self.train_dataloader.state_dict() AttributeError: 'FullyAsyncTrainer' object has no attribute 'train_dataloader'

sry, i have not adapted ot for megatron and encounter the same issue yet.

thanks, I have fixed it

lizipao avatar Nov 26 '25 13:11 lizipao

How do you fix this problem?, I have met the same error @lizipao

Hi,I tried your PR and attempted to replace FSDP with Megatron, but I encountered this error. Have you come across it before? Traceback (most recent call last): File "verl/recipe/fully_async_policy/fully_async_main.py", line 292, in main run_ppo(config, task_runner_class=FullyAsyncTaskRunner) File "verl/verl/trainer/main_ppo.py", line 115, in run_ppo ray.get(runner.run.remote(config)) File "/usr/local/lib/python3.10/dist-packages/ray/_private/auto_init_hook.py", line 22, in auto_init_wrapper return fn(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/ray/_private/client_mode_hook.py", line 104, in wrapper return func(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/ray/_private/worker.py", line 2961, in get values, debugger_breakpoint = worker.get_objects( File "/usr/local/lib/python3.10/dist-packages/ray/_private/worker.py", line 1026, in get_objects raise value.as_instanceof_cause() ray.exceptions.RayTaskError(AttributeError): ray::FullyAsyncTaskRunner.run() (pid=381899, ip=10.92.240.81, actor_id=3eb5061ea7fd165c6fef1fb811000000, repr=<fully_async_main.FullyAsyncTaskRunner object at 0x7f221528f430>) File "verl/recipe/fully_async_policy/fully_async_main.py", line 138, in run self._run_training_loop() File "verl/recipe/fully_async_policy/fully_async_main.py", line 268, in _run_training_loop raise e File "verl/recipe/fully_async_policy/fully_async_main.py", line 262, in _run_training_loop ray.get(future) ray.exceptions.RayTaskError(AttributeError): ray::FullyAsyncTrainer.fit() (pid=382636, ip=10.92.240.81, actor_id=46571d273791a7f60ff7a86211000000, repr=<recipe.fully_async_policy.fully_async_trainer.FullyAsyncTrainer object at 0x7f1e26892f80>) File "verl/recipe/fully_async_policy/fully_async_trainer.py", line 270, in fit self._check_save_checkpoint(False, timing_raw) File "verl/recipe/fully_async_policy/ray_trainer.py", line 722, in _check_save_checkpoint self._save_checkpoint() File "verl/verl/trainer/ppo/ray_trainer.py", line 1024, in _save_checkpoint dataloader_state_dict = self.train_dataloader.state_dict() AttributeError: 'FullyAsyncTrainer' object has no attribute 'train_dataloader'

sry, i have not adapted ot for megatron and encounter the same issue yet.

thanks, I have fixed it

ForeverDJ-ux avatar Dec 05 '25 07:12 ForeverDJ-ux

How do you fix this problem?, I have met the same error @lizipao

Hi,I tried your PR and attempted to replace FSDP with Megatron, but I encountered this error. Have you come across it before? Traceback (most recent call last): File "verl/recipe/fully_async_policy/fully_async_main.py", line 292, in main run_ppo(config, task_runner_class=FullyAsyncTaskRunner) File "verl/verl/trainer/main_ppo.py", line 115, in run_ppo ray.get(runner.run.remote(config)) File "/usr/local/lib/python3.10/dist-packages/ray/_private/auto_init_hook.py", line 22, in auto_init_wrapper return fn(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/ray/_private/client_mode_hook.py", line 104, in wrapper return func(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/ray/_private/worker.py", line 2961, in get values, debugger_breakpoint = worker.get_objects( File "/usr/local/lib/python3.10/dist-packages/ray/_private/worker.py", line 1026, in get_objects raise value.as_instanceof_cause() ray.exceptions.RayTaskError(AttributeError): ray::FullyAsyncTaskRunner.run() (pid=381899, ip=10.92.240.81, actor_id=3eb5061ea7fd165c6fef1fb811000000, repr=<fully_async_main.FullyAsyncTaskRunner object at 0x7f221528f430>) File "verl/recipe/fully_async_policy/fully_async_main.py", line 138, in run self._run_training_loop() File "verl/recipe/fully_async_policy/fully_async_main.py", line 268, in _run_training_loop raise e File "verl/recipe/fully_async_policy/fully_async_main.py", line 262, in _run_training_loop ray.get(future) ray.exceptions.RayTaskError(AttributeError): ray::FullyAsyncTrainer.fit() (pid=382636, ip=10.92.240.81, actor_id=46571d273791a7f60ff7a86211000000, repr=<recipe.fully_async_policy.fully_async_trainer.FullyAsyncTrainer object at 0x7f1e26892f80>) File "verl/recipe/fully_async_policy/fully_async_trainer.py", line 270, in fit self._check_save_checkpoint(False, timing_raw) File "verl/recipe/fully_async_policy/ray_trainer.py", line 722, in _check_save_checkpoint self._save_checkpoint() File "verl/verl/trainer/ppo/ray_trainer.py", line 1024, in _save_checkpoint dataloader_state_dict = self.train_dataloader.state_dict() AttributeError: 'FullyAsyncTrainer' object has no attribute 'train_dataloader'

sry, i have not adapted ot for megatron and encounter the same issue yet.

thanks, I have fixed it

我在recipe\fully_async_policy\fully_async_trainer.py里加了 from verl.trainer.main_ppo import create_rl_dataset, create_rl_sampler from verl.utils.dataset.rl_dataset import collate_fn

    train_dataset = create_rl_dataset(config.data.train_files, config.data, tokenizer, processor)
    val_dataset = create_rl_dataset(config.data.val_files, config.data, tokenizer, processor)
    train_sampler = create_rl_sampler(config.data, train_dataset)

    print(f"[FullyAsyncRollouter] Rollouter _create_dataloader...\n{train_dataset}\n{val_dataset}")

    self._create_dataloader(train_dataset, val_dataset, collate_fn, train_sampler)

lizipao avatar Dec 07 '25 07:12 lizipao

Test Results Supplements

We conducted tests on 64 H20 GPUs using the Qwen2.5-Math-7B model, with the dapo-math-17k dataset as the train set and aime-2024 as the test set. A total of 400 steps were trained, with testing performed every 10 steps. The experimental results are as follows: 截屏2025-12-17 下午2 33 44 截屏2025-12-17 下午2 33 52 截屏2025-12-17 下午2 34 07

We tested under the same conditions by replacing the rollout backend engine with vLLM, and the comparison results are as follows: 截屏2025-12-17 下午2 38 43 截屏2025-12-17 下午2 38 49 截屏2025-12-17 下午2 38 56

A more detailed comparative analysis between vLLM and SGLang is conducted on steps 100-300 (stable phase).

1. Performance Metrics Comparison
Metric SGLang VLLM Ratio (SGLang/VLLM) Relative Difference Note
Throughput (tokens/sec) 703.46 635.85 1.1063 +10.63% SGLang is faster
Time per Step (sec) 193.54 229.89 0.8419 -15.81% SGLang is faster
MFU 0.6802 0.6760 1.0063 +0.63% Comparable
Total Tokens 8,583,224 8,927,580 0.9614 -3.86% VLLM has slightly more
Throughput (perf/throughput)
  • SGLang: Mean=703.46, Median=728.33, Min=280.39, Max=753.76, Std=71.00
  • VLLM: Mean=635.85, Median=689.51, Min=255.31, Max=730.12, Std=113.49
Time per Step (perf/time_per_step)
  • SGLang: Mean=193.54s, Median=184.78s, Min=173.91s, Max=483.87s, Std=30.78s
  • VLLM: Mean=229.89s, Median=203.10s, Min=185.95s, Max=521.57s, Std=60.92s
2. Time Metrics Comparison
Metric SGLang VLLM Ratio (SGLang/VLLM) Relative Difference Note
Generation Time (sec) 40.36 70.53 0.5722 -42.78% SGLang is significantly faster
Actor Update Time (sec) 152.05 158.10 0.9618 -3.82% Comparable
Total Step Time (sec) 193.54 229.89 0.8419 -15.81% SGLang is faster
Validation Wait Time (sec) 0.0024 0.0032 0.7564 -24.36% SGLang is faster
Parameter Sync Time (sec) 18.34 5.18 3.5380 +253.80% ⚠️ VLLM is faster
Generation Time per Token (ms) 0.0024 0.0042 0.5681 -43.19% SGLang is significantly faster
Actor Update Time per Token (ms) 0.0169 0.0172 0.9842 -1.58% Comparable
3. Validation Metrics Comparison
Metric SGLang VLLM Ratio (SGLang/VLLM) Relative Difference Note
Validation Reward (mean@1) -0.3373 -0.4299 0.7846 +21.54% SGLang is higher
Validation Score (mean@1) -0.3372 -0.4299 0.7844 +21.56% SGLang is higher
Validation Accuracy (mean@1) 0.3314 0.2851 1.1625 +16.25% SGLang is higher
Validation Accuracy (val-core/math_dapo/acc/mean@1)
  • SGLang: Mean=0.3314, Median=0.3323, Min=0.3000, Max=0.3510, Std=0.0141
  • VLLM: Mean=0.2851, Median=0.2854, Min=0.2521, Max=0.3167, Std=0.0177

jsfanfanfan avatar Dec 17 '25 06:12 jsfanfanfan

@chenhaiq @zhaochenyang20 could you please trigger the ci ?

AniZpZ avatar Dec 17 '25 06:12 AniZpZ

We further reduced the parameter synchronization time in https://github.com/volcengine/verl/pull/4191/commits/f6c75895475655d4bfb66d641e5cfd3dbcea9f76. Experiments conducted on 32 H20 GPUs, using data from step 20 to 120, show that the average parameter synchronization time decreased from 10.36 seconds to 1.34 seconds,reduced by approximately 87%.

jsfanfanfan avatar Dec 18 '25 16:12 jsfanfanfan

After this is tested and merged I can implement using NCCL directly, no HTTP, engine.update_weights_from_distributed

EduardDurech avatar Dec 26 '25 00:12 EduardDurech

By the way, help update the follow-up to-do list. As I understand it, we only need to keep these two items below. @jsfanfanfan

Transfer queue integration Asynchronous parameter synchronization

ArronHZG avatar Dec 30 '25 09:12 ArronHZG

By the way, help update the follow-up to-do list. As I understand it, we only need to keep these two items below. @jsfanfanfan

Transfer queue integration Asynchronous parameter synchronization

There is still an unresolved conflict between the partial rollout and the memory saver feature in SGLang, @AniZpZ is currently working on resolving this issue.

jsfanfanfan avatar Jan 05 '26 02:01 jsfanfanfan

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jan 09 '26 03:01 CLAassistant