OpenRLHF Cheatsheet
OpenRLHF est un framework RLHF haute performance et open-source conçu pour l’échelle. Construit sur Ray pour la planification distribuée, vLLM pour la génération rapide et DeepSpeed/ZeRO pour l’entraînement, il sépare les modèles Actor, Critic, Reward et Reference sur des GPUs pour que tu puisses entraîner efficacement de grands modèles (70B+). Il implémente un large menu d’algorithmes — PPO, GRPO, REINFORCE++, RLOO — plus l’échantillonnage dynamique et le RL agentic asynchrone.
Le renforcement à l’échelle est exigeant opérationnellement. Commence sur un seul nœud avec un petit modèle, confirme que les tendances de récompense sont correctes, puis passe à une mise à l’échelle avec Ray.
Installation
| Method | Command |
|---|
| pip | pip install openrlhf |
| With vLLM extras | pip install openrlhf[vllm] |
| From source | git clone https://github.com/OpenRLHF/OpenRLHF && cd OpenRLHF && pip install -e . |
| Docker | use the project’s reference image (CUDA + deps preinstalled) |
| Requirements | NVIDIA GPU(s), CUDA, Ray, DeepSpeed, vLLM |
Architecture
| Component | Role |
|---|
| Actor | Le modèle de politique en cours d’entraînement |
| Critic | Modèle de valeur (PPO) |
| Reward model | Évalue les réponses générées |
| Reference model | Baseline gelée pour la pénalité KL |
| Ray | Planifie et place ces modèles sur les GPUs |
| vLLM engine | Accélère la phase de rollout/génération |
Points d’Entrée d’Entraînement Courants
OpenRLHF expédie les modules CLI par algorithme ; lancez avec deepspeed ou ray.
| Command | Purpose |
|---|
openrlhf.cli.train_sft | Supervised fine-tuning |
openrlhf.cli.train_rm | Reward model training |
openrlhf.cli.train_ppo | PPO (single-controller) |
openrlhf.cli.train_ppo_ray | PPO/GRPO distributed with Ray + vLLM |
openrlhf.cli.train_dpo | Direct Preference Optimization |
PPO/GRPO avec Ray (esquisse)
ray start --head --node-ip-address 0.0.0.0
python3 -m openrlhf.cli.train_ppo_ray \
--pretrain Qwen/Qwen2.5-7B-Instruct \
--reward_pretrain OpenRLHF/Llama-3-8b-rm-mixture \
--advantage_estimator group_norm \
--vllm_num_engines 2 --vllm_tensor_parallel_size 1 \
--actor_num_gpus_per_node 4 \
--colocate_actor_ref \
--prompt_data your/prompts --input_key prompt \
--save_path ./ckpt --use_wandb $WANDB_API_KEY
| Flag | Controls |
|---|
--pretrain | Base/actor model |
--reward_pretrain | Reward model path |
--advantage_estimator group_norm | Selects GRPO-style group normalization |
--vllm_num_engines | Number of vLLM rollout engines |
--actor_num_gpus_per_node | GPU allocation for the actor |
--colocate_actor_ref | Place actor + reference together to save GPUs |
Algorithmes
| Algorithm | Flag/Module |
|---|
| PPO | default in train_ppo* |
| GRPO | --advantage_estimator group_norm |
| REINFORCE++ | --advantage_estimator reinforce family |
| RLOO | --advantage_estimator rloo |
| DPO / KTO | dedicated train_dpo / train_kto modules |
| Technique | Flag/Note |
|---|
| ZeRO stage | --zero_stage 3 for large models |
| Offload | --adam_offload to spill optimizer state to CPU |
| Flash attention | --flash_attn |
| Colocation | --colocate_actor_ref, --colocate_critic_reward |
| Dynamic sampling | Built-in to improve sample efficiency |
OpenRLHF vs verl vs ART
| Aspect | OpenRLHF | verl | ART |
|---|
| Foundation | Ray + DeepSpeed + vLLM | HybridFlow + FSDP/Megatron | Client/server + Unsloth |
| Strength | RLHF production, algorithmes variés | Débit + flexibilité | Agents dans ton propre code |
| Multimodal | VLM RLHF (OpenRLHF-M) | Supported | Text-focused |
| Best for | Pipelines RLHF évolutifs | Débit de recherche | Single-agent on-the-job RL |
Ressources