This experiment demonstrates catastrophic forgetting and how DLOG rescues it using orthogonal gating.
Task A: SST-2 (Sentiment Analysis) 🎭
"sentiment: The movie was wonderful.""Positive"Task B: AG News (News Classification) 📰
"classify: Apple released new phone""Sci/Tech"# Phase 1: Train on Sentiment
Model learns: "wonderful" → Positive ✅
# Phase 2: Train on News
Model learns: "Apple" → Sci/Tech ✅
BUT: Gradients for "Apple" accidentally overwrite neurons storing "wonderful"
Result: Model outputs garbage for "wonderful" 💥 CATASTROPHIC FORGETTING
# Test Phase:
Input: "The movie was wonderful."
Expected: "Positive"
Actual: "World" or "Sci/Tech" ❌ (completely wrong!)
# Phase 1: Train on Sentiment
Slow LoRA learns: "wonderful" → Positive ✅
Fast LoRA: mirrors Slow
# Phase 2: Train on News (THE MAGIC HAPPENS HERE)
1. Fast LoRA wants to learn: "Apple" → Sci/Tech
2. Compute gradient: ∇θ_fast
3. 🛡️ ORTHOGONAL PROJECTION:
- Retrieve Slow LoRA's memory subspace (sentiment knowledge)
- Project: ∇θ_fast⊥ = ∇θ_fast - Proj_Slow(∇θ_fast)
- Translation: "Hey Fast LoRA, learn whatever you want,
EXCEPT don't touch the directions Slow uses for sentiment!"
4. Apply clean gradient: ∇θ_fast⊥
5. EMA consolidation: Slow ← 0.999·Slow + 0.001·Fast
# Test Phase:
Input: "The movie was wonderful."
Expected: "Positive"
Actual: "Positive" ✅ (protected by orthogonality!)
Input: "Apple released new phone"
Expected: "Sci/Tech"
Actual: "Sci/Tech" ✅ (new knowledge learned!)
pip install -r requirements.txt
cd e:\Kuliah\sem8\skripsi\dlog
python run_experiment.py --smoke-test
This runs 5 training steps per task with tiny data to verify:
python run_experiment.py --steps 1000
Expected results:
python run_experiment.py --ablation --steps 1000
Compares 5 variants:
All saved to dlog/results/:
| File | What It Shows |
|---|---|
forgetting_comparison.png | Bar chart: DLOG vs Baseline (FP & FT) |
training_loss.png | Loss curves over training |
leakage.png | Leakage ratio (should drop to ~0 for DLOG) |
performance_matrix.png | Heatmap R[i][j] = accuracy on task j after training task i |
efficiency_table.png | Wall-clock time, forward passes, memory usage |
results_table.txt | Summary metrics (copy-paste to thesis!) |
Edit config.py to adjust:
lora_rank = 8 # LoRA rank (try 4, 8, 16)
lambda_orth = 0.1 # Soft constraint weight
projection_type = "memory_gradient" # or "parameter"
ema_decay = 0.999 # Slow LoRA consolidation rate
replay_ratio = 0.2 # 20% replay in each batch
If you get OOM errors:
# Use T5-Base instead (220M params, ~3-4GB VRAM)
python run_experiment.py --model t5-base
Orthogonal Projection (the core trick):
Given:
- g_fast = gradient of Fast LoRA
- U = orthonormal basis from Slow LoRA (or memory gradients)
Project:
g_fast⊥ = g_fast - U @ U^T @ g_fast
Proof of orthogonality:
<g_fast⊥, U> = <g_fast - U @ U^T @ g_fast, U>
= <g_fast, U> - <U @ U^T @ g_fast, U>
= <g_fast, U> - <g_fast, U @ U^T @ U>
= <g_fast, U> - <g_fast, U> (since U^T @ U = I)
= 0 ✅
EMA Consolidation:
θ_slow ← α·θ_slow + (1-α)·θ_fast (α = 0.999)
This slowly "distills" Fast's new knowledge into Slow's long-term memory.
Problem: ModuleNotFoundError: No module named 'transformers'
Fix: pip install -r requirements.txt
Problem: CUDA out of memory
Fix: Use smaller batch size or T5-base: python run_experiment.py --model t5-base
Problem: Training stuck at 0% for minutes
Fix: First run downloads datasets (~500MB). Wait or check internet connection.
Problem: Leakage not dropping to 0
Fix: This is expected for --projection parameter mode. Use --projection memory_gradient (default).
Happy vibe coding! 🎉
1 commits
Python
100.0%
This experiment demonstrates catastrophic forgetting and how DLOG rescues it using orthogonal gating.
Task A: SST-2 (Sentiment Analysis) 🎭
"sentiment: The movie was wonderful.""Positive"Task B: AG News (News Classification) 📰
"classify: Apple released new phone""Sci/Tech"# Phase 1: Train on Sentiment
Model learns: "wonderful" → Positive ✅
# Phase 2: Train on News
Model learns: "Apple" → Sci/Tech ✅
BUT: Gradients for "Apple" accidentally overwrite neurons storing "wonderful"
Result: Model outputs garbage for "wonderful" 💥 CATASTROPHIC FORGETTING
# Test Phase:
Input: "The movie was wonderful."
Expected: "Positive"
Actual: "World" or "Sci/Tech" ❌ (completely wrong!)
# Phase 1: Train on Sentiment
Slow LoRA learns: "wonderful" → Positive ✅
Fast LoRA: mirrors Slow
# Phase 2: Train on News (THE MAGIC HAPPENS HERE)
1. Fast LoRA wants to learn: "Apple" → Sci/Tech
2. Compute gradient: ∇θ_fast
3. 🛡️ ORTHOGONAL PROJECTION:
- Retrieve Slow LoRA's memory subspace (sentiment knowledge)
- Project: ∇θ_fast⊥ = ∇θ_fast - Proj_Slow(∇θ_fast)
- Translation: "Hey Fast LoRA, learn whatever you want,
EXCEPT don't touch the directions Slow uses for sentiment!"
4. Apply clean gradient: ∇θ_fast⊥
5. EMA consolidation: Slow ← 0.999·Slow + 0.001·Fast
# Test Phase:
Input: "The movie was wonderful."
Expected: "Positive"
Actual: "Positive" ✅ (protected by orthogonality!)
Input: "Apple released new phone"
Expected: "Sci/Tech"
Actual: "Sci/Tech" ✅ (new knowledge learned!)
pip install -r requirements.txt
cd e:\Kuliah\sem8\skripsi\dlog
python run_experiment.py --smoke-test
This runs 5 training steps per task with tiny data to verify:
python run_experiment.py --steps 1000
Expected results:
python run_experiment.py --ablation --steps 1000
Compares 5 variants:
All saved to dlog/results/:
| File | What It Shows |
|---|---|
forgetting_comparison.png | Bar chart: DLOG vs Baseline (FP & FT) |
training_loss.png | Loss curves over training |
leakage.png | Leakage ratio (should drop to ~0 for DLOG) |
performance_matrix.png | Heatmap R[i][j] = accuracy on task j after training task i |
efficiency_table.png | Wall-clock time, forward passes, memory usage |
results_table.txt | Summary metrics (copy-paste to thesis!) |
Edit config.py to adjust:
lora_rank = 8 # LoRA rank (try 4, 8, 16)
lambda_orth = 0.1 # Soft constraint weight
projection_type = "memory_gradient" # or "parameter"
ema_decay = 0.999 # Slow LoRA consolidation rate
replay_ratio = 0.2 # 20% replay in each batch
If you get OOM errors:
# Use T5-Base instead (220M params, ~3-4GB VRAM)
python run_experiment.py --model t5-base
Orthogonal Projection (the core trick):
Given:
- g_fast = gradient of Fast LoRA
- U = orthonormal basis from Slow LoRA (or memory gradients)
Project:
g_fast⊥ = g_fast - U @ U^T @ g_fast
Proof of orthogonality:
<g_fast⊥, U> = <g_fast - U @ U^T @ g_fast, U>
= <g_fast, U> - <U @ U^T @ g_fast, U>
= <g_fast, U> - <g_fast, U @ U^T @ U>
= <g_fast, U> - <g_fast, U> (since U^T @ U = I)
= 0 ✅
EMA Consolidation:
θ_slow ← α·θ_slow + (1-α)·θ_fast (α = 0.999)
This slowly "distills" Fast's new knowledge into Slow's long-term memory.
Problem: ModuleNotFoundError: No module named 'transformers'
Fix: pip install -r requirements.txt
Problem: CUDA out of memory
Fix: Use smaller batch size or T5-base: python run_experiment.py --model t5-base
Problem: Training stuck at 0% for minutes
Fix: First run downloads datasets (~500MB). Wait or check internet connection.
Problem: Leakage not dropping to 0
Fix: This is expected for --projection parameter mode. Use --projection memory_gradient (default).
Happy vibe coding! 🎉
1 commits
Python
100.0%