Skip to content

Conversation

@SuperCB
Copy link
Contributor

@SuperCB SuperCB commented Jul 1, 2025

What does this PR do?

PR (https://github.com/volcengine/verl/pull/1911) did not include Multi-stage Awake for Megatron+Sglang. This PR implemented that functionality. After this feature is completed, the sglang's mem_fraction_static parameter can be set to 0.9 or even higher.

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

High-Level Design

Demonstrate the high-level design if this PR is complex.

Specific Changes

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.

@CLAassistant
Copy link

CLAassistant commented Jul 1, 2025

CLA assistant check
All committers have signed the CLA.

@SuperCB
Copy link
Contributor Author

SuperCB commented Jul 1, 2025

Runnable configuration:

set -ex

# If you are using vllm<=0.6.3, you might need to set the following environment variable to avoid bugs:
# export VLLM_ATTENTION_BACKEND=XFORMERS
export CUDA_DEVICE_MAX_CONNECTIONS=1 # For megatron communication/computation overlapping
export VERL_PPO_LOGGING_LEVEL=INFO

gsm8k_train_path=$HOME/data/gsm8k/train.parquet
gsm8k_test_path=$HOME/data/gsm8k/test.parquet
math_train_path=$HOME/data/math/train.parquet
math_test_path=$HOME/data/math/test.parquet
MEGATRON_PATH=/cpfs/user/cuibo/Megatron-LM/
export PYTHONPATH=$MEGATRON_PATH:$PYTHONPATH
train_files="['$gsm8k_train_path' ]"
test_files="['$gsm8k_test_path']"

python3 -m verl.trainer.main_ppo --config-path=./config --config-name='ppo_megatron_trainer' \
	algorithm.adv_estimator=gae \
	data.train_files="$train_files" \
	data.val_files="$test_files" \
	data.train_batch_size=1024 \
	data.max_prompt_length=1024 \
	data.max_response_length=512 \
	data.filter_overlong_prompts=True \
	data.truncation='error' \
	actor_rollout_ref.model.path=Qwen/Qwen2-7B-Instruct \
	actor_rollout_ref.actor.optim.lr=1e-6 \
	actor_rollout_ref.actor.ppo_mini_batch_size=256 \
	actor_rollout_ref.actor.ppo_micro_batch_size_per_gpu=4 \
	actor_rollout_ref.actor.megatron.pipeline_model_parallel_size=1 \
	actor_rollout_ref.actor.megatron.tensor_model_parallel_size=4 \
	actor_rollout_ref.actor.megatron.param_offload=True \
	actor_rollout_ref.actor.megatron.grad_offload=True \
	actor_rollout_ref.actor.megatron.optimizer_offload=True \
	actor_rollout_ref.actor.use_kl_loss=False \
	actor_rollout_ref.rollout.log_prob_micro_batch_size_per_gpu=4 \
	actor_rollout_ref.rollout.tensor_model_parallel_size=4 \
	actor_rollout_ref.rollout.name=sglang \
	actor_rollout_ref.rollout.multi_stage_wake_up=True \
	actor_rollout_ref.rollout.gpu_memory_utilization=0.8 \
	actor_rollout_ref.ref.megatron.tensor_model_parallel_size=4 \
	critic.optim.lr=1e-5 \
	critic.model.path=Qwen/Qwen2-7B-Instruct \
	critic.model.enable_gradient_checkpointing=False \
	critic.ppo_micro_batch_size_per_gpu=4 \
	critic.megatron.param_offload=True \
	critic.megatron.grad_offload=True \
	critic.megatron.optimizer_offload=True \
	algorithm.use_kl_in_reward=False \
	trainer.critic_warmup=0 \
	trainer.logger=['console'] \
	trainer.project_name='verl_ppo_gsm8k_math_examples' \
	trainer.experiment_name='qwen2_7b_megatron' \
	trainer.n_gpus_per_node=8 \
	trainer.nnodes=1 \
	trainer.save_freq=20 \
	trainer.test_freq=5 \
	trainer.total_epochs=100 $@

@SuperCB
Copy link
Contributor Author

SuperCB commented Jul 1, 2025

However, there are still some issues here. The rollout.gpu_memory_utilization can only reach a maximum of 0.8 and cannot be further increased (for example, to 0.9). I am still working on figuring out exactly why this is happening.

@zhaochenyang20
Copy link
Collaborator

zhaochenyang20 commented Jul 1, 2025

However, there are still some issues here. The rollout.gpu_memory_utilization can only reach a maximum of 0.8 and cannot be further increased (for example, to 0.9). I am still working on figuring out exactly why this is happening.

This is usual. FSDP offload and upload cause mem fractions on GPU. So we should left some for that. Also, would you like to add my wechat to discuss. 18015766633

@SuperCB
Copy link
Contributor Author

SuperCB commented Jul 2, 2025

However, there are still some issues here. The rollout.gpu_memory_utilization can only reach a maximum of 0.8 and cannot be further increased (for example, to 0.9). I am still working on figuring out exactly why this is happening.

This is usual. FSDP offload and upload cause mem fractions on GPU. So we should left some for that. Also, would you like to add my wechat to discuss. 18015766633

ok

@zhaochenyang20
Copy link
Collaborator

#2187 is for FSDP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants