Aller au contenu

OpenRLHF Cheatsheet

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

MethodCommand
pippip install openrlhf
With vLLM extraspip install openrlhf[vllm]
From sourcegit clone https://github.com/OpenRLHF/OpenRLHF && cd OpenRLHF && pip install -e .
Dockeruse the project’s reference image (CUDA + deps preinstalled)
RequirementsNVIDIA GPU(s), CUDA, Ray, DeepSpeed, vLLM

Architecture

ComponentRole
ActorLe modèle de politique en cours d’entraînement
CriticModèle de valeur (PPO)
Reward modelÉvalue les réponses générées
Reference modelBaseline gelée pour la pénalité KL
RayPlanifie et place ces modèles sur les GPUs
vLLM engineAccé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.

CommandPurpose
openrlhf.cli.train_sftSupervised fine-tuning
openrlhf.cli.train_rmReward model training
openrlhf.cli.train_ppoPPO (single-controller)
openrlhf.cli.train_ppo_rayPPO/GRPO distributed with Ray + vLLM
openrlhf.cli.train_dpoDirect 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
FlagControls
--pretrainBase/actor model
--reward_pretrainReward model path
--advantage_estimator group_normSelects GRPO-style group normalization
--vllm_num_enginesNumber of vLLM rollout engines
--actor_num_gpus_per_nodeGPU allocation for the actor
--colocate_actor_refPlace actor + reference together to save GPUs

Algorithmes

AlgorithmFlag/Module
PPOdefault in train_ppo*
GRPO--advantage_estimator group_norm
REINFORCE++--advantage_estimator reinforce family
RLOO--advantage_estimator rloo
DPO / KTOdedicated train_dpo / train_kto modules

Mise à l’Échelle & Performance

TechniqueFlag/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 samplingBuilt-in to improve sample efficiency

OpenRLHF vs verl vs ART

AspectOpenRLHFverlART
FoundationRay + DeepSpeed + vLLMHybridFlow + FSDP/MegatronClient/server + Unsloth
StrengthRLHF production, algorithmes variésDébit + flexibilitéAgents dans ton propre code
MultimodalVLM RLHF (OpenRLHF-M)SupportedText-focused
Best forPipelines RLHF évolutifsDébit de rechercheSingle-agent on-the-job RL

Ressources