Some experiments with a new structured pruning algorithm based on centered kernel alignment. Created for my CSC 561 final project at the University of Rhode Island.
Centered kernel alignment (CKA) provides a measure of similiarity between neural network activations. CKA can be used to compute the relative "damage" caused by pruning a particular neuron via the following procedure.
For each neuron in the layer
- Set the weights of the neuron to zero.
- Compute the layer activations.
- Compute the CKA score between the original and new activations.
- Restore the weights of the neuron.
Initutively, high CKA scores correspond to low damage to network representations. Conversely, low CKA scores correspond to high damage to network representations.
To prune the network, neurons are greedily removed from each layer according to the relative damage scores until all layers have been pruned by
This repository contains the project report, presentation, data and scripts for reproducibility. The hyperparameter search, model training and pruning are all automated.
This project requires Python 3.9.6 or Python 3.10.6. Other Python version might also work but have not been tested. See here for details on installing Python 3.9.6 or Python 3.10.6.
The Python dependencies are listed in requirements.txt. Installation instructions for these dependencies are given below.
Navigate to the root directory of the project and execute the following command.
pip install -r requirements.txtFor convenience, the lib/ folder contains Google's implementation of CKA. The original source code can be found here.
To perform the learning rate hyperparameter search, call main_search.py with a configuration file defining the relevant model architecture and training configuration. For example, the following command performs the hyperparameter search for config/ex1/cka.json with WandB.
python3 main_search.py config/ex1/cka.jsonTo perform the same hyperparameter search with Seawulf, move scripts/search.sh into the root directory and execute the following command.
sbatch search.sh config/ex1/cka.jsonTo train the models, call main_train.py with a configuration file defining the relevant model architecture, training configuration and seeds. For example, the following command trains the models defined by config/ex1/cka.json.
python3 main_train.py config/ex1/cka.jsonThe resulting models will be saved to the models/ folder.
To train the same models with Seawulf, move scripts/train.sh into the root directory and execute the following command.
sbatch train.sh config/ex1/cka.jsonTo prune the models, call main_prune.py with a configuration file defining the relevant model architecture, training configuration, pruning configuration and seeds. For example, the following command prunes the models defined by config/ex1/cka.json. Note that the models must already have been trained with main_train.py.
python3 main_prune.py config/ex1/cka.jsonThe resulting output data will be saved to the output/ folder.
To prune the same models with Seawulf, move scripts/prune.sh into the root directory and execute the following command.
sbatch prune.sh config/ex1/cka.json[1] Jonathan Frankle and Michael Carbin. The Lottery Ticket Hypothesis: Finding Sparse, Trainable Neural Networks. 2019. arXiv: 1803.03635 [cs.LG].
[2] Simon Kornblith et al. Similarity of Neural Network Representations Re- visited. 2019. arXiv: 1905.00414 [cs.LG].