Full Fine-tuning & Instruction Tuning
Adapting pre-trained models to downstream tasks: full parameter fine-tuning, instruction tuning (FLAN, Alpaca), supervised fine-tuning (SFT), learning rate schedules, catastrophic forgetting, and multi-task fine-tuning.
Prerequisites
Table of Contents
- Learning Objectives
- Notation
- Core Intuition
- Full Fine-tuning
- Instruction Tuning
- SFT: Supervised Fine-Tuning for Chat
- Learning Rate & Schedule
- Catastrophic Forgetting
- Multi-Task Fine-Tuning
- Common Pitfalls
- Summary
- Exercises
Learning Objectives
- Design a full fine-tuning pipeline for task adaptation.
- Explain instruction tuning and the FLAN/T0 methodology.
- Derive optimal learning rate schedules for fine-tuning.
- Identify and mitigate catastrophic forgetting.
- Balance multi-task training for broad capability.
Notation
- — pre-trained parameters
- — fine-tuning learning rate
- — downstream task dataset
Core Intuition
Pre-training learns general language understanding; fine-tuning specializes it for a specific use case. Full fine-tuning updates ALL parameters — maximum flexibility but risks forgetting pre-trained knowledge and overfitting to small datasets. Instruction tuning is a special form that teaches the model to follow instructions across many tasks, creating a general-purpose assistant.
Full Finetuning Dynamics
Full Fine-tuning
Update all parameters on task-specific data:
When to use full fine-tuning:
- Sufficient data (above 10K examples for above 1B models).
- Maximum quality needed (no PEFT compromise).
- Single-task deployment (don't need to switch between tasks).
Typical hyperparameters:
- Learning rate: to (10-100x smaller than pre-training LR).
- Epochs: 2-5 (more risks overfitting).
- Batch size: 32-128 (smaller than pre-training).
- Warmup: 3-10% of total steps.
Instruction Tuning
FLAN (Wei et al., 2022): Fine-tune on a mixture of tasks phrased as instructions:
Input: "Translate the following to French: Hello, how are you?" Output: "Bonjour, comment allez-vous?"
Key design decisions:
- Task diversity: 62+ datasets across NLU, NLG, reasoning, translation.
- Instruction templates: Multiple phrasings per task (10+ templates).
- Chain-of-thought: Include reasoning traces for complex tasks.
- Task balancing: Limit large datasets; upsample small ones.
FLAN-T5/PaLM result: Instruction-tuned models outperform base models on UNSEEN tasks — zero-shot generalization from following diverse instructions.
Scaling instruction data: More task diversity (not more examples per task) drives improvement. 100 tasks × 1K examples > 10 tasks × 10K examples.
SFT: Supervised Fine-Tuning for Chat
The alignment pipeline's first step:
where is the prompt and is the desired response. Loss computed ONLY on the response tokens (not the prompt).
Data format: (system_prompt, user_message, assistant_response) conversations.
Key practices:
- Data quality over quantity: 10K high-quality conversations outperform 1M noisy ones.
- Diverse tasks: coding, math, creative writing, analysis, roleplay.
- Multi-turn: Include multi-turn conversations for dialogue coherence.
- Format: Train with the exact chat template used at inference.
Learning Rate & Schedule
The fine-tuning LR principle: Start small, decay quickly.
Linear decay with warmup:
Cosine decay:
Layer-wise learning rate decay: Lower layers (general features) get smaller LR; upper layers (task-specific) get larger:
Catastrophic Forgetting
Problem: Fine-tuning on task A degrades performance on task B (previously learned).
Causes:
- Small fine-tuning dataset overrides general knowledge.
- High learning rate pushes parameters far from pre-trained values.
- Limited diversity in fine-tuning data.
Mitigations:
- Lower learning rate (stay close to pre-trained initialization).
- Regularization: Add L2 penalty toward pre-trained weights: .
- Data replay: Mix fine-tuning data with pre-training-style data.
- EWC: Penalize changes to important parameters (Fisher information weighted).
- LoRA/PEFT: Freeze most parameters; only update a small subspace.
Multi-Task Fine-Tuning
Train on multiple tasks simultaneously:
Task balancing strategies:
- Proportional: (large datasets dominate).
- Equal: (each task gets equal influence).
- Temperature sampling: with upsampling small tasks.
- Dynamic (GradNorm): Adjust based on task gradient magnitudes.
When multi-task helps: Tasks are related and share useful representations. When it hurts: Tasks conflict (opposite objectives) or one task dominates.
Common Pitfalls
Pitfall 1. Using pre-training learning rate for fine-tuning. Pre-training LR () is too high; fine-tuning should be or lower to avoid destroying pre-trained features.
Pitfall 2. Computing loss on prompt tokens during SFT. The model already knows how to process prompts from pre-training; only response tokens need learning. Including prompt in loss dilutes the training signal.
Pitfall 3. Fine-tuning for too many epochs on small datasets. After 3-5 epochs on 10K examples, the model overfits (training loss drops while eval loss rises). Use early stopping.
Summary
- Full fine-tuning: Update all parameters; maximum quality; risk of forgetting.
- Instruction tuning: Diverse tasks as instructions; enables zero-shot generalization.
- SFT: Response-only loss on conversations; data quality is critical.
- Learning rate: 10-100x smaller than pre-training; cosine/linear decay.
- Catastrophic forgetting: Mitigate with low LR, regularization, or PEFT.
- Multi-task: Balance datasets carefully; temperature sampling helps.
Exercises
Exercise 1. Design an instruction tuning mixture for a 7B model targeting strong code + math + conversation abilities. Specify datasets, ratios, and templates.
Exercise 2. Compute the optimal fine-tuning learning rate for a model pre-trained with peak LR , using the "1/100" rule.
Exercise 3. For a model fine-tuned on QA: measure catastrophic forgetting by evaluating on translation before and after fine-tuning.
Exercise 4. Compare full fine-tuning vs LoRA for a 13B model on a 50K-example task: estimate quality gap, memory, and training time.
Exercise 5. Derive the GradNorm algorithm for dynamically balancing 3 tasks with different gradient magnitudes.