Fine-Tuning LLMs Tutorial 120 lessons · 3:01:51+ of video
Fine-Tuning LLMs Home What Fine-Tuning Is
What Is Fine-Tuning? How LLMs Work Pretraining vs Fine-Tuning When to Fine-Tune
Prompting, RAG or Fine-Tuning? What Fine-Tuning Can and Can't Do The Tools: Transformers, PEFT, TRL Setup, the Hub and pipeline()
Setting Up The Hugging Face Hub Your First Model: pipeline() Tokenizers
Tokenizers Token IDs and Special Tokens Padding, Truncation, Attention Masks Models, Logits and Generation
Loading a Model Logits and Probabilities Generating Text Decoding, Instruct Models and Chat Templates
Decoding Settings Base vs Instruct Models Chat Templates Memory and Data Types
Parameters and Memory Data Types Training Memory How Training Works
Loss Gradients and Learning Rate Epochs, Batches, Steps Working with Datasets
The datasets Library map, filter, split Our Project Data Classification Fine-Tuning
Classification Fine-Tuning Tokenize the Dataset A Classification Model Training with the Trainer
Trainer and TrainingArguments Train It Evaluate It Overfitting, Saving and Using
Overfitting Save and Load Use Your Model Fine-Tuning a Language Model
Full Fine-Tuning an LLM Labels for Causal LMs Why We Need PEFT LoRA Explained
PEFT: the Big Idea LoRA Explained Rank and Alpha LoRA with PEFT
Which Layers? LoraConfig get_peft_model Instruction Data
Instruction Data Formats Build a Chat Dataset Train on Answers Only Your First LoRA Fine-Tune
TRL and SFTTrainer SFTConfig First LoRA Run Results, Loss and Hyperparameters
Before and After Reading the Loss Hyperparameters That Matter Save, Load and Merge Adapters
Saving Adapters Loading Adapters Merging Adapters Quantization and QLoRA
Quantization 4-bit NF4 QLoRA Fitting Training into Memory
GPU Memory Budget Gradient Accumulation Gradient Checkpointing Precision, Length and Hardware
Mixed Precision Sequence Length and Packing Where to Train Bigger Models and Many Adapters
A Bigger Model Many Adapters Practice Data: Quality and Collection
Quality Beats Quantity Collecting Data Synthetic Data Data: Cleaning, Splits and Size
Cleaning and Dedup Splits and Leakage How Much Data? Data: Prompts, Conversations and Sharing
System Prompts Multi-turn Data Sharing Datasets Data: Balance, Safety and Practice
Label Balance Bias and Safety Data Practice Evaluating a Fine-Tuned Model
Why Evaluation Is Hard Exact Match and Valid JSON Perplexity Evaluation Loops, Judges and Forgetting
An Evaluation Loop LLM as a Judge Catastrophic Forgetting Comparing Runs and Error Analysis
Comparing Runs Error Analysis Evaluation Practice Preference Tuning and DPO
Preference Tuning DPO DPO with TRL Beyond LoRA: PEFT, Distillation and Prompting
Other PEFT Methods Distillation When Not to Fine-Tune Sharing and Serving Your Model
Push to the Hub Serving with vLLM GGUF and Ollama Fast Inference, Many Adapters and Costs
Fast Inference Serving Many Adapters Costs Project: Plan, Data and Baseline
Project: Plan Project: Baseline Project: Dataset Project: Train, Evaluate and Improve
Project: Train Project: Evaluate Project: Improve Project: Save, Use and Wrap-up
Project: Merge and Save Project: Chat With It Project: Wrap-up Mistakes, Troubleshooting and Interview Basics
Common Mistakes Troubleshooting Interview: Core Interview Questions and Cheat Sheets
Interview: LoRA and Training Cheat Sheet: Code Cheat Sheet: Settings Final Quiz, Next Steps and Recap
Final Quiz What to Learn Next Course Recap Fine-Tuning LLMs · Lesson 94 of 120
Other PEFT Methods Beyond LoRA.
⏱ 2 min read ▶ Video at 2:23:03 🎓 Free
▶ starts at 2:23:03 LoRA is the most popular way to fine-tune efficiently. But it's not the only one. The PEFT library has several other methods. Let's meet the main ones.
LoRA is the most popular Not the only one Meet the others DoRA splits each weight into a size, and a direction, and adapts both. It's often a little better than LoRA. IA three learns tiny scaling vectors, that multiply the activations. And prompt tuning learns a few virtual tokens, that are added in front of every input.
Method What it learns LoRA small matrices B·A per layer DoRA LoRA + a size per weight IA3 scaling vectors Prompt tuning a few virtual tokens
Let's compare their sizes. We build each config, wrap the same model, and count the trainable parameters. Use dora equals true turns LoRA into DoRA. Run it. LoRA and DoRA train about five million parameters. IA three trains fifty seven thousand. And prompt tuning, only eleven thousand. Fewer parameters means less to store, but usually less power to learn.
methods.py python Copy
from transformers import AutoModelForCausalLM
from peft import get_peft_model, LoraConfig, IA3Config, PromptTuningConfig
NAME = "HuggingFaceTB/SmolLM2-135M-Instruct"
configs = {
"LoRA r=16" : LoraConfig( r = 16 , target_modules = "all-linear" , task_type = "CAUSAL_LM" ),
"DoRA r=16" : LoraConfig( r = 16 , target_modules = "all-linear" , use_dora = True ,
task_type = "CAUSAL_LM" ),
"IA3" : IA3Config( task_type = "CAUSAL_LM" ),
"Prompt tuning" : PromptTuningConfig( num_virtual_tokens = 20 , task_type = "CAUSAL_LM" ),
}
for name, config in configs.items():
model = get_peft_model(AutoModelForCausalLM.from_pretrained( NAME ), config)
trainable, total = model.get_nb_trainable_parameters()
print ( f " { name :14 } { trainable :>10, } trainable ( { trainable / total :.3% } )" ) Output
LoRA r=16 4,884,480 trainable (3.504%)
DoRA r=16 5,040,000 trainable (3.611%)
IA3 57,600 trainable (0.043%)
Prompt tuning 11,520 trainable (0.009%) Prefer to watch? The full Fine-Tuning LLMs course is free All lessons in one video with animations, real code and chapters.
Watch free In practice, start with LoRA. It works well, and every tool supports it. Try DoRA if you want a little extra quality. And use IA three, or prompt tuning, only when storage is extremely tight, like thousands of adapters.
key value Default LoRA A bit better DoRA, use_dora=True Tiny IA3, prompt tuning Support LoRA works everywhere
Let's recap. DoRA improves LoRA a little. IA three, and prompt tuning, are tiny, but weaker. And LoRA is the best default. Next, distillation.
Key takeaways LoRA: default DoRA: a bit better IA3, prompt tuning: tiny