LoRA & PEFT
Parameter-Efficient Fine-Tuning lets you train large models with less memory.What is LoRA?
LoRA (Low-Rank Adaptation) adds small trainable matrices to the model while keeping base weights frozen. This dramatically reduces memory usage and training time.Quick Start
Python API
Parameters
Rank (lora_r)
Higher rank = more parameters = more capacity:Alpha
The alpha/rank ratio affects learning:Target Modules
By default, LoRA targets all linear layers (all-linear). You can customize:
With Quantization
Combine LoRA with quantization for maximum memory savings:Memory Comparison
Merging Adapters
By default, LoRA adapters are automatically merged into the base model after training. This makes inference simpler - you get a single model file ready to use.Default Behavior (Merged)
Save Adapters Only
To save only the adapter files (smaller, but requires base model for inference):Manual Merge Later
You must specify either
--output-folder to save locally or --push-to-hub to upload to Hugging Face Hub.Merge Tool Parameters
Or in Python:
Convert to Kohya Format
Convert LoRA adapters to Kohya-compatible.safetensors format:
Loading Adapters
Use adapters without merging:Best Practices
Training
- Use higher learning rate (2e-4 to 1e-3)
- LoRA benefits from longer training
- Consider targeting all linear layers for complex tasks
Memory
- Start with
lora_r=16 - Add quantization if needed
- Use gradient checkpointing (on by default)
Quality
- Higher rank generally = better quality
- Test on your specific task
- Compare with full fine-tuning if memory allows
Next Steps
Quantization
Further memory reduction
DPO Training
Preference optimization