Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 20 additions & 221 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,229 +1,28 @@
# Changelog

All notable changes to the Alignment Framework.

## [0.2.0] - 2025-10-03

### Major Release: Information-Theoretic Metrics & Service Layer

This release introduces **intelligent, redundancy-aware pruning** with a complete service layer architecture and three new information-theoretic metrics.

---
## Recent Updates

### Added

#### New Service Layer
- `alignment.services.ActivationCaptureService` - Centralized activation and weight collection
- `alignment.services.NodeScoringService` - Composite importance scoring engine
- `alignment.services.MaskOperations` - Unified pruning mask utilities
- `alignment.services.ActivationData` - Dataclass for captured data
- `alignment.services.CompositeScores` - Dataclass for multi-metric scores

**Impact:** Reduces code duplication by ~40%, cleaner APIs

#### New Information-Theoretic Metrics
- `alignment.metrics.PairwiseRedundancyGaussian` - Per-neuron redundancy measurement
- Computes `R(Y_i, Y_j) = -0.5 * log(1 - ρ²)` for sampled neuron pairs
- Identifies redundant neurons for pruning
- Supports random, nearest, and all-pairs sampling

- `alignment.metrics.SynergyGaussianMMI` - Target-conditional synergy measurement
- Computes `S_MMI(Z; Y_i, Y_j)` using MMI redundancy axiom
- Identifies complementary neuron pairs
- Preserves synergistic features during pruning

**Impact:** Enables redundancy-aware pruning with expected +3-5% accuracy retention

#### Enhanced Existing Metrics
- `alignment.metrics.RayleighQuotient.compute_class_conditioned()` - New method
- Class-conditioned RQ: `RQ(w; Σ_{X|y})`
- Discriminative alignment: `ΔRQ = RQ - E[RQ|class]`
- Identifies task-relevant neurons

**Impact:** Task-aware pruning decisions

#### **Hook Management** 🔒
- `alignment.models.HookManager` - Context-managed hook lifecycle
- `alignment.models.PersistentHookManager` - Long-lived hooks with auto-cleanup
- `BaseModelWrapper.forward_with_activations()` - Safe activation capture
- `BaseModelWrapper.capture_activations_safe()` - Convenience method

**Impact:** Prevents memory leaks in long experiments

#### **Examples** 📖
- `examples/06_redundancy_aware_pruning.py` - Complete workflow demonstration
- Shows all new features in action
- Compares redundancy-aware vs baseline pruning
- Demonstrates ΔRQ analysis

---
- Service layer architecture: `ActivationCaptureService`, `NodeScoringService`, `MaskOperations`
- Information-theoretic metrics: `PairwiseRedundancyGaussian`, `SynergyGaussianMMI`
- Class-conditioned RQ: `RayleighQuotient.compute_class_conditioned()`
- Hook management: `HookManager`, `PersistentHookManager`
- `forward_with_activations()` for safe activation capture

### Changed

#### **RayleighQuotient Improvements**
- Added `regularization` parameter (default: 1e-6) for numerical stability
- Automatic diagonal regularization prevents singular covariance matrices
- Better handling of small batches and edge cases

#### **BaseModelWrapper Enhancements**
- Integrated `HookManager` for automatic cleanup
- Improved activation capture with guaranteed hook removal
- Added `__del__` to ensure cleanup on destruction

#### **Package Version**
- Version bumped: 0.1.0 → 0.2.0

---
- RayleighQuotient: Added regularization parameter for numerical stability
- BaseModelWrapper: Integrated HookManager for automatic cleanup

### Fixed

- **Memory leaks:** HookManager ensures all hooks are properly removed
- **Numerical stability:** Covariance regularization prevents crashes on small batches
- **Hook accumulation:** Context managers prevent hook buildup over multiple captures

---

### Performance

- **Code duplication:** Reduced by ~40% via service layer
- **Memory safety:** 100% - all hooks auto-managed
- **Computation cost:** Redundancy/synergy scale as O(n·K), not O(n²)

---

### Documentation

#### **New Documentation**
- `CODEBASE_IMPROVEMENTS.md` - 40+ pages of architectural recommendations
- `IMPLEMENTATION_ROADMAP.md` - Week-by-week implementation plan
- `unified_manuscript.tex` - Publication-ready research paper
- `PROGRESS_REPORT.md` - Phase 1 progress tracking
- `PHASE2_COMPLETE.md` - Phase 2 achievements
- `SESSION_SUMMARY.md` - Overall session summary
- `IMPLEMENTATION_COMPLETE.md` - Comprehensive overview
- This CHANGELOG

#### **Updated Documentation**
- All new classes have comprehensive docstrings
- Type hints added throughout
- Examples demonstrate new features

---

### Migration Guide

#### **v0.1.0 → v0.2.0**

**Good news:** All changes are **100% backward compatible!**

#### **Existing code continues to work:**
```python
# This still works exactly as before
from alignment.metrics import get_metric
rq = get_metric('rayleigh_quotient')
scores = rq.compute(inputs, weights)
```

#### **Recommended updates (optional):**

**1. Use HookManager for safety:**
```python
# Before
wrapper = BaseModelWrapper(model)
outputs = model(inputs)
activations = wrapper._activation_cache

# After (safer)
wrapper = BaseModelWrapper(model)
outputs, activations = wrapper.forward_with_activations(inputs)
# Hooks auto-cleaned!
```

**2. Use services for cleaner code:**
```python
# Before
# Manual activation capture and metric computation
# (50+ lines of boilerplate)

# After
from alignment.services import ActivationCaptureService, NodeScoringService

capture = ActivationCaptureService(wrapper)
data = capture.capture(input_batch)

scorer = NodeScoringService(metrics={...})
scores = scorer.compute_layerwise_scores(data, targets)
# (5 lines!)
```

**3. Enable redundancy-aware pruning:**
```python
# Before
rq_scores = rq_metric.compute(inputs, weights)
mask = create_mask(rq_scores, amount=0.5)

# After
scores = scorer.compute_composite_scores(
inputs, weights, targets,
include_redundancy=True,
include_synergy=True
)
mask = MaskOperations.create_structured_mask(scores.composite, amount=0.5)
```

---

### Deprecations

**None.** All existing APIs maintained.

---

### Breaking Changes

**None.** Full backward compatibility.

---

## Future Plans

### **v0.3.0 - Planned Features**
- [ ] Backend abstraction (eager/JIT/CUDA)
- [ ] Experiment component extraction
- [ ] Comprehensive test suite (>85% coverage)
- [ ] Recipe gallery with 5-7 examples
- [ ] Performance optimizations

### **v0.4.0 - Planned Features**
- [ ] Transformer-specific metrics
- [ ] LLM support (attention head analysis)
- [ ] Custom CUDA kernels
- [ ] Distributed covariance estimation

---

## Contributors

- Houman Safaai (Architecture, Implementation)
- Andrew Landau (Original RQ implementation)

---

## See Also

- **Documentation:** `docs/` directory
- **Examples:** `examples/` directory
- **Tests:** `tests/` directory
- **Roadmap:** `IMPLEMENTATION_ROADMAP.md`
- **Paper:** `drafts/unified_manuscript.tex`

---

## License

See LICENSE file for details.

---

Version 0.2.0

- Memory leaks from accumulated hooks
- Numerical stability in small batch scenarios

## Core Features

- Rayleigh Quotient and class-conditioned variants
- Mutual Information (Gaussian and binning methods)
- Information-theoretic metrics (redundancy, synergy, PID)
- Similarity metrics (CKA, activation correlation)
- Model wrappers for PyTorch models
- Pruning strategies (magnitude, gradient, alignment-based)
- Service layer for activation capture and scoring
85 changes: 0 additions & 85 deletions docs/testing_report.md

This file was deleted.

Loading