| name | lora-fine-tuning |
| description | How to implement LoRA (Low-Rank Adaptation) for efficient fine-tuning of large language models. Use this skill whenever the user wants to fine-tune an LLM, reduce training memory/compute requirements, implement parameter-efficient fine-tuning, or adapt a pre-trained model to a new task without retraining all parameters. Make sure to use this skill when users mention fine-tuning, LoRA, PEFT, parameter-efficient training, or want to train on limited hardware. |
LoRA Fine-Tuning Implementation
This skill helps you implement LoRA (Low-Rank Adaptation) for efficient fine-tuning of large language models. LoRA reduces training costs by only updating small adapter matrices instead of the entire model.
When to Use LoRA
Use LoRA when you need to:
- Fine-tune a large model on limited hardware (less GPU memory)
- Adapt a pre-trained model to a new task without full retraining
- Store multiple task-specific adaptations efficiently
- Reduce training time and computational costs
How LoRA Works
LoRA replaces standard linear layers with a combination of:
- Original frozen weights (preserved from pre-training)
- Two small trainable matrices (A and B) that approximate weight updates
The forward pass becomes: output = original_linear(x) + alpha * (x @ A @ B)
Key Benefits
- Fewer trainable parameters: Only matrices A and B are updated
- Preserved knowledge: Original model weights stay frozen
- Storage efficiency: Save only small LoRA matrices per task
- Faster training: Less computation per gradient update
Implementation
Step 1: Define LoRA Components
Use the scripts/lora_layers.py module which provides: