Simple Post-Training Pipeline Documentation — SFT with VERL + Docker
This document outlines the complete workflow for using the Simple Post-Training package with VERL and Docker.
I. Installation and Environment Setup
Follow these steps to set up your environment for training and evaluation:
1.1 Create Conda Environment
Create a new conda environment specifically for training:
conda create -n _train python=3.10
conda activate _train1.2 Install Required Packages
Install the packages from requirements.txt:
# Install PyTorch
pip3 install torch torchvision
# Install main dependencies
pip install wandb swanlab huggingface matplotlib seaborn jupyterlab scipy1.3 Install Faith Evaluation Framework
Install the faith evaluation framework locally with VLLM support:
cd evaluation_frameworks/faith
pip install -e '.[vllm]'
cd ../..1.4 Setup Environment Variables
Create and configure your environment variables:
- Copy the example environment file:
cp .env.example .env- Edit the
.envfile with your specific configurations:
# Open .env in your preferred editor and set:
# REQUIRED - Set these to your actual paths:
export PROJECT_ROOT=/path/to/simple-post-training # Your project root directory
export STORAGE_ROOT=/path/to/storage-folder # Where data, models, and containers will be stored
# Set your API keys (as needed):
export HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxx # HuggingFace token
export WANDB_API_KEY=your_wandb_api_key_here # Weights & Biases API key
export SWANLAB_API_KEY=your_swanlab_api_key_here # SwanLab API key (alternative to WandB)
# Optional - for notifications:
export TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
export TELEGRAM_CHAT_ID=your_telegram_chat_id_here
export SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL- Source the environment file:
source .envImportant: The PROJECT_ROOT and STORAGE_ROOT variables are critical for the pipeline to function correctly. All data, models, and container folders will be created under STORAGE_ROOT.
1.5 Create Directory Structure
Create the necessary folder structure in your STORAGE_ROOT:
# Create container folder for Docker images
mkdir -p $STORAGE_ROOT/container
# Create data directories
mkdir -p $STORAGE_ROOT/data/raw # For raw data downloaded from Google Cloud or Hugging Face
mkdir -p $STORAGE_ROOT/data/processed # For processed data used for training
# Create model directories
mkdir -p $STORAGE_ROOT/models/base # For base models downloaded from Hugging Face or Google Cloud
mkdir -p $STORAGE_ROOT/models/checkpoints # For model checkpoints generated during trainingDirectory Structure Purpose:
- $STORAGE_ROOT/container: Store Docker images for VERL and other containers
- $STORAGE_ROOT/data/raw: Store raw datasets downloaded from Google Cloud or Hugging Face
- $STORAGE_ROOT/data/processed: Store processed and formatted data ready for training
- $STORAGE_ROOT/models/base: Store pre-trained base models downloaded from Hugging Face or Google Cloud
- $STORAGE_ROOT/models/checkpoints: Store model checkpoints generated during the training process
II. Authentication Setup (Ignore if you have done them already)
Configure authentication for the services you’ll be using:
2.1 GitHub Authentication
Set up GitHub access for cloning repositories and accessing private repos:
# Configure git with your credentials
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
# For private repositories, set up SSH key or personal access token
# Option 1: SSH Key (recommended)
# ssh-keygen -t ed25519 -C "your.email@example.com"
# Add the public key to your GitHub account: https://github.com/settings/keys
# Option 2: Personal Access Token
# Create a token at: https://github.com/settings/tokens
# Use the token when prompted for password during git operations2.2 Google Cloud Authentication
If using Google Cloud Storage for data or model storage:
# Install gcloud CLI if not already installed
# Follow instructions at: https://cloud.google.com/sdk/docs/install
# Authenticate with Google Cloud
gcloud auth login
# Set up your project
gcloud config set project YOUR_PROJECT_ID
# Set up your default region (e.g., us-central1, europe-west1, asia-southeast1)
gcloud config set compute/region YOUR_REGION
# Set up application default credentials
gcloud auth application-default login
# If using service account (recommended for production):
# 1. Create service account and download JSON key from Google Cloud Console
# 2. Set the path in your .env file:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/gcs_credentials.json2.3 HuggingFace Authentication
Set up HuggingFace access for downloading models and datasets:
# Login to HuggingFace CLI
huggingface-cli login
# Enter your HF token when prompted (get it from https://huggingface.co/settings/tokens)
# Alternatively, the token is already set in your .env file:
# export HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxx
# Verify authentication
hf auth whoami2.4 Weights & Biases or SwanLab Authentication
For experiment tracking, the API keys for Weights & Biases (WANDB_API_KEY) or SwanLab (SWANLAB_API_KEY) are automatically configured when you source the .env file. No additional setup is required.
2.5 Telegram Notifications (Optional)
Telegram bot tokens and chat IDs (TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID) are automatically configured when you source the .env file. To use notifications, simply ensure you’ve created a bot via @BotFather on Telegram and added the credentials to your .env file.
III. Download VERL Docker Image and Setup Training Framework
3.1 Configure Docker Access
Before downloading Docker images, ensure your user has proper Docker permissions:
# Add your user to the docker group
sudo usermod -aG docker $USER
# Apply the group changes without logging out
newgrp docker
# Verify Docker access
docker psNote: If you still get permission errors, you may need to logout and login again for the group changes to take full effect.
3.2 Download VERL Docker Image
Download the VERL Docker image to your storage directory:
# Download the VERL docker image
wo
# This downloads: hiyouga/verl:ngc-th2.6.0-cu126-vllm0.8.4-flashinfer0.2.2-cxx11abi0The script will:
- Pull the Docker image from the registry
- Save it as a
.tarfile in$STORAGE_ROOT/container/ - Create the following structure:
$STORAGE_ROOT/container/ ├── verl_ngc-th2.6.0-cu126-vllm0.8.4-flashinfer0.2.2-cxx11abi0.tar └── verl_ngc-th2.6.0-cu126-vllm0.8.4-flashinfer0.2.2-cxx11abi0.info
3.3 Start Docker Container
Start the VERL Docker container in background mode:
# Start the Docker container with VERL framework
./scripts/containers/start_docker.sh verl sft
# This will:
# - Start a container named 'training_sft' running in background
# - Mount all necessary directories from $STORAGE_ROOT and $PROJECT_ROOT
# - Configure GPU access and environment variables
# - Keep the container running persistentlyThe container runs in the background and will automatically restart if the system reboots.
3.4 Install VERL Framework Inside Container
Connect to the running container and install VERL with VLLM support:
# Attach to the running container
docker exec -it training_sft bash
# Inside the container, navigate to VERL directory
cd /workspace/training_frameworks/verl
# Install VERL with VLLM support
pip3 install -e .[vllm]
# Verify installation (still inside container)
python -c "import verl; print('VERL installed successfully')"
# Install additional packages as needed
# For visualization and plotting:
pip install matplotlib seaborn
# For experiment tracking with SwanLab (alternative to WandB):
pip install swanlab
# Other useful packages you might need:
# pip install pandas numpy scipy
# pip install jupyter notebook ipython
# pip install tensorboard
# Exit the container (but it keeps running)
exitThe container includes:
- VERL training framework with VLLM 0.8.4
- FlashInfer 0.2.2 for optimized attention
- PyTorch 2.6.0 with CUDA 12.6
- All necessary dependencies pre-installed
Note on Package Installation:
- Packages installed inside the Docker container persist as long as the container is running
- If you stop and remove the container, you’ll need to reinstall additional packages
- To make package installations permanent, consider creating a custom Docker image or using a requirements file
- For production use, it’s recommended to build a custom image with all required packages
Container Management Commands:
- Attach to container:
docker exec -it training_sft bash - View logs:
docker logs -f training_sft - Stop container:
docker stop training_sft - Check status:
docker ps | grep training_sft
IV. Download Datasets and Models
4.1 Configure Download Resources
Before downloading, you need to configure what resources to download by editing the download script:
# Exit from Docker container if you're still inside
exit
# Edit the download script to specify your models and datasets
nano scripts/support/download_resources.shThe script is configured to download:
HuggingFace Models:
meta-llama/Llama-3.1-8B-Instruct(requires HF_TOKEN)allenai/Llama-3.1-Tulu-3-8B-RMfdtn-ai/Foundation-Sec-8B
HuggingFace Datasets:
allenai/tulu-3-sft-mixtureallenai/llama-3.1-tulu-3-8b-preference-mixtureOpen-Orca/OpenOrca
Google Cloud Storage Resources:
- Synthetic training data from
gs://ri-minerva/instruction_tuning_datasets/ - Fine-tuned model checkpoint from
gs://ri-minerva/instruction-tuning/checkpoints/
Edit the arrays in the script (lines ~145-181) to add or remove resources as needed.
4.2 Download Resources
Run the download script to fetch all configured resources:
# Dry run to see what will be downloaded
./scripts/support/download_resources.sh
# Actually download the resources
./scripts/support/download_resources.sh --downloadThe script will:
- Download models to
$STORAGE_ROOT/models/base/ - Download datasets to
$STORAGE_ROOT/data/raw/ - Skip any resources that already exist locally
- Show progress for each download
4.3 Verify Downloads
After downloading, verify the resources:
# Check downloaded models
ls -la $STORAGE_ROOT/models/base/
# Check downloaded datasets
ls -la $STORAGE_ROOT/data/raw/
# Check disk usage
du -sh $STORAGE_ROOT/models/base/*
du -sh $STORAGE_ROOT/data/raw/*Expected Directory Structure:
$STORAGE_ROOT/
├── models/
│ └── base/
│ ├── meta-llama_Llama-3.1-8B-Instruct/
│ ├── allenai_Llama-3.1-Tulu-3-8B-RM/
│ ├── fdtn-ai_Foundation-Sec-8B/
│ └── minerva_sft/
└── data/
└── raw/
├── allenai_tulu-3-sft-mixture/
├── allenai_llama-3.1-tulu-3-8b-preference-mixture/
├── Open-Orca_OpenOrca/
└── zhuoran_synthetic_data/
Note:
- Gated models like Llama require HF_TOKEN to be set in your
.envfile - GCS downloads require Google Cloud authentication (done in Step II)
- Large datasets may take significant time to download
V. Process Data for SFT Training
Data processing can be done either inside Docker or in your conda environment. This step prepares and aggregates datasets for training.
5.1 Configure Dataset Selection
Edit the configuration file to specify which datasets to use:
# Edit the source configuration
nano trainers/sft_verl/configs/source_configs.yamlIn the dataset_name section, uncomment or add the datasets you want to include:
dataset_name:
- zhuoran_synthetic_simpleqa
- zhuoran_synthetic_cvss_pred
- zhuoran_synthetic_cwe_pred
- allenai/tulu-3-sft-mixture
- Open-Orca/OpenOrca
# Add more datasets as needed5.2 Configure Data Processors
Each dataset needs a corresponding data processor. The mapping is defined in:
# Check dataset-to-processor mapping
cat trainers/sft_verl/config_files/dataset_module_map.jsonFor new datasets, you need to:
- Add an entry in
dataset_module_map.json - Create a corresponding processor file in
trainers/sft_verl/data_processors/
5.3 Set Sample Size
Control how many data points from each dataset to include by setting the sample size in each processor:
# In each data processor file (e.g., data_processors/tulu_sft.py):
SAMPLE_SIZE = int(os.getenv("SAMPLE_SIZE", 2000)) # Default 2000 samplesYou can override this globally:
export SAMPLE_SIZE=5000 # Use 5000 samples from each dataset5.4 Generate Training Data
Run the data preparation script to aggregate and split the data:
# Run data preparation in background
./scripts/experiments/verl_sft_prepare.sh > sft_data_gen.log 2>&1 &
# Monitor progress
tail -f sft_data_gen.log
# Check if process is running
ps aux | grep verl_sft_prepareThis script will:
- Load datasets from
$STORAGE_ROOT/data/raw/ - Process each dataset using its corresponding processor
- Sample the specified number of data points
- Aggregate all datasets into a single training corpus
- Split into training (99%) and validation (1%) sets
- Save processed data to
$STORAGE_ROOT/data/processed/
5.5 Verify Processed Data
After processing completes, verify the output:
# Check processed data directory
ls -la $STORAGE_ROOT/data/processed/
# Check the generated files
ls -la $STORAGE_ROOT/data/processed/sft_train_data/
# Count number of samples
wc -l $STORAGE_ROOT/data/processed/sft_train_data/train.jsonl
wc -l $STORAGE_ROOT/data/processed/sft_train_data/val.jsonl
# Preview a few samples
head -n 2 $STORAGE_ROOT/data/processed/sft_train_data/train.jsonl | jq .Expected Output Structure:
$STORAGE_ROOT/data/processed/
└── sft_train_data/
├── train.jsonl # Training split (99%)
├── val.jsonl # Validation split (1%)
└── metadata.json # Dataset statistics
Example Output from Data Processing:
==========================================
📊 Dataset Composition Summary
==========================================
zhuoran_synthetic_simpleqa: 200,000 samples (50.0%)
zhuoran_synthetic_cvss_pred: 50,000 samples (12.5%)
zhuoran_synthetic_cwe_pred: 50,000 samples (12.5%)
allenai/tulu-3-sft-mixture: 50,000 samples (12.5%)
Open-Orca/OpenOrca: 50,000 samples (12.5%)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✓ Total Training Samples: 379,999
✓ Total Validation Samples: 20,001
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Tips:
- Adjust
SAMPLE_SIZEbased on your compute resources and training time - For debugging, use smaller sample sizes (e.g., 100-500)
- The train_split ratio (99/1) can be adjusted in
source_configs.yaml - Check
sft_data_gen.logfor any processing errors
VI. Run SFT Training with VERL
6.1 Configure Training Hyperparameters
Edit the training script to set your hyperparameters:
# Edit the training script
nano scripts/experiments/verl_sft_train.shKey hyperparameters to configure:
# GPU Configuration
export NUM_GPUS=8 # Number of GPUs to use
export CUDA_VISIBLE_DEVICES="0,1,2,3,4,5,6,7" # Specific GPU IDs
# Batch Size Configuration
export MICRO_BATCH_SIZE_PER_GPU=2 # Batch size per GPU
export GLOBAL_BATCH_SIZE=128 # Total batch size across all GPUs
export GRADIENT_ACCUMULATION_STEPS=8 # Steps to accumulate gradients
# Learning Rate
export LEARNING_RATE=5e-6 # Initial learning rate
export LR_SCHEDULER="cosine" # Learning rate scheduler
# Training Steps and Checkpointing
export MAX_STEPS=4500 # Total training steps (based on data size)
export EVAL_STEPS=500 # Evaluate every N steps
export SAVE_STEPS=500 # Save checkpoint every N steps
export SAVE_TOTAL_LIMIT=5 # Keep only last N checkpoints
# Logging
export LOGGING_STEPS=10 # Log metrics every N steps
export PROJECT_NAME="sft_training" # Project name for tracking
export JOB_NAME="llama3_8b_$(date +%Y%m%d_%H%M%S)" # Unique job name6.2 Calculate Training Steps
The script will output total training steps based on your data:
Total training steps: 4452
Use this to determine checkpoint frequency:
- For ~4500 steps: Save every 500 steps = ~9 checkpoints
- Set
SAVE_TOTAL_LIMITto keep only the best/recent ones
6.3 Launch Training
Start the training inside the Docker container:
# Attach to the running container
docker exec -it training_sft bash
# Navigate to workspace
cd /workspace
# Launch training
./scripts/experiments/verl_sft_train.sh
# Or run in background with logging
nohup ./scripts/experiments/verl_sft_train.sh > training.log 2>&1 &
# Monitor training progress
tail -f training.log6.4 Monitor Training
Training logs and checkpoints will be saved to:
# Training logs location
$STORAGE_ROOT/models/checkpoints/{PROJECT_NAME}/{JOB_NAME}/training.log
# Monitor from outside Docker
tail -f $STORAGE_ROOT/models/checkpoints/sft_training/*/training.log
# Check GPU utilization
nvidia-smi -l 1
# Monitor with WandB or SwanLab (if configured)
# Check your dashboard at https://wandb.ai or SwanLab interface6.5 Training Output Structure
$STORAGE_ROOT/models/checkpoints/
└── {PROJECT_NAME}/
└── {JOB_NAME}/
├── training.log # Main training log
├── checkpoint-500/ # Checkpoint at step 500
│ ├── model.safetensors
│ ├── optimizer.pt
│ └── training_state.json
├── checkpoint-1000/ # Checkpoint at step 1000
├── checkpoint-1500/
└── final_model/ # Final trained model
├── config.json
├── model.safetensors
└── tokenizer_config.json
6.6 Resume Training (if interrupted)
If training is interrupted, resume from checkpoint:
# Find latest checkpoint
LATEST_CHECKPOINT=$(ls -td $STORAGE_ROOT/models/checkpoints/{PROJECT_NAME}/{JOB_NAME}/checkpoint-* | head -1)
# Resume training
export RESUME_FROM_CHECKPOINT=$LATEST_CHECKPOINT
./scripts/experiments/verl_sft_train.shTraining Tips:
- Start with smaller
MAX_STEPS(e.g., 100) for testing - Monitor loss convergence in the first 500 steps
- Adjust learning rate if loss doesn’t decrease
- Use gradient accumulation for larger effective batch sizes with limited GPUs
- Save checkpoints frequently early in training, less frequently later
- Keep training logs for debugging and analysis