RL Training Module
AITraining includes a comprehensive reinforcement learning module for advanced LLM training scenarios.The CLI commands (
--trainer ppo, --trainer grpo, --trainer dpo, --trainer reward) use TRL library implementations for stability. The autotrain.trainers.rl module documented here provides lower-level building blocks for custom RL training pipelines.Overview
The RL module provides:- PPO Trainer - Proximal Policy Optimization with KL penalty and GAE
- DPO Trainer - Direct Preference Optimization from preference data
- Reward Models - Standard, pairwise, and multi-objective reward models
- RL Environments - Text generation, math, code, and preference comparison environments
- Async Pipeline - Forward-backward training with gradient accumulation
PPO Training
Configuration
PPO Architecture
The PPO implementation uses aPPOModel wrapper that adds a value head to any causal LM:
Adaptive KL Controller
TheAdaptiveKLController automatically adjusts the KL penalty coefficient to keep KL divergence near the target:
Training Loop
Key Features
DPO Training
Train directly from preference data without a separate reward model.Configuration
Preference Dataset
PreferenceDataset must be imported directly from autotrain.trainers.rl.dpo as it’s not exported in the main __init__.py.Reference-Free DPO
For training without a reference model:Reward Models
Standard Reward Model
Training on Preferences
Pairwise Reward Model
For direct preference comparison using Bradley-Terry model:Multi-Objective Reward Model
Combine multiple reward signals:RL Environments
Environment Dataclasses
Text Generation Environment
Multi-Objective Environment
Preference Comparison Environment
For RLHF and DPO data collection:Built-in Environments
Forward-Backward Pipeline
Async training with gradient accumulation:Built-in Loss Functions
The pipeline supports several built-in loss functions:Custom Loss Functions
High-Level Client
AsyncTrainingClient must be imported directly from autotrain.trainers.rl.forward_backward as it’s not exported in the main __init__.py.Checkpointing
Sampling
Generate samples during training:Best Practices
PPO Training
- Start with small KL coefficient - Let the adaptive controller adjust
- Use gradient accumulation - Larger effective batch sizes are more stable
- Monitor KL divergence - Should stay close to target
- Warm up the value function - Train critic before full PPO
DPO Training
- High-quality preference data - Quality matters more than quantity
- Low learning rate - 1e-6 to 1e-5 recommended
- Label smoothing - 0.1 can improve robustness
- Evaluate frequently - Track accuracy and reward margin
Reward Modeling
- Balanced data - Equal chosen/rejected examples
- Diverse prompts - Cover expected use cases
- LoRA for efficiency - Fine-tune large models efficiently
- Multi-objective - Separate safety and helpfulness signals
CLI Integration
For production use, the CLI provides simpler interfaces using TRL implementations:Next Steps
PPO Training
CLI guide for PPO
GRPO Training
RL with custom environments
DPO Training
CLI guide for DPO
Reward Modeling
Train reward models
ORPO Training
Odds Ratio Preference Optimization