Continual Learning & Catastrophic Forgetting
Training models on sequential tasks without forgetting: elastic weight consolidation (EWC), progressive neural networks, experience replay, PackNet, and modern continual pre-training strategies for LLMs.
Prerequisites
Table of Contents
- Learning Objectives
- Notation
- Core Intuition
- The Catastrophic Forgetting Problem
- Elastic Weight Consolidation (EWC)
- Experience Replay
- Progressive Neural Networks
- Continual Pre-training for LLMs
- Model Merging as Continual Learning
- Common Pitfalls
- Summary
- Exercises
Learning Objectives
- Formalize catastrophic forgetting and measure its severity.
- Derive EWC from a Bayesian perspective (Fisher information as importance).
- Design experience replay buffers for continual learning.
- Apply continual pre-training to update LLMs with new knowledge.
- Use model merging techniques to combine task-specific adaptations.
Notation
- — sequence of tasks
- — Fisher information matrix after task
- — optimal parameters for task
Core Intuition
Neural networks learn by adjusting all parameters — but this means learning task B overwrites the parameters that encoded task A. This "catastrophic forgetting" is the fundamental challenge of continual learning: how to accumulate knowledge over time without losing what was previously learned. Solutions range from protecting important parameters (EWC) to replaying old data (experience replay) to growing the network (progressive nets).
Continual Learning (EWC)
The Catastrophic Forgetting Problem
Formal definition: After training on tasks sequentially:
Why it happens in neural networks:
- Shared representation: all tasks use the same parameters.
- No explicit memory: unlike the brain, no separate episodic memory.
- Gradient interference: gradients for new task point away from old task optimum.
Stability-plasticity dilemma:
- Too stable → can't learn new tasks.
- Too plastic → forgets old tasks.
- Must balance both.
Elastic Weight Consolidation (EWC)
Kirkpatrick et al. (2017): Protect important parameters with a quadratic penalty:
where is the Fisher information of parameter (measuring its importance for old tasks).
Fisher information:
Interpretation: Parameters with high Fisher are "important" (small changes cause large loss increase). EWC penalizes changes to these parameters heavily; unimportant parameters can change freely.
Bayesian view: EWC approximates the posterior as a Gaussian centered at with precision . Training on with this prior prevents forgetting .
Experience Replay
Simple but effective: Store a small buffer of old task data; mix with new task during training:
where is a replay buffer of stored examples.
Buffer strategies:
- Random: Store random subset of old data.
- Herding: Store representative examples (closest to class mean).
- Gradient-based: Store examples with high gradient magnitude.
Buffer size tradeoff: Larger buffer = less forgetting, more memory. Typical: 1-5% of old data.
For LLMs: Replay a fraction of pre-training data during fine-tuning (5-10% of each batch).
Progressive Neural Networks
Rusu et al. (2016): Don't overwrite — grow:
- Train a model for task 1 (freeze it).
- Add a new column (model) for task 2, with lateral connections from task 1.
- Add another column for task 3, with connections from tasks 1 and 2.
Properties:
- Zero forgetting (old parameters are frozen).
- Positive forward transfer (new tasks can use old features via lateral connections).
- Growing cost (one model per task — impractical for many tasks).
Continual Pre-training for LLMs
Problem: LLM knowledge becomes stale (trained on data up to a cutoff date). How to update without full retraining?
Approaches:
1. Continued pre-training: Resume pre-training on new data:
- Use low learning rate (1/10 of original).
- Mix new data with old data replay (5-20%).
- Risk: slight degradation on old benchmarks.
2. Domain adaptation: Focus on new domain while preserving general ability:
- Train on domain-specific corpus (medical, legal, code).
- Replay general data to prevent catastrophic forgetting.
3. Knowledge editing: Modify specific facts without retraining:
- ROME/MEMIT: Direct parameter editing for fact updates.
- Limited to simple fact changes; doesn't generalize.
Model Merging as Continual Learning
Instead of sequential training: Train separate models for each task, then merge:
Linear merging (TIES, DARE):
Task arithmetic: Task vectors can be added:
Advantage: No sequential training needed. Train tasks in parallel, merge at the end.
Limitation: Works best when task vectors are approximately orthogonal (non-conflicting).
Common Pitfalls
Pitfall 1. Using high learning rate for continual pre-training. This causes immediate forgetting. Use LR that's 5-10x lower than original pre-training peak.
Pitfall 2. EWC without sufficient Fisher estimation. Computing Fisher on too few examples gives noisy importance estimates. Use 1000+ samples.
Pitfall 3. Merging models trained with very different data distributions. If tasks are conflicting (e.g., "be verbose" vs "be concise"), linear merging produces a poor compromise.
Summary
- Catastrophic forgetting: Learning new tasks degrades old task performance.
- EWC: Quadratic penalty weighted by Fisher information (parameter importance).
- Experience replay: Mix old data with new data during training.
- Progressive nets: Grow the model; zero forgetting but linear cost.
- Continual pre-training: Low LR + data replay to update LLM knowledge.
- Model merging: Train separately, merge after — avoids sequential forgetting entirely.
Exercises
Exercise 1. Compute the Fisher information for a 2-class logistic regression model with weights .
Exercise 2. For experience replay with 1% buffer: estimate the forgetting rate after 10 sequential tasks on CIFAR-100.
Exercise 3. Design a continual pre-training schedule to update LLaMA-2 (trained through 2023) with 2024 data. Specify LR, data mix, and evaluation strategy.
Exercise 4. Prove that linear model merging is optimal when task vectors are orthogonal (in parameter space).
Exercise 5. Compare the compute cost of: (a) retraining from scratch, (b) continual pre-training, (c) model merging for adding a new language to a multilingual LLM.