Skip to main content

LLM Training

The aitraining llm command trains large language models with support for multiple trainers and techniques.

Quick Start

Available Trainers

generic is an alias for default. All three (default, sft, generic) produce the same behavior.
PPO Trainer Requirements: PPO requires either --rl-reward-model-path (path to a trained reward model) or --model-ref (reference model for KL divergence). See PPO Training for full documentation.
GRPO Trainer Requirements: GRPO requires --rl-env-module (Python module path) and --rl-env-class (class name) for the custom environment. See GRPO Training for full documentation.

Parameter Groups

Parameters are organized into logical groups:

Basic Parameters

Always specify these parameters: While --model, --data-path, and --project-name have defaults, you should always explicitly set them for your use case. The --project-name parameter sets the output folder - use a path like --project-name ./models/my-experiment to control where the trained model is saved.

Training Configuration

Checkpointing & Evaluation

Performance & Memory

Unsloth Requirements: Unsloth only works with sft/default trainers and specific model architectures (llama, mistral, gemma, qwen2). See Unsloth Integration for details.

Backend & Distribution

Multi-GPU Behavior: With multiple GPUs and --distributed-backend not set, DDP is used automatically. Set --distributed-backend deepspeed for DeepSpeed Zero-3 optimization. Training is launched via Accelerate.
DeepSpeed Checkpointing: When using DeepSpeed, model saving uses accelerator.get_state_dict() and unwraps the model. PEFT adapter saving is handled differently under DeepSpeed.

PEFT/LoRA Parameters

Data Processing

Chat Template Auto-Selection: SFT/DPO/ORPO/Reward trainers default to tokenizer (model’s built-in template). Use --chat-template none for plain text training.
Processed Data Saving: By default (auto), processed data is saved locally to {project}/data_processed/. If the source dataset was from the Hub, it’s also pushed as a private dataset. Original columns are renamed to _original_* to prevent conflicts.

Training Examples

SFT with LoRA

DPO Training

For DPO, you must specify the column names for prompt, chosen, and rejected responses:
DPO and ORPO require --prompt-text-column and --rejected-text-column to be specified.

ORPO Training

ORPO combines SFT and preference optimization:

GRPO Training

Train with Group Relative Policy Optimization using your own reward environment:
GRPO generates multiple completions per prompt, scores them via your environment (0-1), and optimizes the policy. See GRPO Training for environment interface details.

Knowledge Distillation

Train a smaller model to mimic a larger one:
Distillation defaults: --distill-temperature 3.0, --distill-alpha 0.7, --distill-max-teacher-length 512

Logging & Monitoring

Weights & Biases (Default)

W&B logging with LEET visualizer is enabled by default. The LEET visualizer shows real-time training metrics directly in your terminal.
To disable W&B or the visualizer:

TensorBoard

Push to Hugging Face Hub

Upload your trained model:
The repository is created as private by default. By default, the repo will be named {username}/{project-name}.

Custom Repository Name or Organization

Use --repo-id to push to a specific repository, useful for:
  • Pushing to an organization instead of your personal account
  • Using a different repo name than your local project-name
When using --repo-id, you don’t need --username since the repo ID already specifies the destination. However, you still need --token for authentication.

Advanced Options

Hyperparameter Sweeps

Enhanced Evaluation

View All Parameters

See all parameters for a specific trainer:

Next Steps

YAML Configs

Use configuration files

DPO Training

Deep dive into DPO

LoRA/PEFT

Efficient fine-tuning

Distillation

Knowledge distillation

GRPO Training

RL with custom environments