verl Guide: Volcano Engine RL Framework for LLMs

The Problem: The Computational Mismatch in LLM Reinforcement Learning
In modern artificial intelligence, autonomous web data extraction agents, and reasoning-driven copilot platforms powered by AiFetchly, foundation models increasingly rely on post-training reinforcement learning (RL). While Supervised Fine-Tuning (SFT) teaches models how to mimic human style and syntax, Reinforcement Learning with Verifiable Rewards (RLVR) enables emergent Chain-of-Thought (CoT) reasoning, autonomous error correction, and multi-step tool-calling verification—as demonstrated by frontier models like DeepSeek-R1, OpenAI o1, and Kimi k1.5.
However, scaling reinforcement learning (such as Proximal Policy Optimization or Group Relative Policy Optimization) on Large Language Models has historically been one of the most frustrating, resource-intensive challenges in deep learning infrastructure.
The core failure stems from a fundamental computational mismatch between rollout generation and model training.
The Traditional RLHF Computational Dilemma:
┌─────────────────────────────────────────────────────────────────┐
│ 1. Rollout Phase (Sample Generation): Memory-Bandwidth Bound │
│ • Autoregressive token-by-token generation across batch │
│ • Requires dynamic KV caching, continuous batching, and high QPS│
│ • Ideal Engine: Specialized Inference Serving (vLLM / SGLang) │
└─────────────────────────────────────────────────────────────────┘
▲
│ Severe Systems Mismatch!
▼
┌─────────────────────────────────────────────────────────────────┐
│ 2. Training Phase (Policy & Value Updates): Compute-Bound │
│ • Parallel matrix multiplication backpropagation (backward pass)│
│ • Requires ZeRO/FSDP parameter sharding, TP/PP, gradient states │
│ • Ideal Engine: Distributed Training (PyTorch FSDP2 / Megatron) │
└─────────────────────────────────────────────────────────────────┘
Result: Existing frameworks suffer from 80% GPU idle stalls or severe VRAM thrashing! 1. The Rollout Generation Bottleneck
In a standard PPO or GRPO training loop, the system must generate thousands of candidate completions (rollouts) for every prompt batch before computing reward signals:
- Legacy RLHF frameworks (such as Hugging Face TRL, early DeepSpeed-Chat, and naive PyTorch implementations) execute the generation phase inside the training framework itself.
- Because standard training engines lack PagedAttention, dynamic memory management, and iteration-level continuous batching, autoregressive generation is excruciatingly slow.
- In production training runs, over 70% to 85% of total cluster GPU time is spent idling, waiting for slow, unbatched autoregressive decoding to finish before a single backward pass can execute.
2. High-Bandwidth Memory (HBM) Exhaustion Across Multiple Models
Standard PPO requires co-locating up to four distinct model copies simultaneously:
- The Actor (Policy) Model: The model being actively trained.
- The Critic (Value) Model: Predicts expected state rewards to compute Generalized Advantage Estimation (GAE).
- The Reference Model: Frozen base model used to calculate KL-divergence penalties.
- The Reward Model: Evaluates output quality and assigns scalar scores.
When scaling beyond 14B or 32B parameters, loading weights, optimizer states, and activations for four model instances across GPU nodes causes immediate Out-of-Memory (OOM) failures, forcing teams to dramatically downscale batch sizes and truncate reasoning sequences.
3. The IPC and Weight Synchronization Nightmare
To bypass slow generation in PyTorch, some teams attempted to run two separate clusters: one cluster running inference engines (like vLLM) and another running training frameworks (like Megatron-LM).
However, this decoupled topology introduces severe operational friction:
- After every training step, updated policy weights must be serialized, transferred over TCP/InfiniBand network sockets, and re-loaded into the inference workers.
- Network transfer latency, serialization overhead, and inter-process communication (IPC) deadlocks wipe out the throughput gains of dedicated serving engines.
To resolve these architectural trade-offs, researchers and engineers at ByteDance Volcano Engine created verl (Volcano Engine Reinforcement Learning for LLMs): a flexible, production-grade distributed RL library that seamlessly unifies high-throughput vLLM rollout generation with PyTorch FSDP2 and Megatron-LM training via zero-copy in-place memory management.
The Solution: verl Architecture and Hybrid Engine Topology
verl breaks the RLHF scaling wall by introducing a modular, decoupled programming model orchestrated by Ray, coupled with a Hybrid Engine Architecture that allows inference engines and training engines to share physical GPUs with zero-copy weight synchronization.
verl Hybrid Engine Co-Execution Architecture:
┌─────────────────────────────────────────────────────────────────┐
│ Ray Orchestrator: Decoupled RL Algorithmic Workflow (GRPO / PPO)│
└─────────────────────────────────────────────────────────────────┘
│
┌───────────────┴───────────────┐
▼ ▼
┌─────────────────────────────┐ ┌─────────────────────────────────┐
│ Rollout Workers (vLLM Engine)│ │ Training Workers (FSDP2/Megatron)│
│ • PagedAttention V2 │ │ • Distributed Backpropagation │
│ • Continuous Batching │ │ • Per-parameter sharding (ZeRO-3)│
│ • Generates 32K CoT rollouts│ │ • FP8 mixed-precision gradients │
└─────────────────────────────┘ └─────────────────────────────────┘
▲ ▲
└─────── In-Place GPU Memory ───┘
Zero-Copy Weight Synchronization
(Zero CPU Host / Network Roundtrips!) 1. Decoupled Programming Model with Ray
verl completely decouples the mathematical logic of reinforcement learning algorithms from low-level distributed hardware primitives:
- Algorithmic Abstraction: PPO, GRPO, ReMax, DPO, and Reinforcement Learning with Verifiable Rewards (RLVR) are expressed as high-level, human-readable Python workflows.
- Ray Actor Orchestration: Instead of hardcoding MPI process ranks, verl represents model roles as modular Ray actors (
RolloutWorker,ActorTrainingWorker,CriticTrainingWorker,RewardWorker). - This allows developers to flexibly scale the ratio of generation GPUs to training GPUs dynamically depending on cluster availability.
2. The Hybrid Engine: In-Place vLLM and FSDP2 Co-Execution
The defining systems breakthrough of verl is its Hybrid Engine:
- Rather than hosting separate machines for inference and training, verl executes both vLLM (inference) and PyTorch FSDP2 / Megatron-LM (training) on the same physical GPUs.
- Phase 1 (Rollout): vLLM initializes the model in GPU memory, executing high-throughput batched sampling using PagedAttention and chunked prefill.
- Phase 2 (Training): Once rollouts finish, verl unloads intermediate inference activation caches and dynamically exposes the raw parameter tensors to PyTorch FSDP2.
- Zero-Copy Weight Update: After gradient descent computes weight updates, verl synchronizes the updated weights directly inside GPU High-Bandwidth Memory (HBM) using in-place tensor pointer remapping. There is zero serialization to CPU RAM and zero network transfer.
3. Native GRPO Support for Long-Horizon Reasoning
verl provides native, highly optimized support for Group Relative Policy Optimization (GRPO)—the exact algorithmic foundation popularized by DeepSeek-R1:
- Critic Model Elimination: Traditional PPO requires a massive Critic model that consumes 50% of the training memory budget. GRPO eliminates the Critic entirely by sampling a group of outputs ${y_1, y_2, \dots, y_G}$ for each prompt $q$ and computing the baseline advantage relatively: $$A_i = \frac{R_i - \text{mean}({R_1, \dots, R_G})}{\text{std}({R_1, \dots, R_G}) + \epsilon}$$
- 32K+ Token Chain-of-Thought: By saving memory previously reserved for the Critic network, verl easily accommodates long reasoning trajectories up to 32,000 or 64,000 tokens per rollout without Out-of-Memory crashes.
Architectural Comparison: verl vs. TRL vs. DeepSpeed-Chat vs. OpenRLHF
To understand why verl has become the open-source standard for post-training reasoning models, consider the following technical benchmark comparison:
| System Dimension | Hugging Face TRL | DeepSpeed-Chat | OpenRLHF | verl (ByteDance) |
|---|---|---|---|---|
| Rollout Engine | Naive PyTorch generation | DeepSpeed ZeRO-Inference | Ray + vLLM | Integrated Hybrid vLLM Engine |
| Training Engine | PyTorch / Accelerate | DeepSpeed ZeRO-3 | Megatron-LM / vLLM | PyTorch FSDP2 & Megatron-LM |
| Weight Synchronization | Intra-process (Slow) | Host CPU memory copy | Network / Ray IPC | In-Place Zero-Copy GPU HBM Sync |
| GRPO Support | Experimental / Inefficient | None | Basic | Native First-Class SOTA (32K+ CoT) |
| Relative Training Speed | 1.0x (Baseline) | 1.8x | 3.5x | 4.0x – 10.0x (Peak Hardware MFU) |
| Max Context Length (RL) | ~4,096 Tokens | ~8,192 Tokens | ~16,384 Tokens | 32,768+ Tokens (Reasoning Scale) |
| Hardware Portability | NVIDIA GPUs | NVIDIA GPUs | NVIDIA GPUs | NVIDIA, AMD ROCm, Apple Silicon |
Hands-On Implementation: Training a Reasoning LLM with verl and GRPO
Below is a complete, production-ready guide showing how to set up verl, configure a Group Relative Policy Optimization (GRPO) training pipeline, and execute post-training with verifiable rewards on a multi-GPU workstation or cluster.
Step 1: Install verl and Hardware Dependencies
Clone the verl repository and install with vLLM and FlashAttention-2 support:
# Create isolated Python virtual environment
conda create -n verl python=3.10 -y
conda activate verl
# Install PyTorch with CUDA 12.4
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
# Install vLLM and FlashAttention-2
pip install "vllm>=0.6.3" flash-attn --no-build-isolation
# Clone and install verl
git clone https://github.com/volcengine/verl.git
cd verl
pip install -e . Step 2: Define a Verifiable Reward Function
In reasoning RL (RLVR), rewards are strictly deterministic. Below is an accuracy reward function verifying mathematical solutions extracted from a model’s Chain-of-Thought:
# reward_function.py
import re
def compute_math_reward(solution_str: str, ground_truth: str) -> float:
"""
Verifiable Reward Function:
Awards 1.0 for exact mathematical correctness,
0.1 for proper formatting (<think> ... </think> <answer> ... </answer>),
and 0.0 for incorrect answers.
"""
reward = 0.0
# 1. Check for valid structured thinking tags
has_thinking = bool(re.search(r"<think>.*?</think>", solution_str, re.DOTALL))
has_answer = bool(re.search(r"<answer>.*?</answer>", solution_str, re.DOTALL))
if has_thinking and has_answer:
reward += 0.1
# 2. Extract final boxed answer
match = re.search(r"<answer>(.*?)</answer>", solution_str, re.DOTALL)
if match:
predicted_answer = match.group(1).strip()
# Verify exact mathematical match
if predicted_answer.lower() == ground_truth.strip().lower():
reward += 0.9
return reward Step 3: Configure verl GRPO Training YAML
Configure verl’s training parameters using Hydra YAML configuration (grpo_math.yaml):
data:
train_files: './data/math_prompts.parquet'
prompt_key: 'prompt'
max_prompt_length: 1024
max_response_length: 4096
train_batch_size: 128
actor_rollout_ref:
model:
path: 'Qwen/Qwen2.5-7B'
external_lib: null
actor:
strategy: 'fsdp'
fsdp_config:
wrap_policy: 'transformer_auto_wrap'
mixed_precision: true
optim:
lr: 1.0e-6
ppo_mini_batch_size: 32
ppo_micro_batch_size_per_gpu: 2
use_kl_loss: true
kl_loss_coef: 0.001
rollout:
name: 'vllm'
temperature: 0.8
top_p: 0.95
n: 8 # GRPO group size: Sample 8 completions per prompt!
gpu_memory_utilization: 0.5
ref:
fsdp_config:
wrap_policy: 'transformer_auto_wrap'
algorithm:
adv_estimator: 'grpo' # Uses Group Relative Policy Optimization!
gamma: 1.0
lam: 1.0
trainer:
total_epochs: 3
save_freq: 50
test_freq: 10
logger: ['console', 'wandb'] Step 4: Launch Distributed Training Loop
Execute distributed GRPO training across 8x NVIDIA H100 or A100 GPUs using Ray:
# Launch verl distributed training job
python3 -m verl.trainer.main_ppo --config-path=./config --config-name=grpo_math trainer.project_name=verl_reasoning_experiment During training, verl’s console monitors rollout throughput, group-relative advantage variance, and the emergence of extended reflection tokens ("Wait, let me double check...").
Production Deployment with aiFetchly
In autonomous web data extraction, multi-step browser navigation, and schema synthesis platforms engineered by AiFetchly, foundation models execute complex, multi-page data extraction workflows.
Here is how verl-trained reasoning models transform automated web intelligence:
aiFetchly Agentic Post-Training Loop with verl:
┌─────────────────────────────────────────────────────────────────┐
│ 1. Autonomous Web Task Ingestion │
│ • Prompt: "Scrape quarterly balance sheet from dynamic website" │
├─────────────────────────────────────────────────────────────────┤
│ 2. High-Throughput vLLM Exploration Rollouts │
│ • verl generates N=8 exploratory trajectories in parallel │
│ • Agents propose varied CSS selectors, click paths, and tools │
├─────────────────────────────────────────────────────────────────┤
│ 3. Verifiable Web Extraction Reward Computation │
│ • Deterministic validator checks extracted JSON against schema │
│ • Success = Valid financial sum (Reward +1.0) │
│ • Failure = Anti-bot trigger / Empty table (Reward 0.0) │
├─────────────────────────────────────────────────────────────────┤
│ 4. verl In-Place GRPO Policy Backpropagation │
│ • Advantage computed relative to peer trajectory success │
│ • Policy learns self-correcting navigation without human demos! │
└─────────────────────────────────────────────────────────────────┘ - Self-Correcting Web Navigation: By post-training agents with verl and verifiable rewards, aiFetchly’s browser controllers learn to backtrack, inspect failed DOM queries, and discover alternative click sequences autonomously.
- Zero Human-Annotation Overhead: Instead of paying for costly human-labeled scraping demonstrations, verl trains agents via pure synthetic reinforcement learning with programmatic DOM validators.
- Cluster Efficiency: With verl’s in-place zero-copy weight synchronization, aiFetchly scales agent post-training at a fraction of the cloud GPU compute costs required by legacy RLHF stacks.
To discover how aiFetchly combines reasoning foundation models with scalable web data extraction, explore our AiFetchly Documentation or examine our AiFetchly Pricing.