This guide provides step-by-step instructions for setting up the environment, running PPO training, evaluating models, and generating plots.
- Prerequisites
- Environment Setup
- Starting the Reward Model Server
- Running Training
- Running Evaluation
- Generating Plots
- Conda (or Miniconda) installed
- CUDA-capable GPU(s) with sufficient memory (recommended: 8+ GPUs for training)
- Python 3.8+
# Create a new conda environment with Python 3.10
conda create -n trl python=3.10 -y
# Activate the environment
conda activate trlNavigate to the repository root and install all requirements:
# Navigate to the repository root (where requirements.txt is located)
cd /path/to/trl
# Install all dependencies from requirements.txt
pip install -r requirements.txtNote: The installation may take several minutes, especially for packages like flash-attn and deepspeed. Make sure you have CUDA properly installed for GPU support.
# Check that key packages are installed
python -c "import torch; print(f'PyTorch: {torch.__version__}')"
python -c "import transformers; print(f'Transformers: {transformers.__version__}')"
python -c "import trl; print(f'TRL: {trl.__version__}')"
python -c "from accelerate import Accelerator; print('Accelerate: OK')"The reward model server is part of the MisleadLM repository, which is a fork from the original paper "Language Models Learn to Mislead Humans via RLHF".
Option 1: Use Pre-trained Reward Model (Recommended)
You can use a pre-trained reward model from Hugging Face instead of training your own. The reward model checkpoint is available at: basebala/reward-model-checkpoint-qa
Start the reward model server from the MisleadLM repository:
# Navigate to the MisleadLM folder
cd /path/to/MisleadLM
# Start the reward model server (configure it to use the pre-trained model)
bash reward_model_general_server.shOption 2: Train Your Own Reward Model
If you prefer to train your own reward model, you can do so and then start the server with your custom checkpoint.
Important:
- The reward model server must be running on
http://localhost:8115/rewardbefore starting training - Keep the server running in a separate terminal during training
- The training script will send prompts to this server to get reward scores
Navigate to the PPO scripts directory:
cd examples/scripts/ppoUse the accelerate launch command format shown in ppo_testing_v2.py. The file contains example commands at the top - use those as a reference and modify the arguments as needed for your setup.
Example format (see ppo_testing_v2.py for full details):
accelerate launch --config_file examples/accelerate_configs/deepspeed_zero2.yaml \
ppo_testing_v2.py \
--output_dir ./models/ppo_output \
--learning_rate 1.0e-5 \
--per_device_train_batch_size 1 \
--gradient_accumulation_steps 8 \
--total_episodes 30000 \
--save_strategy steps \
--save_steps 100 \
--eval_strategy steps \
--eval_steps 100Key Training Arguments:
--output_dir: Directory to save checkpoints and logs--learning_rate: Learning rate (default: 1.0e-5)--per_device_train_batch_size: Batch size per GPU (default: 1)--gradient_accumulation_steps: Number of steps to accumulate gradients (default: 8)--total_episodes: Total number of training episodes--save_strategy: When to save checkpoints (steps,epoch, orno)--save_steps: Save checkpoint every N steps--eval_strategy: When to run evaluation (steps,epoch, orno)--eval_steps: Run evaluation every N steps
Note: The training script uses the SFT checkpoint as the base model. The SFT checkpoint is available on Hugging Face: basebala/llama-3.1-8b-sft-checkpoint-80
Training progress is automatically logged to:
- Console output: Real-time metrics and QA accuracy
- Weights & Biases (if configured): Training curves and metrics
- Checkpoint directories: Model checkpoints saved at specified intervals
Use the provided evaluation script:
bash run_evaluation.shEdit run_evaluation.sh to customize:
--model_path: Path to your trained PPO checkpoint--base_model_path: Path to the base model (SFT checkpoint available at basebala/llama-3.1-8b-sft-checkpoint-80)--val_data_path: Path to validation QA dataset JSON file--batch_size: Batch size per GPU (adjust based on GPU memory)- Other evaluation parameters as needed
The script uses accelerate launch for multi-GPU evaluation, which significantly speeds up evaluation on large validation sets.
Generate comparison plots from evaluation results or W&B runs:
python plot_accuracy_comparison.py \
--results_file evaluation_results.json \
--output_file accuracy_comparison.pngIf you logged results to W&B:
python plot_accuracy_comparison.py \
--wandb_project your-project-name \
--wandb_runs run1 run2 run3 \
--output_file comparison.png--results_file: Path to evaluation results JSON file--wandb_project: W&B project name (if using W&B)--wandb_runs: List of W&B run names to compare--output_file: Output path for the plot image
- TRL Documentation: https://huggingface.co/docs/trl
- Accelerate Documentation: https://huggingface.co/docs/accelerate
- Performance Guide: See
PERFORMANCE_GUIDE.mdfor optimization tips - Evaluation Guide: See
EVALUATION_README.mdfor detailed evaluation instructions