Skip to main content

Overview

LoRA (Low-Rank Adaptation) is a parameter-efficient fine-tuning technique that significantly reduces the number of trainable parameters while maintaining model performance. Instead of fine-tuning all model parameters, LoRA adds small trainable rank decomposition matrices to specific layers.

Benefits of LoRA

  • Reduced Memory Usage: Train large models with less GPU memory
  • Faster Training: Fewer parameters to update means faster iterations
  • Smaller Checkpoints: LoRA adapters are typically 1-2% the size of full model weights
  • Easy Deployment: Swap different LoRA adapters for different tasks without loading multiple full models

Enabling LoRA

Add LoRA parameters to your training script:

LoRA Parameters

Core Parameters

boolean
default:"False"
Enable LoRA training. Set to True to use parameter-efficient fine-tuning.
integer
default:"8"
LoRA rank dimension. Controls the bottleneck dimension of the low-rank matrices.Common values:
  • 4: Minimal parameters, fastest training
  • 8: Balanced performance (recommended)
  • 16: Higher capacity
  • 32-64: Approaching full fine-tuning performance
integer
default:"16"
LoRA scaling parameter. Controls the magnitude of LoRA updates.Typical configuration:
  • Set to 2 × lora_r for balanced scaling
  • Higher values = stronger LoRA influence
float
default:"0.0"
Dropout probability for LoRA layers.Recommendations:
  • 0.0: No dropout (default, usually sufficient)
  • 0.05-0.1: For larger datasets prone to overfitting

Configuration Examples

Minimal LoRA (Fastest)

Best for: Quick experimentation, limited compute
Characteristics:
  • Smallest adapter size (~0.5-1% of model size)
  • Fastest training
  • May have slightly lower performance on complex tasks
Best for: Most use cases, good performance-efficiency tradeoff
Characteristics:
  • Moderate adapter size (~1-2% of model size)
  • Good training speed
  • Strong performance across most tasks

High-Capacity LoRA

Best for: Complex tasks, large datasets, when approaching full fine-tuning performance
Characteristics:
  • Larger adapter size (~4-8% of model size)
  • Slower training than lower ranks
  • Performance closer to full fine-tuning
  • Consider dropout for regularization

Complete LoRA Training Script

train_lora.sh
With LoRA enabled, you can often increase the batch size since fewer parameters are being updated. Try doubling per_device_train_batch_size compared to full fine-tuning.

LoRA with Component Training

LoRA adapters are applied only to the components you choose to train:

Learning Rate Adjustment

LoRA training typically benefits from higher learning rates than full fine-tuning:

Saving and Loading LoRA Adapters

Checkpoint Structure

LoRA training saves both the adapter weights and the configuration:

Loading for Inference

Memory Requirements

Approximate GPU memory usage for different configurations:

Qwen2.5-VL-3B

Qwen2.5-VL-7B

For single GPU training with limited memory, use LoRA with r=4 and enable gradient checkpointing in your DeepSpeed config.

Best Practices

Start with r=8 and adjust based on results:Increase rank if:
  • Model is underfitting
  • Task is complex with many nuances
  • Dataset is large and diverse
Decrease rank if:
  • Memory is limited
  • Training time is critical
  • Task is relatively simple
LoRA works well with other efficiency techniques:
Train separate LoRA adapters for different tasks:
Then swap adapters at inference time without reloading the base model.

Troubleshooting

Common Issues:
  1. Underfitting: If LoRA performance is significantly worse than expected:
    • Increase lora_r (try 16 or 32)
    • Increase lora_alpha proportionally
    • Increase learning rate
    • Train for more epochs
  2. Overfitting: If validation loss increases while training loss decreases:
    • Add lora_dropout (0.05-0.1)
    • Reduce lora_r
    • Add weight decay
    • Use data augmentation
  3. Memory Issues: If still running out of memory with LoRA:
    • Reduce lora_r to 4
    • Decrease batch size
    • Enable gradient checkpointing
    • Use DeepSpeed ZeRO-3

Further Reading