Home

Awesome

Open In Colab arXiv Generic badge

Adversarial Pruning: A Survey and Benchmark of Pruning Methods for Adversarial Robustness :scissors: :shield:

Recent work has proposed neural network pruning techniques to reduce the size of a network while preserving robustness against adversarial examples, i.e., well-crafted inputs inducing a misclassification. These methods, which we refer to as adversarial pruning methods, involve complex and articulated designs, making it difficult to analyze the differences and establish a fair and accurate comparison. In this work, we overcome these issues by surveying current adversarial pruning methods and proposing a novel taxonomy to categorize them based on two main dimensions: the pipeline, defining when to prune; and the specifics, defining how to prune. We then highlight the limitations of current empirical analyses and propose a novel, fair evaluation benchmark to address them. We finally conduct an empirical re-evaluation of current adversarial pruning methods and discuss the results, highlighting the shared traits of top-performing adversarial pruning methods, as well as common issues.

Authors: Giorgio Piras (University of Cagliari, University of Roma La Sapienza), Maura Pintor (University of Cagliari), Ambra Demontis (University of Cagliari), Battista Biggio (University of Cagliari), Giorgio Giacinto (University of Cagliari), Fabio Roli (University of Cagliari, University of Genova)

For further details, please refer to our paper

Main idea

Play with the notebook :video_game:

Interactive Plot

Open our Google Colab, select the models you want to compare, and analyze the security curves!

Hands-on :test_tube:

To clone our repo, copy and paste this command

git clone https://github.com/pralab/AdversarialPruningBenchmark

Test a pruned model already loaded in the benchmark :hammer_and_wrench:

To test a pruned model that is available at our leaderboard, one must specify the AP method, the architecture, the dataset, the structure, and the sparsity. Then, the model can be loaded and tested, and additionally security curves can be plotted!

from utils.utils import load_model, model_key_maker
from utils.plots import plot_sec_curve
from utils.test import test_model_aa, test_model_hofmn
from taxonomy.utils import load_ap_taxonomy

ap = "HYDRA_Sehwag2020Hydra"
arch = "resnet18"
ds = "CIFAR10"
struct = "weights"  # or filters, channels
sr = "90"

# get a unique model key
model_key = model_key_maker(ap_method=ap,
                            architecture=arch,
                            dataset=ds,
                            structure=struct,
                            sparsity_rate=sr)

# get model and distances given their unique key
model = load_model(model_key=model_key)
distances = load_distance(model_key=model_key)

# test the model 
clean_acc, rob_acc_aa = test_model_aa(model, dataset=ds, data_dir='my_datadir/CIFAR10', device='cuda:0')
rob_acc_hofmn, _ = test_model_hofmn(model, model_key=model_key, dataset=ds, data_dir='my_datadir/CIFAR10', device='cuda:0', loss='DLR', optimizer='SGD', scheduler='CALR', get_distances=False)

# plot security curve (you can compare even more models together)
names = [model_key]  # add a name for each model to appear in the legend
plot_sec_curve(distances, names, title=model_key+'DLR_SGD_CALR', save=False)

print(f'Model {model_key} clean accuracy: {clean_acc}')
print(f'Model {model_key} AA robust accuracy: {rob_acc_aa}')
print(f'Model {model_key} HOFMN robust accuracy: {rob_acc_hofmn}')
print(f'Within the taxonomy, here are the AP entries: {load_ap_taxonomy(ap)}')

Evaluate your local model :microscope:

If you instead want to test your local model with AutoAttack and HO-FMN, follow this code after cloning the repo through:

from utils.utils import model_key_maker
from utils.plots import plot_sec_curve
from utils.test import test_model_aa, test_model_hofmn
from your_model.arch import arch

# load your local model
local_model = arch() 
local_model.load_state_dict(torch.load("your_model_state_dict"))
model_key='my_model'

# test the model 
clean_acc, rob_acc_aa = test_model_aa(local_model, dataset='CIFAR10', data_dir='my_datadir/CIFAR10', device='cuda:0')
rob_acc_hofmn, distances = test_model_hofmn(model=local_model, model_key=model_key, dataset='CIFAR10', data_dir='my_datadir/CIFAR10', save_dist_path='my_path', device='cuda:0', loss='DLR', optimizer='SGD', scheduler='CALR', get_distances=True)

print(f'Clean accuracy: {clean_acc}')
print(f'AA robust accuracy: {rob_acc_aa}')
print(f'HOFMN robust accuracy: {rob_acc_hofmn}')

# plot security curve 
names = ['my_model']
plot_sec_curve(distances, names, title='local_model_SecCurve', save=False)

Contributing to the benchmark :hugs:

We welcome AP authors wishing to see their AP taxonomized and benchmarked!

Important reminder on contributing.

Please note: diversity is fundamental to assess your AP validity! Therefore, we specify that each AP author is required to load at least 3 checkpoints to guarantee a minimum acceptable starting level. The number of three checkpoints equals to one architecture/dataset/structure pair and the 3 corresponding sparsities (i.e., 90%, 95%, and 99% for US; 50%, 75%, and 90% for S). However, we encourage authors to always load the complete suite of models, which would guarantee a more complete and reliable validation of the new AP method. Therefore, you are always encouraged to load 12 (for one structure) checkpoints corresponding to the two architectures (ResNet18 and VGG16), the two datasets (CIFAR10 and SVHN), and the three sparsities determined by the used structure (50-75-90 if S, 90-95-99 if US)!

Contributing to the benchmark is simple and requires just three steps:

STEP 1: New Taxonomy entry. Compile the taxonomy of your AP method in our Google Drive form. This will automatically process your AP and send you a corresponding JSON entry via email.

STEP 2: Run evaluation. Clone the AP repo and evaluate the checkpoints as follows:

import torch
from utils.utils import model_key_maker, load_model
from utils.test import benchmark
# load your architecture
from your_models.arch import arch

# load your local model
local_model = arch() 
local_model.load_state_dict(torch.load("your_model_state_dict"))

# get a unique model key
model_key = model_key_maker(ap_method='ap_key', # first entry of json file
                            architecture='resnet18', # or vgg16
                            dataset='CIFAR10', # or SVHN
                            structure='weights', # if US; or filters and channels if S
                            sparsity_rate='90') # or any other sparsity

# prints the results (that you should keep) and it saves the distances pickle
save_dist_path='my_path'
benchmark(local_model, model_key, data_dir, save_dist_path, device)  

# check architecture compliance 
model = load_model(model_key='base_resnet18', normalization=False)  # or base_vg16
model.load_state_dict("your_model_state_dict", strict=True)


The benchmark method will test your model using both AA and HO-FMN, and will print the AA and HO-FMN evaluation results. By checking the compliance, you can understand if your local model can be loaded into the available base VGG16 and ResNet18 implementation. If not, this should be indicated in Step3.

STEP 3: Open the issue. The last step consists in loading the JSON Entry sent via email and the output of the benchmark method into the dedicated issue, New AP method. Specifically, for each model, you are required to put the results and model key given by the benchmark method, and the corresponding checkpoint and distances Google Drive link (yes, it has to be on your gdrive). In addition, you are required to indicate if your checkpoints require data normalization, and if they cannot be loaded into the base model implementation. If your checkpoint does not fit the available implementation, please indicate why (you will be just required to add the network implementation, if necessary).

Taxonomy

A-Methods Pruning After Training

NamePretrainingFinetuning1S/ITS/USL/GCriterion
RADMMATAT1SS, USLSOLWM
HYDRAATAT1SUSLLIS
HeraclesATAT1SS, USGLIS
HARPATAT1SS, USGLIS
PwoAATKD1SUSLSOLWM
MADATAT1SUSGLIS
Sehwag19ATATITS, USLLWM
RSRAT + CNIn.s.1SUSGRELWM
BNAPATAT1S, ITS, USGLIS
RFPATAT1SSLHGM
Deadwoodingn.s.KD + AT1SUSGSOLWM
FREATATITSGLIS
Luo23ATAT1SSLLIS
SR-GKPNTNT1SSLLIS
FSRPATAT1SSLLIS

B-Methods Pruning Before Training

NamePruning StepTraining Step1S/ITS/USL/GCriterion
Cosentino19ATATITUSGLWM
Li20ATAT1SUSGLWM
Wang20ATATITUSGLWM
RSTATNone1SUSLLIS
RobustBirdATATITUSGLWM
AWTATATn.s.USn.s.LWM

D-Methods Pruning During Training

NameTraining StepS/USL/GCriterion
TwinRepATS, USGRELWM
BCS-PATUSL, GBCS
DNRATS, USGSOLWM
InTrainATS, USGLIS
FlyingBirdATUSGLWM

Legend

For a detailed description, please refer to our paper.

Leaderboard

CIFAR-10 US pruning

NameResNet18 90%ResNet18 95%ResNet18 99%VGG16 90%VGG16 95%VGG16 99%
RADMM80.54/43.6879.33/42.5671.17/37.2174.76/39.9272.67/38.4457.69/31.30
HYDRA76.74/43.3476.16/42.4572.21/38.8078.31/43.8176.58/42.6170.59/35.56
HARP83.38/45.4083.38/45.6983.11/45.5080.70/42.8380.26/41.2179.42/42.02
PwoA83.29/45.3582.58/41.2576.33/28.9567.50/30.4965.85/26.3958.36/15.43
MAD73.67/41.1070.70/38.9658.90/29.2672.09/39.8070.45/38.1043.35/25.90
Li2077.39/41.3173.54/39.2959.42/31.3775.66/39.2669.27/38.2758.49/31.24
RST60.92/14.3156.93/16.7648.90/15.1675.81/26.9971.45/23.9464.16/14.80
RobustBird78.16/43.3579.27/44.6069.36/37.0873.95/41.6276.16/41.8067.94/37.46
TwinRep76.37/42.9373.19/41.4764.97/36.1075.36/41.8474.16/40.8169.95/38.49
FlyingBird80.69/46.4977.42/46.1075.40/42.0276.72/43.9575.22/44.4772.49/40.49

CIFAR-10 S pruning

NameResNet18 50%ResNet18 75%ResNet18 90%VGG16 50%VGG16 75%VGG16 90%
RADMM79.27/42.6878.81/40.7970.53/37.3074.58/39.6770.51/37.7458.58/31.79
HARP77.38/42.7380.06/42.0977.88/41.5976.70/40.0173.61/39.1466.45/35.62
PwoA83.44/44.7981.77/37.8576.41/28.5666.33/30.1563.36/24.9157.71/18.39
TwinRep79.90/45.5879.37/45.2178.41/44.3077.65/43.1377.58/42.7776.26/42.14

SVHN US pruning

NameResNet18 90%ResNet18 95%ResNet18 99%VGG16 90%VGG16 95%VGG16 99%
RADMM---62.25/44.4052.24/42.9964.91/37.91
HYDRA90.95/44.1289.91/45.2985.71/34.2087.89/45.8587.95/44.5780.85/40.30
HARP92.96/45.3992.75/45.9593.38/34.4292.69/44.0092.25/44.1790.60/44.36
PwoA92.41/42.6692.21/39.5090.05/29.5889.33/38.9589.08/35.2084.47/21.46
MAD---89.42/37.4686.40/24.90-
Li2089.95/43.6255.04/19.9836.71/13.0953.69/26.3148.24/20.3945.88/14.56
RST79.89/34.1574.90/31.9461.55/25.3588.74/43.9987.64/41.9188.42/41.25
RobustBird91.00/46.2390.18/47.2686.12/42.6289.04/42.8188.24/41.64-
TwinRep88.90/46.7288.59/47.1685.09/43.4487.22/45.5489.70/44.3386.03/43.55
FlyingBird92.60/39.8191.14/47.4392.15/41.8091.05/49.0491.12/49.9490.03/48.80

SVHN S pruning

NameResNet18 50%ResNet18 75%ResNet18 90%VGG16 50%VGG16 75%VGG16 90%
RADMM------
HARP91.72/45.8292.07/46.8091.03/45.2591.53/44.1089.06/42.4587.89/39.25
PwoA92.56/41.6892.61/38.6991.42/31.6989.16/39.0989.22/33.8987.17/24.55
TwinRep90.71/37.3388.71/45.2885.44/45.1089.91/45.8287.10/43.2689.61/44.83

Citation

@article{piras2024adversarialpruningsurveybenchmark,
      title={Adversarial Pruning: A Survey and Benchmark of Pruning Methods for Adversarial Robustness}, 
      author={Giorgio Piras and Maura Pintor and Ambra Demontis and Battista Biggio 
      and Giorgio Giacinto and Fabio Roli},
      journal={arXiv preprint arXiv:2409.01249},
      year={2024},
}

Contact

Feel free to contact us about anything related to our benchmark by creating an issue, a pull request or by email at giorgio.piras@unica.it.