Navigation
🏋️ Training Systems· 8 min read

Continual Learning

Catastrophic forgetting, replay buffers, elastic weight consolidation — updating models incrementally without losing prior capabilities.

continual-learningcatastrophic-forgettingreplayewcincremental

When you fine-tune a model on new data, it tends to forget old capabilities — “catastrophic forgetting.” Continual learning techniques allow incremental updates without starting from scratch.


1. The Forgetting Problem

Fine-tuning on domain B degrades performance on domain A:

Model stateDomain A (general)Domain B (medical)
Base model85%40%
After SFT on B60% (↓25%)92%
Target85%92%

The weight updates that improve medical knowledge overwrite the representations used for general knowledge.


2. Mitigation Strategies

Replay Buffers

Mix old data into new training:

# 80% new domain data, 20% replay from old training data
dataset = ConcatDataset([
    new_domain_data,                  # 80%
    Subset(original_training_data, indices=replay_indices),  # 20%
])

Effectiveness: Simple, works well, but requires access to original training data.

Elastic Weight Consolidation (EWC)

Add a regularization term that penalizes changing important weights:

Ltotal=Ltask+λ2∑iFi(θi−θi∗)2L_{\text{total}} = L_{\text{task}} + \frac{\lambda}{2} \sum_i F_i (\theta_i - \theta_i^*)^2

Where FiF_i is the Fisher information (importance) of parameter ii, and θ∗\theta^* are the original weights. Important weights are penalized more for changing.

LoRA for Continual Learning

Train separate LoRA adapters for each domain:

DomainApproachForgetting?
MedicalLoRA adapter ANo (base unchanged)
LegalLoRA adapter BNo (base unchanged)
BothMerge or switch adaptersNo forgetting

LoRA naturally prevents catastrophic forgetting because the base model is frozen. Each adapter learns domain-specific adjustments without interfering.

Knowledge Distillation

Use the old model as a teacher to regularize the new model:

L=α⋅Ltask+(1−α)⋅KL(pold∥pnew)L = \alpha \cdot L_{\text{task}} + (1-\alpha) \cdot \text{KL}(p_{\text{old}} \| p_{\text{new}})

The KL divergence term ensures the updated model’s output distribution stays close to the original on general inputs. This is used in practice by teams that do periodic “model merges” — combining capabilities from separately fine-tuned models.

Data Mixing (Most Common in Practice)

The simplest and most effective strategy for production: always train on a mix of old and new data, with proportions tuned by evaluation:

mix_ratios = {
    "original_pretraining_sample": 0.10,   # prevent forgetting
    "previous_sft_data": 0.20,              # maintain old skills
    "new_domain_data": 0.60,                # learn new capability
    "safety_data": 0.10,                    # maintain alignment
}

This is what most production teams actually do — it’s simple, effective, and doesn’t require complex algorithms. Llama-3.1 used extensive data mixing during continued pre-training to add multilingual capabilities without losing English performance.


For LoRA as a continual learning strategy, see LoRA.

3. Practical Recommendations

ScenarioBest approach
Adding a new capabilityLoRA adapter (no forgetting)
Improving existing capabilitiesReplay buffer (mix old + new)
Periodic model refreshFull retrain on combined data
Continuous data streamEWC + replay buffer

Self-Check

  • Explain catastrophic forgetting with a concrete example
  • Implement a replay buffer for continual fine-tuning
  • Explain EWC’s Fisher information regularization
  • Explain why LoRA naturally prevents forgetting

References