A comprehensive, beginner-friendly repository for fine-tuning large language models using modern techniques like LoRA, DPO, and Unsloth optimizations.
# Install dependencies
!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
# Load and fine-tune in 3 lines
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained("unsloth/llama-3-8b-bnb-4bit")
model = FastLanguageModel.get_peft_model(model, r=16)
# Add your training code here| π Folder | π― Purpose | π₯ Best For | β±οΈ Time Needed |
|---|---|---|---|
| FineTuning LanguageModels | Basic concepts & simple examples | Beginners, students | 1-2 hours |
| FineTuning LargeLanguageModels | Advanced techniques & model-specific guides | Practitioners, researchers | 3-5 hours |
| FineTuning VisionModel | Vision-language model fine-tuning | Computer vision researchers | 2-3 hours |
| Advanced FineTuning Methods | Multi-LoRA & LoRA composition techniques | Advanced researchers, ML engineers | 3-4 hours |
| Task Specific FineTuning | Specialized task fine-tuning (Code generation) | Domain specialists, developers | 2-3 hours |
| Reinforcement Learning Based FineTning | Human preference alignment (DPO, RLHF) | Advanced users, alignment researchers | 2-4 hours |
| docs/ | Comprehensive guides & troubleshooting | All skill levels | Reference |
β Start with Basic LoRA Fine-tuning
- β Easy to understand
- β Low memory requirements
- β Good results for most tasks
β Use 4-bit Quantized LoRA
- β Works on Google Colab T4
- β 70% less memory usage
- β Minimal performance loss
β Try DPO Training
- β Improves response quality
- β Better human alignment
- β No reward model needed
β Use Vision Model Fine-tuning
- β Image + text processing
- β Mathematical formula recognition
- β Multimodal AI applications
β Try Multi-LoRA Methods
- β Multiple skills without forgetting
- β Dynamic adapter switching
- β Combine different expertises
β Use Task-Specific Fine-tuning
- β Advanced code generation
- β Multi-language programming support
- β Optimized with Qwen2.5-Coder
| Model | Size | Min GPU Memory | Training Time (100 steps) | Best Use Case |
|---|---|---|---|---|
| Phi-3 Mini | 3.8B | 6GB | 10 mins | Coding tasks, efficiency |
| Llama-3-8B | 8B | 12GB | 20 mins | General conversation |
| Qwen2.5-7B | 7.6B | 10GB | 18 mins | Multilingual, math |
| Qwen2-VL-7B | 7B | 8GB | 25 mins | Vision-language tasks |
π‘ Tip: All memory requirements assume 4-bit quantization with LoRA
!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
!pip install --no-deps "trl<0.9.0" transformers datasetspip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
pip install "unsloth[cu121-ampere-torch230] @ git+https://github.com/unslothai/unsloth.git"β Getting CUDA out of memory errors? β See Memory Optimization Guide
β Model not following instructions?
β Try DPO Training
β Training too slow? β Check Performance Optimization Tips
- Week 1: Basic Fine-tuning Concepts
- Week 2: LoRA and PEFT Techniques
- Week 3: Vision-Language Models
- Week 4: Human Preference Alignment
- Week 5: Advanced Multi-LoRA Methods
- Week 6: Task-Specific Applications
Fine-tuning is like teaching a smart student a new skill:
- π§ Pre-trained model = Student who already knows language
- π Your dataset = Textbook for the new skill
- βοΈ Fine-tuning = Practice sessions to master the skill
- π― Fine-tuned model = Expert in your specific task
| Approach | Cost | Time | Data Needed | Results |
|---|---|---|---|---|
| Training from scratch | $1M+ | Months | Billions of tokens | 100% |
| Fine-tuning | $10-100 | Hours | Thousands of examples | 95%+ |
β 99% cost reduction while maintaining excellent performance!
# Start with a pre-trained model
model = "unsloth/llama-3-8b-bnb-4bit" # Already knows language# Your specialized dataset
dataset = [
{"instruction": "Explain photosynthesis", "output": "Photosynthesis is..."},
{"instruction": "Write code", "output": "def function():..."}
]# Train only 1% of parameters
model = FastLanguageModel.get_peft_model(model, r=16) # LoRA magicThis repository contains everything you need to master fine-tuning, from beginner-friendly tutorials to advanced optimization techniques.
Learn the fundamentals with hands-on examples and step-by-step guides.
Explore advanced techniques like DPO training and model optimization.
Master vision-language models and human preference alignment.
- π Bug reports: GitHub Issues
- π¬ Questions: GitHub Discussions
- π Documentation: Check the docs/ folder
- π€ Contributing: See CONTRIBUTING.md
MIT License - see LICENSE file for details.
β Star this repo if it helped you fine-tune your models!
Updates all model parameters during training. Requires high computational resources but achieves best task-specific performance.
Updates only a small subset of parameters with 90% reduction in computational cost while matching full fine-tuning performance.
Quantization reduces model weight precision from 32-bit to lower precision (8-bit, 4-bit), dramatically reducing memory usage while maintaining performance.
- FP32: 4 bytes per parameter (baseline)
- INT8: 1 byte per parameter (75% memory reduction)
- INT4: 0.5 bytes per parameter (87.5% memory reduction)
FP32: 7B Γ 4 bytes = 28 GB
INT8: 7B Γ 1 byte = 7 GB (75% reduction)
INT4: 7B Γ 0.5 bytes = 3.5 GB (87.5% reduction)
LoRA decomposes weight updates into low-rank matrices, reducing trainable parameters by 99% while maintaining performance.
W' = W + ΞW
ΞW = A Γ B
- W: Original pre-trained weights (frozen)
- A: Low-rank matrix (d Γ r)
- B: Low-rank matrix (r Γ k)
- r: Rank (much smaller than d or k)
- r = 8-16: Standard choice, good balance
- r = 32-64: Complex adaptations
- r = 128+: Approaching full fine-tuning
4096 Γ 4096 layer with r=16:
Original: 4096 Γ 4096 = 16,777,216 parameters
LoRA: (4096 Γ 16) + (16 Γ 4096) = 131,072 parameters
Reduction: 99.2% fewer parameters
Small neural network modules inserted between transformer layers for task-specific adaptation.
Input β Layer Norm β Adapter β Residual Connection β Output
| Aspect | LoRA | Adapters |
|---|---|---|
| Parameter Count | 0.1-1% | 2-4% |
| Training Speed | Faster | Moderate |
| Modularity | Limited | High |
This repository contains six specialized folders:
Foundational fine-tuning techniques and inference examples for beginners.
Advanced model-specific fine-tuning using UnSloth, LoRA, and quantization techniques.
Vision-language model fine-tuning for multimodal AI applications.
Cutting-edge Multi-LoRA and LoRA composition techniques for multiple domain expertise.
Specialized fine-tuning for domain-specific tasks like code generation.
Human preference alignment using Direct Preference Optimization (DPO) and RLHF.
# Clone repository
git clone https://github.com/Abeshith/FineTuning_LanguageModels.git
cd FineTuning_LanguageModels
# Install dependencies
pip install transformers datasets torch torchvision
pip install unsloth peft bitsandbytes trl accelerate