Skip to main content

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 a PPOModel wrapper that adds a value head to any causal LM:

Adaptive KL Controller

The AdaptiveKLController 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

  1. Start with small KL coefficient - Let the adaptive controller adjust
  2. Use gradient accumulation - Larger effective batch sizes are more stable
  3. Monitor KL divergence - Should stay close to target
  4. Warm up the value function - Train critic before full PPO

DPO Training

  1. High-quality preference data - Quality matters more than quantity
  2. Low learning rate - 1e-6 to 1e-5 recommended
  3. Label smoothing - 0.1 can improve robustness
  4. Evaluate frequently - Track accuracy and reward margin

Reward Modeling

  1. Balanced data - Equal chosen/rejected examples
  2. Diverse prompts - Cover expected use cases
  3. LoRA for efficiency - Fine-tune large models efficiently
  4. 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