verl로 Qwen3 강화학습
verl로 Qwen3 강화학습 (RL) 훈련하기
verl은 대규모 언어 모델(LLM)을 위한 유연하고 효율적이며 프로덕션 준비가 된 RL 훈련 라이브러리예요. verl은 "HybridFlow: A Flexible and Efficient RLHF Framework" 논문의 오픈소스 버전이에요.
출처: 문서
본문
GitHub 저장소: verl
verl은 유연하고 사용하기 쉬워요:
- 다양한 RL 알고리즘의 쉬운 확장: 하이브리드 컨트롤러 프로그래밍 모델 덕분에 복잡한 Post-Training 데이터플로우를 유연하게 표현하고 효율적으로 실행할 수 있어요. GRPO, PPO 같은 RL 데이터플로우를 몇 줄의 코드로 만들 수 있어요.
- 모듈식 API로 기존 LLM 인프라와의 매끄러운 통합: 계산과 데이터 의존성을 분리해서 FSDP, Megatron-LM, vLLM, SGLang 등 기존 LLM 프레임워크와 매끄럽게 통합할 수 있어요.
- 유연한 디바이스 매핑: 모델을 서로 다른 GPU 집합에 다양한 방식으로 배치할 수 있어 효율적인 리소스 활용과 다양한 클러스터 크기로의 확장을 지원해요.
- 인기 HuggingFace 모델과의 즉시 통합: verl은 Qwen, Llama 등을 포함한 인기 LLM 모델을 지원해요.
verl은 빠르기도 해요:
- 최첨단 처리량: SOTA LLM 훈련·추론 엔진 통합과 SOTA RL 처리량을 제공해요.
- 3D-HybridEngine을 통한 효율적인 actor 모델 리셰딩: 메모리 중복을 제거하고 훈련·생성 단계 전환 시 통신 오버헤드를 크게 줄여줘요.
다음으로 verl로 Qwen3 모델을 훈련하는 방법을 소개할게요.
강화학습 (RL)
현재 verl은 FSDP, Megatron-LM, vLLM, SGLang 등 다양한 훈련 프레임워크와 추론 프레임워크의 조합을 지원해요. 또한 PPO, GRPO, DAPO 등 여러 알고리즘으로 훈련할 수 있어요.
1단계: 환경 및 훈련 준비
verl의 설치 가이드를 따라 환경 구성을 완료하면 돼요.
데이터 준비는 다음 명령으로 수행할 수 있어요:
git clone https://github.com/volcengine/verl.git
cd verl
python3 examples/data_preprocess/gsm8k.py --local_dir ~/data/gsm8k
모델 다운로드는 다음 명령으로 할 수 있어요:
python3 -c "import transformers; transformers.pipeline('text-generation', model='Qwen/Qwen3-1.7B')"
2단계: 훈련 시작
verl에서는 훈련 프레임워크와 추론 프레임워크가 각각 모델 훈련·추론 작업을 지원한다면 자유롭게 조합할 수 있어서, verl이 RL 관련 훈련을 지원할 수 있어요.
아래는 FSDP와 vLLM을 사용해 verl에서 Qwen3 모델을 훈련하는 예시예요. Qwen3-1.7B를 예시로 골랐는데, 이 모델은 단일 80GB GPU와 64GB 이상 메모리의 머신만 있으면 훈련을 시작할 수 있기 때문이에요.
python3 -m verl.trainer.main_ppo \
algorithm.adv_estimator=grpo \
data.train_files=$HOME/data/gsm8k/train.parquet \
data.val_files=$HOME/data/gsm8k/test.parquet \
data.train_batch_size=1024 \
data.max_prompt_length=512 \
data.max_response_length=1024 \
data.filter_overlong_prompts=True \
data.truncation='error' \
actor_rollout_ref.model.path=Qwen/Qwen3-1.7B \
actor_rollout_ref.actor.optim.lr=1e-6 \
actor_rollout_ref.model.use_remove_padding=True \
actor_rollout_ref.actor.ppo_mini_batch_size=80 \
actor_rollout_ref.actor.ppo_micro_batch_size_per_gpu=20 \
actor_rollout_ref.actor.use_kl_loss=True \
actor_rollout_ref.actor.kl_loss_coef=0.001 \
actor_rollout_ref.actor.kl_loss_type=low_var_kl \
actor_rollout_ref.actor.entropy_coeff=0 \
actor_rollout_ref.model.enable_gradient_checkpointing=True \
actor_rollout_ref.actor.fsdp_config.param_offload=False \
actor_rollout_ref.actor.fsdp_config.optimizer_offload=False \
actor_rollout_ref.rollout.log_prob_micro_batch_size_per_gpu=20 \
actor_rollout_ref.rollout.tensor_model_parallel_size=1 \
actor_rollout_ref.rollout.name=vllm \
actor_rollout_ref.rollout.gpu_memory_utilization=0.6 \
actor_rollout_ref.rollout.n=3 \
actor_rollout_ref.ref.log_prob_micro_batch_size_per_gpu=20 \
actor_rollout_ref.ref.fsdp_config.param_offload=True \
algorithm.use_kl_in_reward=False \
trainer.critic_warmup=0 \
trainer.logger=['console'] \
trainer.project_name='verl_grpo_example_gsm8k' \
trainer.experiment_name='qwen3_1_7b_function_rm' \
trainer.n_gpus_per_node=1 \
trainer.nnodes=1 \
trainer.save_freq=-1 \
trainer.test_freq=5 \
trainer.total_epochs=15 $@
마지막으로
사용 중 어려움을 겪는다면 GitHub에서 토론에 참여해 보세요.