Skip to content

Repository files navigation

🧠 Catastrophic Forgetting Analysis
in Large Language Models

Evaluating & Mitigating Catastrophic Forgetting during Continual Instruction Tuning of BLOOMZ (560M β†’ 3B)

πŸ€— 31 Model Checkpoints β€’ πŸ–₯️ Live Demo β€’ πŸ“Š Key Findings β€’ πŸš€ Quick Start


πŸ“– About

This research project investigates Catastrophic Forgetting (CF) β€” the phenomenon where neural networks lose previously learned knowledge when trained on new tasks. We conducted systematic experiments on the BLOOMZ model family across 5 sequential instruction-tuning tasks, combining mechanistic interpretability with practical mitigation strategies.

πŸ”¬ Research Pipeline

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  BLOOMZ (560M / 1.1B / 3B)                                                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚  β”‚ SIMP β”‚ β†’  β”‚ EMDG β”‚ β†’  β”‚ InqQG β”‚ β†’  β”‚ EXP β”‚ β†’  β”‚ HGen β”‚   Sequential    β”‚
β”‚  β”‚Task 1β”‚    β”‚Task 2β”‚    β”‚Task 3 β”‚    β”‚Task4β”‚    β”‚Task 5β”‚   Fine-Tuning   β”‚
β”‚  β””β”€β”€β”¬β”€β”€β”€β”˜    β””β”€β”€β”¬β”€β”€β”€β”˜    β””β”€β”€β”¬β”€β”€β”€β”€β”˜    β””β”€β”€β”¬β”€β”€β”˜    β””β”€β”€β”¬β”€β”€β”€β”˜                  β”‚
β”‚     ↓           ↓           ↓            ↓          ↓                      β”‚
β”‚  [Eval]      [Eval]      [Eval]       [Eval]     [Eval]   ← MMLU/BoolQ/   β”‚
β”‚                                                               RACE         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Mechanistic Analysis:  Gradient Conflict β”‚ CKA Drift β”‚ Loss Sharpness    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Mitigation Strategies: πŸ”€ Mixing β”‚ 🧊 Freezing β”‚ πŸ“ Curvature Reg.      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“Š Key Findings

Forgetting Metrics (FG%) β€” Lower is Better

Model Method Naive (No Fix) πŸ”€ Mixing 🧊 Freezing πŸ“ Curvature
BLOOMZ-560M Full FT 22.03% 6.05% βœ… 13.61% 13.81%
BLOOMZ-1.1B Full FT 12.94% 5.79% βœ… 11.81% 7.92%
BLOOMZ-3B Full FT 5.84% 2.51% βœ… 4.88% 5.01%
BLOOMZ-560M QLoRA 4-bit 13.30% 8.54% 5.54% βœ… 8.97%
BLOOMZ-3B QLoRA 4-bit 5.91% 4.33% 2.22% βœ… 3.92%

πŸ’‘ Key Insight: Mixing works best for Full Fine-Tuning (large parameter space), while Freezing is optimal for QLoRA (constrained adapter space).

πŸ“‰ Forgetting Curves β€” Accuracy Degradation Over Sequential Tasks

Forgetting Curve - BLOOMZ-560M Full FT

BLOOMZ-560M Full Fine-Tuning: Accuracy drops significantly on MMLU, BoolQ, and RACE as the model learns new tasks sequentially.

Forgetting Curve - BLOOMZ-3B

BLOOMZ-3B: Larger models show more resilience to forgetting, but CF is still present.

πŸ”₯ CKA Heatmap β€” Representational Drift Across Layers

CKA Heatmap - 560M Full FT CKA Heatmap - QLoRA 560M

Left: Full FT 560M β€” Right: QLoRA 560M. CKA scores near 1.0 = stable representations, near 0.0 = severe drift. Middle layers (L10-L14) drift most after domain-shifting tasks like EMDG.

⚑ Gradient Conflict & Loss Landscape Analysis

Gradient Conflict Analysis Fisher Trace - Loss Landscape

Left: Gradient interference between consecutive tasks β€” high conflict ratio indicates opposing optimization directions. Right: Fisher Trace measures loss landscape sharpness β€” sharper landscapes correlate with higher forgetting.

πŸ“Š Mitigation Strategy Comparison

FG Comparison - 560M Pareto Chart - Stability vs Plasticity

Left: Forgetting Metric comparison across strategies β€” Mixing achieves the lowest FG for Full FT. Right: Pareto chart showing the Stability-Plasticity trade-off β€” ideal position is top-right corner.


πŸ–₯️ Interactive Demo

A full-stack web application for real-time visualization and model inference:

Features

  • πŸ“ˆ 6 chart types: Forgetting curves, CKA heatmaps, gradient conflict, Pareto, strategy comparison
  • πŸ€– Live inference: Generate text with any of the 31 model checkpoints
  • βš”οΈ A/B comparison: Side-by-side output comparison (Original vs Catastrophically Forgotten)
  • πŸ”— Chain comparison: Track output degradation across all 5 task checkpoints
  • πŸ“Š Strategy comparison: Compare mitigation strategies in real-time

Demo includes:

  • πŸ“ˆ 6 interactive chart types rendered server-side with Matplotlib
  • πŸ€– Real-time text generation with any of the 31 BLOOMZ checkpoints
  • βš”οΈ Side-by-side A/B comparison of Original vs Forgotten model outputs
  • πŸ”— Chain comparison to visualize output degradation across all 5 task checkpoints

πŸš€ Quick Start

1. Clone & Install

git clone https://github.com/dovanminh100104-coder/Catastrophic-Forgetting-Analysis-BLOOMZ.git
cd Catastrophic-Forgetting-Analysis-BLOOMZ
pip install -r requirements.txt

2. Run Demo Server

python demo_server.py

Opens automatically at http://localhost:8000

πŸ’‘ First run downloads models from HuggingFace (~1.1GB/model). Use --no-preload to skip.

3. Generate Paper Charts

python generate_charts.py
# Output: charts/ directory with all PNG figures

πŸ“ Project Structure

.
β”œβ”€β”€ πŸ“„ demo_server.py            # FastAPI backend + inference engine + chart API
β”œβ”€β”€ 🌐 demo_frontend.html        # Interactive web UI (vanilla JS)
β”œβ”€β”€ πŸ“Š demo_data.json            # Experiment results (accuracy, FG, CKA, gradients)
β”œβ”€β”€ πŸ“ˆ generate_charts.py        # Publication-quality chart generator
β”œβ”€β”€ πŸ–ΌοΈ hinh1_framework.html      # Research framework diagram
β”œβ”€β”€ πŸ“‹ requirements.txt          # Python dependencies
β”œβ”€β”€ πŸ“– README_models.md          # Full list of 31 HuggingFace models
β”œβ”€β”€ πŸ“Š assets/                   # Charts and figures for README
β”œβ”€β”€ πŸ“ Workflow_ThucNghiem.md    # 5-step experiment workflow
β”œβ”€β”€ πŸ“„ Baibaonhom04_detai28.*    # Research paper (DOCX + PDF)
β”œβ”€β”€ πŸ“„ BaoCaoMonHocNhom04_*      # Course report (DOCX + PDF)
└── πŸ§ͺ thucnghiem/               # Kaggle experiment notebooks (GPU T4)
    β”œβ”€β”€ thucnghiem-cf-llms-560m-final.ipynb    # Full FT 560M
    β”œβ”€β”€ thucnghiem-cf-llms-1b1-final.ipynb     # Full FT 1.1B (coming soon)
    β”œβ”€β”€ thucnghiem-cf-llms-3b.ipynb            # Full FT 3B
    β”œβ”€β”€ cf-bloomz-560m-lora-final.ipynb        # QLoRA 560M
    └── cf-bloomz-3b-lora-final.ipynb          # QLoRA 3B

πŸ€— Models on HuggingFace

31 model checkpoints hosted at huggingface.co/dovanminh100104

πŸ“¦ Full Model List (click to expand)

BLOOMZ-560M Full Fine-Tuning (8 models)

Checkpoint HuggingFace ID
After Task 1 (SIMP) dovanminh100104/cf-experiment-v4-baseline-simp
After Task 2 (EMDG) dovanminh100104/cf-experiment-v4-baseline-emdg
After Task 3 (InqQG) dovanminh100104/cf-experiment-v4-baseline-inqqg
After Task 4 (EXP) dovanminh100104/cf-experiment-v4-baseline-exp
After Task 5 (HGen) dovanminh100104/cf-experiment-v4-baseline-hgen
Mixing Strategy dovanminh100104/cf-experiment-v4-mixing-final
Curvature Strategy dovanminh100104/cf-experiment-v4-curvature-final
Freezing Strategy dovanminh100104/cf-experiment-v4-freezing-final

BLOOMZ-560M QLoRA 4-bit (4 models)

Checkpoint HuggingFace ID
Baseline (5 tasks) dovanminh100104/cf-lora-560m-final
Mixing Strategy dovanminh100104/cf-lora-560m-mixing-final
Curvature Strategy dovanminh100104/cf-lora-560m-curvature-final
Freezing Strategy dovanminh100104/cf-lora-560m-freezing-final

See README_models.md for the complete list of all 31 models.

Quick Load Example

# Full Fine-Tuned model
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("dovanminh100104/cf-experiment-v4-baseline-hgen")
tokenizer = AutoTokenizer.from_pretrained("bigscience/bloomz-560m")

# QLoRA adapter
from peft import PeftModel
base = AutoModelForCausalLM.from_pretrained("bigscience/bloomz-560m")
model = PeftModel.from_pretrained(base, "dovanminh100104/cf-lora-560m-final")

πŸ› οΈ Tech Stack

Category Technologies
Training PyTorch, HuggingFace Transformers, PEFT, BitsAndBytes
Quantization QLoRA (NF4 4-bit)
Compute Kaggle GPU T4 (15.6GB VRAM)
Demo Backend FastAPI, Uvicorn
Demo Frontend Vanilla JS, CSS3 (Glassmorphism UI)
Visualization Matplotlib, Seaborn
Model Hosting HuggingFace Hub (31 checkpoints)

πŸ“š References

  • Kirkpatrick et al., "Overcoming catastrophic forgetting in neural networks", PNAS 2017
  • Kornblith et al., "Similarity of Neural Network Representations Revisited", ICML 2019
  • Hu et al., "LoRA: Low-Rank Adaptation of Large Language Models", ICLR 2022
  • Dettmers et al., "QLoRA: Efficient Finetuning of Quantized LLMs", NeurIPS 2023

πŸ‘₯ Authors β€” Group 04

Name Role
Đỗ VΔƒn Minh Researcher & Developer
Nguyα»…n Thα»‹ TuyαΊΏt Lan Researcher & Developer

⭐ If you find this project helpful, please consider giving it a star!

About

Evaluating and Mitigating Catastrophic Forgetting in BLOOMZ LLMs with Interactive Demo, 31 Model Checkpoints, and Mechanistic Analysis

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages