Skip to content

Commit 32ad292

Browse files
authored
update cluster experiments, dataloaders and pruning strategies for vision nets (#128)
## Description <!-- Brief description of the changes --> ## Type of Change - [ ] Bug fix - [ ] New feature - [ ] Breaking change - [ ] Documentation ## Testing - [ ] Tests pass locally - [ ] New tests added (if applicable) ## Related Issues Closes #
2 parents 2e3ac94 + 9b2a2a1 commit 32ad292

201 files changed

Lines changed: 32979 additions & 5745 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ jobs:
4545
4646
- name: Run tests
4747
run: |
48-
pytest tests/ -v --cov=src/alignment --cov-report=xml --cov-report=html --tb=short -ra
49-
48+
pytest tests/ -v --cov=src/alignment --cov-report=xml --cov-report=html --cov-report=term-missing --tb=short -ra
49+
50+
- name: Check coverage threshold
51+
run: |
52+
coverage report --fail-under=25
53+
5054
- name: Upload coverage to Codecov
5155
uses: codecov/codecov-action@v3
5256
with:

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,12 @@ repos:
4646
hooks:
4747
- id: detect-secrets
4848
args: ['--baseline', '.secrets.baseline']
49+
50+
- repo: local
51+
hooks:
52+
- id: fast-tests
53+
name: Fast unit tests
54+
entry: python -m pytest tests/unit/ -x -q -m "not slow and not integration and not gpu"
55+
language: system
56+
pass_filenames: false
57+
always_run: true

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,18 @@ Cross-layer halo analysis tracks downstream dependencies to predict cascade effe
8585
```
8686
alignment/
8787
├── configs/
88-
├── cluster_analysis/ # Cluster-based analysis configs
89-
├── paper/ # Paper experiment configs
90-
└── examples/ # Example configs
88+
| ├── cluster_analysis/ # Cluster-based analysis configs
89+
| ├── paper/ # Paper experiment configs
90+
| └── examples/ # Example configs
9191
├── scripts/
92-
├── run_experiment.py # Main entry point
93-
└── run_analysis.py # Post-hoc analysis
92+
| ├── run_experiment.py # Main entry point
93+
| └── run_analysis.py # Post-hoc analysis
9494
├── src/alignment/
95-
├── analysis/ # Visualization, clustering, cascade analysis
96-
├── experiments/ # Experiment classes
97-
├── metrics/ # Importance metrics
98-
├── models/ # Model wrappers
99-
└── pruning/ # Pruning strategies
95+
| ├── analysis/ # Visualization, clustering, cascade analysis
96+
| ├── experiments/ # Experiment classes
97+
| ├── metrics/ # Importance metrics
98+
| ├── models/ # Model wrappers
99+
| └── pruning/ # Pruning strategies
100100
├── tests/ # Unit tests
101101
└── docs/ # Documentation
102102
```

configs/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ configs/
77
├── template.yaml # Complete template with all options
88
├── unified_template.yaml # Unified format template
99
├── vision_prune/ # Vision model pruning configs
10-
├── resnet18_cifar10_full.yaml
11-
├── resnet18_cifar10_unified.yaml # Unified format version
12-
├── resnet50_imagenet100.yaml
13-
├── vgg16_cifar10_full.yaml
14-
└── mobilenetv2_cifar10_full.yaml
10+
| ├── resnet18_cifar10_full.yaml
11+
| ├── resnet18_cifar10_unified.yaml # Unified format version
12+
| ├── resnet50_imagenet100.yaml
13+
| ├── vgg16_cifar10_full.yaml
14+
| └── mobilenetv2_cifar10_full.yaml
1515
├── prune_llm/ # LLM pruning configs
16-
├── llama3_8b_full.yaml
17-
├── llama3_8b_unified.yaml # Unified format version
18-
├── llama2_7b_full.yaml
19-
├── mistral_7b_full.yaml
20-
└── qwen2_7b_full.yaml
16+
| ├── llama3_8b_full.yaml
17+
| ├── llama3_8b_unified.yaml # Unified format version
18+
| ├── llama2_7b_full.yaml
19+
| ├── mistral_7b_full.yaml
20+
| └── qwen2_7b_full.yaml
2121
└── examples/ # Example configs
2222
├── mnist_basic.yaml
2323
├── resnet_pruning.yaml

configs/examples/cnn2p2_pruning_comprehensive.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ cnn:
8787
# Higher score = more important (keep) when selection_mode="low"
8888
#
8989
# INTERPRETATION GUIDE:
90-
# - rayleigh_quotient: High = aligned with data keep (prune low)
91-
# - conditional_rayleigh_quotient: High = aligned with class-specific data keep (prune low)
92-
# - mi_about_class: High = informative about class keep (prune low)
93-
# - average_redundancy: High = MORE redundant prune (use selection_mode="high" to prune high scorers)
94-
# - activation_l2_norm: High = active neuron keep (prune low)
95-
# - composite_importance: Combines RQ + class_MI - redundancy prune low
96-
# - alignment_minus_redundancy: RQ - R prune low
90+
# - rayleigh_quotient: High = aligned with data -> keep (prune low)
91+
# - conditional_rayleigh_quotient: High = aligned with class-specific data -> keep (prune low)
92+
# - mi_about_class: High = informative about class -> keep (prune low)
93+
# - average_redundancy: High = MORE redundant -> prune (use selection_mode="high" to prune high scorers)
94+
# - activation_l2_norm: High = active neuron -> keep (prune low)
95+
# - composite_importance: Combines RQ + class_MI - redundancy -> prune low
96+
# - alignment_minus_redundancy: RQ - R -> prune low
9797

9898
pruning:
9999
enabled: true

configs/examples/llama2_7b_pruning.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
#
1313
# From SCAR paper Table 5 (Cross-Model Generalization at 50% sparsity):
1414
# ┌─────────────────┬──────────────┬──────────────────┐
15-
# Model Method │ PPL↓ │ Acc.
15+
# | Model | Method | PPLdown | Acc.up |
1616
# ├─────────────────┼──────────────┼───────┼─────────┤
17-
# Llama-2-7B Wanda 19.4 62.3%
18-
# SCAR 13.1 66.8%
17+
# | Llama-2-7B | Wanda | 19.4 | 62.3% |
18+
# | | SCAR | 13.1 | 66.8% |
1919
# └─────────────────┴──────────────┴───────┴─────────┘
2020
#
2121
# EXPECTED RUNTIME: ~6-10 hours on H100
@@ -139,7 +139,7 @@ supernode_summary:
139139
pruning:
140140
enabled: true
141141

142-
sparsity_levels: [0.25, 0.5, 0.75]
142+
sparsity_levels: [0, 0.25, 0.5, 0.75]
143143

144144
selection_modes: ["low", "high"]
145145

configs/examples/llama3_comprehensive_pruning.yaml

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@
77
# This config runs a comprehensive comparison of:
88
#
99
# ┌─────────────────────────────────────────────────────────────────────────┐
10-
# CATEGORY METHOD REFERENCE
10+
# | CATEGORY | METHOD | REFERENCE |
1111
# ├────────────────────┼───────────────────────────────┼────────────────────┤
12-
# ALIGNMENT-BASED rayleigh_quotient (RQ) Our method
13-
# gaussian_mi_analytic (MI) Related to RQ
14-
# average_redundancy Info-theoretic
12+
# | ALIGNMENT-BASED | rayleigh_quotient (RQ) | Our method |
13+
# | | gaussian_mi_analytic (MI) | Related to RQ |
14+
# | | average_redundancy | Info-theoretic |
1515
# ├────────────────────┼───────────────────────────────┼────────────────────┤
16-
# SCAR METRICS scar_loss_proxy Activation + Grad
17-
# (activation+grad) scar_activation_power Raw activation
18-
# scar_taylor First-order term
19-
# scar_curvature Second-order term
16+
# | SCAR METRICS | scar_loss_proxy | Activation + Grad |
17+
# | (activation+grad) | scar_activation_power | Raw activation |
18+
# | | scar_taylor | First-order term |
19+
# | | scar_curvature | Second-order term |
2020
# ├────────────────────┼───────────────────────────────┼────────────────────┤
21-
# SUPERNODE-AWARE supernode_protection_score Protects important
22-
# supernode_connectivity_score Connectivity-based
21+
# | SUPERNODE-AWARE | supernode_protection_score | Protects important |
22+
# | | supernode_connectivity_score | Connectivity-based |
2323
# ├────────────────────┼───────────────────────────────┼────────────────────┤
24-
# GENERALIZED generalized_importance No outlier needed
24+
# | GENERALIZED | generalized_importance | No outlier needed |
2525
# ├────────────────────┼───────────────────────────────┼────────────────────┤
26-
# MAGNITUDE-BASED activation_l2_norm Common baseline
26+
# | MAGNITUDE-BASED | activation_l2_norm | Common baseline |
2727
# ├────────────────────┼───────────────────────────────┼────────────────────┤
28-
# SOTA BASELINES wanda Sun et al. 2023
29-
# sparsegpt Frantar+Alistarh'23
28+
# | SOTA BASELINES | wanda | Sun et al. 2023 |
29+
# | | sparsegpt | Frantar+Alistarh'23|
3030
# └─────────────────────────────────────────────────────────────────────────┘
3131
#
3232
# EVALUATION BENCHMARKS:
@@ -364,32 +364,32 @@ visualization:
364364
# ├── results_YYYYMMDD_HHMMSS.json # All metrics and scores
365365
# ├── experiment.log
366366
# ├── plots/
367-
# ├── pruning/
368-
# ├── pruning_comparison.png # All methods, perplexity
369-
# ├── pruning_comparison_loss.png # All methods, loss
370-
# ├── pruning_comparison_accuracy_mmlu.png # All methods, MMLU
371-
# ├── pruning_comparison_accuracy_*.png # Other benchmarks
372-
# └── pruning_<method>_comparison_*.png # Per-method plots
373-
# ├── histograms/
374-
# ├── histogram_rayleigh_quotient.png
375-
# ├── histogram_scar_loss_proxy.png
376-
# └── histogram_*.png
377-
# ├── scatter/
378-
# ├── scatter_activation_l2_norm_vs_rayleigh_quotient.png
379-
# └── scatter_*.png
380-
# ├── supernode/
381-
# ├── supernode_comparison_*.png
382-
# └── supernode_score_dist_*.png
383-
# ├── supernode_robustness/
384-
# ├── jaccard_heatmap_*.png # Metric overlap heatmaps
385-
# ├── spearman_heatmap_*.png # Score correlation heatmaps
386-
# ├── bootstrap_stability_*.png # Per-neuron stability
387-
# ├── consistency_bars_*.png # Cross-metric consistency
388-
# └── score_scatter_matrix_*.png # Metric pair correlations
389-
# ├── redundancy/
390-
# └── redundancy_heatmap_*.png
391-
# └── scar/
392-
# ├── scar_loss_proxy_layers.png
393-
# └── scar_metrics_heatmap.png
367+
# | ├── pruning/
368+
# | | ├── pruning_comparison.png # All methods, perplexity
369+
# | | ├── pruning_comparison_loss.png # All methods, loss
370+
# | | ├── pruning_comparison_accuracy_mmlu.png # All methods, MMLU
371+
# | | ├── pruning_comparison_accuracy_*.png # Other benchmarks
372+
# | | └── pruning_<method>_comparison_*.png # Per-method plots
373+
# | ├── histograms/
374+
# | | ├── histogram_rayleigh_quotient.png
375+
# | | ├── histogram_scar_loss_proxy.png
376+
# | | └── histogram_*.png
377+
# | ├── scatter/
378+
# | | ├── scatter_activation_l2_norm_vs_rayleigh_quotient.png
379+
# | | └── scatter_*.png
380+
# | ├── supernode/
381+
# | | ├── supernode_comparison_*.png
382+
# | | └── supernode_score_dist_*.png
383+
# | ├── supernode_robustness/
384+
# | | ├── jaccard_heatmap_*.png # Metric overlap heatmaps
385+
# | | ├── spearman_heatmap_*.png # Score correlation heatmaps
386+
# | | ├── bootstrap_stability_*.png # Per-neuron stability
387+
# | | ├── consistency_bars_*.png # Cross-metric consistency
388+
# | | └── score_scatter_matrix_*.png # Metric pair correlations
389+
# | ├── redundancy/
390+
# | | └── redundancy_heatmap_*.png
391+
# | └── scar/
392+
# | ├── scar_loss_proxy_layers.png
393+
# | └── scar_metrics_heatmap.png
394394
# └── checkpoints/
395395

configs/examples/llama3_extended_analysis.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,20 @@ visualization:
192192
# Expected outputs:
193193
# - results/llama3_extended_analysis_YYYYMMDD_HHMMSS/
194194
# ├── metrics/
195-
# ├── layer_metrics.json
196-
# ├── halo_redundancy_results.json
197-
# ├── multi_supernode_results.json
198-
# └── cross_layer_results.json
195+
# | ├── layer_metrics.json
196+
# | ├── halo_redundancy_results.json
197+
# | ├── multi_supernode_results.json
198+
# | └── cross_layer_results.json
199199
# ├── plots/
200-
# ├── halo/
201-
# ├── halo_redundancy_by_depth.png
202-
# ├── halo_redundancy_comprehensive.png
203-
# └── halo_redundancy_heatmap.png
204-
# ├── multi_supernode/
205-
# └── cluster_analysis_*.png
206-
# └── cross_layer/
207-
# ├── cross_layer_redundancy.png
208-
# └── layer_efficiency.png
200+
# | ├── halo/
201+
# | | ├── halo_redundancy_by_depth.png
202+
# | | ├── halo_redundancy_comprehensive.png
203+
# | | └── halo_redundancy_heatmap.png
204+
# | ├── multi_supernode/
205+
# | | └── cluster_analysis_*.png
206+
# | └── cross_layer/
207+
# | ├── cross_layer_redundancy.png
208+
# | └── layer_efficiency.png
209209
# └── evaluation/
210210
# └── benchmark_results.json
211211
# ============================================================================

0 commit comments

Comments
 (0)