This repository contains the official implementation and reproduction scripts for "Causal Circuit-Guided Pruning: A Principled Framework for Functionality-Preserving Compression of Transformers".
We introduce CC-Prune, a method that identifies and protects causally important computational circuits via activation patching, allowing for high-sparsity model compression without catastrophic performance degradation. This framework is compared against state-of-the-art baselines such as Wanda.
.
├── Dockerfile_CWP # Docker configuration for the experimental environment
├── casual_pruning_execution.sh # Main execution script (Builds Docker & runs experiments)
├── casual_active_scoring.py # [Step 1] Calculates causal importance via Activation Patching
├── casual_active_pruning.py # [Step 2] Performs CC-Prune using scores from Step 1
├── casual_active_visualize.py # [Step 3] Generates heatmaps and score plots
├── casual_wanda_scoring.py # [Baseline Step 1] Calculates Wanda importance scores
├── casual_wanda_pruning.py # [Baseline Step 2] Performs Wanda pruning using scores
├── results/ # Directory for output CSVs and PNGs (Mounted to container)
└── README.md # This file
To replicate the experiments, you need a machine with NVIDIA GPUs and the following software installed:
--gpus all)The entire pipeline (environment build, scoring, pruning, and visualization) is automated via the shell script.
Clone the repository:
git clone <your-repo-url>
cd <repo-name>
Run the reproduction script:
bash casual_pruning_execution.sh
causal-pruning using Dockerfile_CWP.casual_active_scoring.py to generate causal importance scores.casual_active_pruning.py to prune the model while protecting the circuit.casual_active_visualize.py to generate figures.casual_wanda_scoring.py to calculate Wanda metrics.casual_wanda_pruning.py for comparison.Note: By default, the script uses GPU 0 (CUDA_VISIBLE_DEVICES="0"). Modify casual_pruning_execution.sh if you need to use different GPUs.
The experiments consist of sequential stages. Scoring must be executed before Pruning for both methods.
casual_active_scoring.pycausal_scores_*.csv.casual_active_pruning.pycasual_active_visualize.pyprotection_L3_H5.png) proving that specific weights are protected.casual_wanda_scoring.pycasual_wanda_pruning.pyAll experimental results, including CSV logs and generated figures, will be saved in the ./results directory.
Key outputs include:
causal_scores_*.csv: Raw importance scores for all components (Generated by scoring step).hybrid_pruning_results_*.csv: Performance metrics of CC-Prune at various sparsity levels.wanda_pruning_results_*.csv: Performance metrics of Wanda pruning.protection_L*_H*.png: Proof of circuit protection mechanism.Note: The filenames in this repository use "casual" for historical consistency, but the methodology refers to "Causal" (Cause-and-Effect).
This repository contains the official implementation and reproduction scripts for "Causal Circuit-Guided Pruning: A Principled Framework for Functionality-Preserving Compression of Transformers".
We introduce CC-Prune, a method that identifies and protects causally important computational circuits via activation patching, allowing for high-sparsity model compression without catastrophic performance degradation. This framework is compared against state-of-the-art baselines such as Wanda.
.
├── Dockerfile_CWP # Docker configuration for the experimental environment
├── casual_pruning_execution.sh # Main execution script (Builds Docker & runs experiments)
├── casual_active_scoring.py # [Step 1] Calculates causal importance via Activation Patching
├── casual_active_pruning.py # [Step 2] Performs CC-Prune using scores from Step 1
├── casual_active_visualize.py # [Step 3] Generates heatmaps and score plots
├── casual_wanda_scoring.py # [Baseline Step 1] Calculates Wanda importance scores
├── casual_wanda_pruning.py # [Baseline Step 2] Performs Wanda pruning using scores
├── results/ # Directory for output CSVs and PNGs (Mounted to container)
└── README.md # This file
To replicate the experiments, you need a machine with NVIDIA GPUs and the following software installed:
--gpus all)The entire pipeline (environment build, scoring, pruning, and visualization) is automated via the shell script.
Clone the repository:
git clone <your-repo-url>
cd <repo-name>
Run the reproduction script:
bash casual_pruning_execution.sh
causal-pruning using Dockerfile_CWP.casual_active_scoring.py to generate causal importance scores.casual_active_pruning.py to prune the model while protecting the circuit.casual_active_visualize.py to generate figures.casual_wanda_scoring.py to calculate Wanda metrics.casual_wanda_pruning.py for comparison.Note: By default, the script uses GPU 0 (CUDA_VISIBLE_DEVICES="0"). Modify casual_pruning_execution.sh if you need to use different GPUs.
The experiments consist of sequential stages. Scoring must be executed before Pruning for both methods.
casual_active_scoring.pycausal_scores_*.csv.casual_active_pruning.pycasual_active_visualize.pyprotection_L3_H5.png) proving that specific weights are protected.casual_wanda_scoring.pycasual_wanda_pruning.pyAll experimental results, including CSV logs and generated figures, will be saved in the ./results directory.
Key outputs include:
causal_scores_*.csv: Raw importance scores for all components (Generated by scoring step).hybrid_pruning_results_*.csv: Performance metrics of CC-Prune at various sparsity levels.wanda_pruning_results_*.csv: Performance metrics of Wanda pruning.protection_L*_H*.png: Proof of circuit protection mechanism.Note: The filenames in this repository use "casual" for historical consistency, but the methodology refers to "Causal" (Cause-and-Effect).