| Evolution of OOD Reasoning Performance for SFT+RL | Advantage Distribution in PPO at Different Checkpoints |
|---|---|
![]() |
![]() |
This repository provides a comprehensive framework for training Large Language Models (LLMs) using both Supervised Fine-Tuning (SFT) and Reinforcement Learning (RL) approaches. The framework supports both LLaMA and Qwen model families and includes evaluation pipelines for various tasks.
Before using this repository, you MUST replace all /path placeholders with your actual paths:
- Replace
/path/to/condawith your conda installation path - Replace
/path/to/cudawith your CUDA installation path - Replace
/path/to/datawith your dataset directory path - Replace
/path/to/modelwith your model checkpoint directory - Update email addresses in SLURM scripts from
xxx@email.comto your email - Set proper WANDB API keys in scripts (currently set to placeholder values)
- Installation
- Repository Structure
- Quick Start
- Supervised Fine-Tuning (SFT)
- Reinforcement Learning Training
- Evaluation
- Configuration
- Scripts Overview
- Troubleshooting
- Python 3.13
- CUDA-compatible GPU
- Conda or virtual environment manager
- Clone the repository:
git clone https://github.com/xiaodanguoguo/RL_Heals_SFT.git
cd RL_Heals_SFT- Install dependencies:
pip install -r requirements.txt- Install the gym environment:
cd gym
pip install -e .
cd ..- Set up environment variables:
export PYTHONPATH=/path/to/your/RL_Heals_SFT:$PYTHONPATH
export WANDB_API_KEY="your_wandb_key"RL_Heals_SFT/
βββ sft/ # Supervised Fine-Tuning modules
β βββ src/ # Core SFT implementation
β βββ sft_scripts/ # SFT training scripts
βββ rl/ # Reinforcement Learning modules
β βββ configs/ # RL configuration files
β βββ trainer/ # RL trainers (PPO, etc.)
β βββ launcher.py # RL training launcher
βββ evaluation/ # Evaluation framework
β βββ evaluator/ # Model evaluators
β βββ configs/ # Evaluation configurations
βββ gym/ # Custom gym environments
β βββ gym_cards/ # Card game environments
βββ scripts/ # Training and evaluation scripts
β βββ gp_training/ # General purpose training
β βββ gp_evaluation/ # General purpose evaluation
β βββ virl_training/ # VIRL-specific training
βββ analysis/ # Analysis and visualization tools
βββ virl/ # VIRL-specific modules
βββ utils_*.py # Utility functions
Ensure your datasets are in the correct format and update paths in configuration files:
# Update data paths in configuration files
# Example: rl/configs/llama_gp_language.yaml
# Example: evaluation/configs/llama_gp_language.yamlCritical Step: Update all hardcoded paths in the following files:
# Scripts with hardcoded paths that need updating:
scripts/gp_training/language_train-qwen.sh
scripts/gp_evaluation/language_ood_dir_eval_recover-batch.sh
analysis/angle_acm.sh
# SFT Training (Llama)
cd sft/sft_scripts
bash gp_l.sh
# RL Training (Llama)
cd scripts/gp_training
bash language_train.sh
# Evaluation
cd scripts/gp_evaluation
bash language_indist_eval.shSFT configurations are defined in sft/src/training/params.py and can be customized via command-line arguments.
Located in sft/sft_scripts/:
gp_l.sh- General purpose Llama SFTgp_l-qwen.sh- General purpose Qwen SFTgp_l-8.sh- 8-GPU Llama trainingvirl_l.sh- VIRL Llama SFTvirl_l-qwen.sh- VIRL Qwen SFT
cd sft/sft_scripts
# Edit the script to update paths:
# - Update conda environment path
# - Update CUDA paths if needed
# - Set proper data paths
# - Configure output directories
# Run training
bash gp_l.sh--model_name_or_path: Base model path--data_path: Training data directory--output_dir: Output directory for checkpoints--learning_rate: Learning rate (default: 1e-5)--num_train_epochs: Number of training epochs--per_device_train_batch_size: Batch size per device
The RL framework uses Proximal Policy Optimization (PPO) for training.
Located in rl/configs/:
llama_gp_language.yaml- Llama general purpose configllama_gp_language-qwen.yaml- Qwen general purpose configllama_virl_language.yaml- Llama VIRL configllama_virl_language-qwen.yaml- Qwen VIRL config
Located in scripts/gp_training/ and scripts/virl_training/:
# Llama RL training
bash scripts/gp_training/language_train.sh
# Qwen RL training
bash scripts/gp_training/language_train-qwen.sh
# Multi-GPU training
bash scripts/gp_training/language_train-8.sh--model_name: Model identifier--config_file: Configuration file path--num_episodes: Number of RL episodes--learning_rate: PPO learning rate--ppo_epochs: PPO update epochs per rollout
The evaluation system supports multiple evaluators:
LlamaEvaluator- For Llama modelsQwenEvaluator- For Qwen models- Custom evaluators for specific tasks
Located in scripts/gp_evaluation/:
# In-distribution evaluation
bash language_indist_eval.sh
# Out-of-distribution evaluation
bash language_ood_eval.sh
# Batch evaluation
bash run_batch_eval.shcd evaluation
# Configure evaluation settings in run_eval.py
# Update model paths and data paths
# Run evaluation
python run_eval.py \
--model_path /path/to/your/model \
--config_path configs/llama_gp_language.yaml \
--output_dir results/Set these before running any scripts:
export PYTHONPATH=/path/to/RL_Heals_SFT:$PYTHONPATH
export WANDB_API_KEY="your_actual_wandb_key"
export CUDA_VISIBLE_DEVICES="0,1,2,3" # Adjust for your setupMost scripts include SLURM headers. Update the following in each script:
#SBATCH --mail-user=your_email@institution.edu # Replace xxx@email.com
#SBATCH --account=your_account
#SBATCH --partition=your_partitionUpdate model paths in configuration files:
# Example: rl/configs/llama_gp_language.yaml
model_name: "/path/to/your/llama/model"
tokenizer_name: "/path/to/your/llama/tokenizer"| Script | Purpose | Model | Notes |
|---|---|---|---|
sft/sft_scripts/gp_l.sh |
SFT training | Llama | General purpose |
sft/sft_scripts/gp_l-qwen.sh |
SFT training | Qwen | General purpose |
scripts/gp_training/language_train.sh |
RL training | Llama | PPO-based |
scripts/gp_training/language_train-qwen.sh |
RL training | Qwen | PPO-based |
| Script | Purpose | Task Type |
|---|---|---|
scripts/gp_evaluation/language_indist_eval.sh |
In-distribution eval | Language tasks |
scripts/gp_evaluation/language_ood_eval.sh |
Out-of-distribution eval | Language tasks |
evaluation/run_eval.py |
General evaluation | Configurable |
| Script | Purpose |
|---|---|
analysis/svd-recover.sh |
SVD-based model analysis |
analysis/angle_acm.sh |
Angle analysis for ACM |
- Path Errors: Ensure all
/pathplaceholders are replaced with actual paths - CUDA Errors: Verify CUDA installation and GPU availability
- Import Errors: Check PYTHONPATH is set correctly
- Permission Errors: Ensure proper file permissions for scripts
Before running any scripts, verify these paths are updated:
- Conda environment paths in shell scripts
- CUDA installation paths
- Data directory paths
- Model checkpoint paths
- Output directory paths
- PYTHONPATH exports
- Email addresses in SLURM scripts
- WANDB API keys
Enable debug logging:
export WANDB_MODE=offline # For offline debugging
export TRANSFORMERS_VERBOSITY=debugFor large models, consider:
- Using DeepSpeed configuration files in
scripts/ - Reducing batch sizes
- Using gradient checkpointing
- Model parallelism across multiple GPUs
If you use this code in your research, please cite:
@misc{jin2025rlfinetuninghealsood,
title={RL Fine-Tuning Heals OOD Forgetting in SFT},
author={Hangzhan Jin and Sitao Luan and Sicheng Lyu and Guillaume Rabusseau and Reihaneh Rabbany and Doina Precup and Mohammad Hamdaqa},
year={2025},
eprint={2509.12235},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2509.12235},
}This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
For issues and questions:
- Check the troubleshooting section above
- Review configuration files for path issues
- Ensure all dependencies are installed correctly
- Open an issue with detailed error messages and system information
/path references and configuration parameters before use.

