An Empirical Study of Aegis
Daniel Saragih Paridhi Goel Tejas Balaji Alyssa Li

Sufficent Conditions for the preservation of Polygonal-Connectedness in an arbitrary normed space
    Savvas Andronicou and Emmanouil Milakis
    
=================================================================================================




    Bit flipping attacks are one class of attacks on neural networks with numerous defense mechanisms invented to mitigate its potency. Due to the importance of ensuring the robustness of these defense mechanisms, we perform an empirical study on the Aegis framework. We evaluate the baseline mechanisms of Aegis on low-entropy data (MNIST), and we evaluate a pre-trained model with the mechanisms fine-tuned on MNIST. We also compare the use of data augmentation to the robustness training of Aegis, and how Aegis performs under other adversarial attacks, such as the generation of adversarial examples. We find that both the dynamic-exit strategy and robustness training of Aegis has some drawbacks. In particular, we see drops in accuracy when testing on perturbed data, and on adversarial examples, as compared to baselines. Moreover, we found that the dynamic exit-strategy loses its uniformity when tested on simpler datasets [Done as part of coursework for CSC413 at the University of Toronto.].
    The code for this project is available on GitHub.
[<https://github.com/paridhi26/CSC413-project>]




§ INTRODUCTION


The development of deep neural networks (DNN) has ushered a new era of security and safety applications, but along with it new vulnerabilities. One such concern is the threat of bit flipping attacks (BFAs), in which an adversary can tamper with critical model parameters, and negatively influence the accuracy of prediction. Recognizing the possibility of being attacked in this way, a defense mechanism called Aegis <cit.>, applies a dynamic-exit strategy by attaching extra internal classifiers (ICs) to hidden layers (Figure <ref>), while also performing robustness training (ROB) on the model by simulating BFAs during the fine-tuning of ICs (to be discussed in Section 2).



Motivated by the importance of mitigating such attacks on machine learning models, in this project, we conducted various tests on the Aegis framework. Specifically, our experiments were concerned with:

    
  * Evaluating the test accuracy, accuracy on perturbed test data, and vulnerability to attack when using low-entropy data such as MNIST.
    
  * Evaluating the test accuracy, accuracy on perturbed test data, and vulnerability to attack when trained on a general dataset like CIFAR10 and then fine-tuned[Fine-tuning, in our case, is slightly different from the conventional definition; see Section 2.] on MNIST.
    
  * Evaluating the vulnerability of Aegis on other adversarial attacks such as the generation of adversarial examples <cit.>.




§ BACKGROUND AND RELATED WORK

The threat of BFAs on deep learning models rose to prominence with DeepHammer <cit.>, which aimed to reproduce the well-known Rowhammer attacks on DNNs. Defenses against the attack  generally fall into the categories of model augmentation or integrity verification <cit.>; the defense that we will focus on falls in the former category. For instance, we have defenses such as BIN <cit.> and RA-BNN <cit.> which aims to binarize the model parameters, and in doing so increase the necessary bit flips to disrupt model performance. On the other hand, ModelShield <cit.> uses hash verification to verify the integrity of model parameters. 

The Aegis paper proposes a defense mechanism which is "non intrusive, platform independent, and utility preserving" <cit.>. The goal of the authors in developing a mechanism with these properties arose from the issues and difficulties encountered with previous defense mechanisms, such as having to retrain the entire model or having to change the parameters in the model. As such, Aegis only involves attaching ICs to the original model. Moreover, the training run only involves training the ICs while freezing the base model parameters; this procedure is what we refer to as fine-tuning.

In light of its goal, Aegis adopts two defensive mechanisms. The first involves a dynamic-exit shallow-deep network (DESDN) where samples randomly exit the network early with a uniform probability distribution on the layers. Using the convention of Figure <ref>, we sample q candidates from a uniform distribution over (C_1, …, C_N). We then exit from the first of the candidates which exceed a certain confidence (defined as the highest probability over target classes) threshold τ. Thus, when attackers attempt to target particular layers of the network, they will find it extremely difficult to pinpoint a set of layers that are likely to have the most negative effect on the prediction if attacked. This contrasts with a network without any early exists wherein the most vulnerable bits are those closest to the output classifier.

A second mechanism is robustness training (ROB) wherein the authors deliberately flipped vulnerable bits and trained the early exit classifiers using these features (Figure <ref>). To do so, we take a copy of the clean model M to make a flipped model M. The vulnerable bits are identified through a gradient ranking algorithm. In particular, define ℒ = L_CE(F_final(x), t) where L_CE is the cross-entropy loss and t is the ground-truth label. If we denote the parameter bits of M as B, for each b ∈ B, calculate ∇_b ℒ. Rank the gradients ∇_b ℒ, and choose the top-k such bits to flip (where k is the attack budget). During training we pass the training data and label through M and M, and propagate the sum of their losses through the shared ICs.





§ METHODS




 §.§ Base model training

The focus of our methods is on studying the Aegis mechanisms. To start, as in the original paper, we used ResNet32 <cit.> and VGG16 <cit.> as the base models. We trained four baseline models: ResNet32 on MNIST and CIFAR10 <cit.>, referred to as R-MNIST and R-CIFAR and VGG16 on MNIST and CIFAR10: V-MNIST, V-CIFAR. 

In this initial training run, we froze the parameters of the internal classifiers (C_1, …, C_N) and instead made predictions using the main classifier head F_final. We ran the training loop for 30 epochs on MNIST and 60 epochs on CIFAR. We also used the Adam optimizer with a learning rate of 4 × 10^-4, and a batch size of 128. The output is an array of probabilities over the target classes and the loss used is cross-entropy.



 §.§ Fine-tuning

Subsequently, we endowed these models with the Aegis ICs and further fine-tuned them. In particular, we fine-tuned three types of models: with ROB, without ROB, and with augmented data (without ROB). The augmentation strategy is our contribution motivated by the similarity of ROB to data augmentation strategies (i.e. both attempt to patch up under-represented areas of the learned distribution). The augmentation techniques we applied include rotation, translation, scaling, Gaussian blur, and random erasing. These model types will be distinguished with the suffix -r, -nor, and -aug respectively. In this fine-tuning session, we froze the base model parameters and only allowed gradients to change the internal classifier parameters. 


For the MNIST models, we fine-tuned with the same dataset. However, to accomplish our second objective, for both of our CIFAR models, R-CIFAR and V-CIFAR, we performed this fine-tuning step on the MNIST dataset. Thus, a model such as R-CIFAR-r is one initially trained on CIFAR and then fine-tuned on MNIST with ROB applied. The hyperparameters are the same as in base model training except we use 30 epochs when fine-tuning both MNIST and CIFAR models. 





 §.§ Evaluation

Prior work <cit.> has shown that training on adversarial samples in fact reduces the accuracy on real (non-adversarial) data as it dilutes the learned probability distribution. We highlighted this effect by performing inference on MNIST data which is relatively low entropy as compared to the datasets used in the original paper. In the same vein, we performed inference on perturbed data, where the perturbations are label-invariant (e.g. noising, blurring, and slight rotations). Overall, we made use of three types of evaluation procedures: 

    
  * A baseline evaluation which tests on the fine-tuning dataset while using the early-exit strategy on fine-tuned models.
    
  * A perturbed evaluation where label-invariant transformations are applied to the test data; again early-exit is used.
    
  * An adversarial evaluation where we first attack the model with Proflip <cit.> and observe the attack success rate (ASR).

In each case, we used the MNIST test set of 10000 images.

An additional experiment that we performed aims to test Aegis' robustness to adversarial samples <cit.>. As was shown in <cit.>, methods that directly focus on preventing specific attacks often suffer on other, unrelated attacks. We verified this finding on all of our fine-tuned models by reporting the accuracy on the samples produced by Fast Gradient Sign Methods (FGSM) <cit.> to judge how it fares against non-BFA adversaries. This is a rather simple attack that calculates the gradient with respect to the input data ∇_ xℒ( x,  t) and transforms the input in the direction of the gradient: 
    x_perturbed =  x + ϵsign∇_ xℒ( 𝓍,  𝓉)   for some 0 ≤ϵ < 1.




§ RESULTS




 §.§ Baseline Evaluation

Table <ref> shows the test accuracies we got for the different baseline models when tested on the fine-tuning dataset while using the early-exit strategy on fine-tuned models. All -r, -nor, -aug  were finetuned on MNIST and then were evaluated on MNIST. The basic non-finetuned models R-CIFAR and V-CIFAR were trained on CIFAR and tested on CIFAR. Similarly, the non-finetuned models R-MNIST and V-MNIST were trained and tested on MNIST. Due to the ease of learning MNIST, a pattern is not apparent from the baseline accuracies alone, thus we subsequently consider the perturbed accuracies.






 §.§ Perturbed Data Evaluation

In this evaluation procedure, we perturbed the test data by adding some label-invariant transformations to it before testing. These transformations were random rotations, random translations, random scaling, Gaussian Blur, Gaussian noise and random erasing. 
We evaluated the models on perturbed test data to further pronounce the differences between different fine-tuning settings (-r, -nor, -aug ). This is motivated by the fact that performance on perturbed test examples better demonstrates the ability of a model to learn general features of the data in a particular training set.

The perturbed accuracy column in Table <ref> shows the test accuracies we got for the fine-tuned models (-r, -nor, -aug ) when we tested them on the fine-tuning dataset with label-invariant transformations applied to the test data while using the early-exit strategy. It also shows the accuracies we got for the non-finetuned models (R-MNIST, V-MNIST,  R-CIFAR, V-CIFAR) after similarly testing them on test data with label-invariant transformations applied. Excepting the perturbations, the training and evaluation datasets are the same as those used in Baseline Evaluation.

As expected, the two base (not fine-tuned) CIFAR models  R-CIFAR and V-CIFAR, showed the largest drop in accuracy when evaluated on perturbed CIFAR images compared to R-MNIST and V-MNIST which were evaluated on MNIST which is low entropy. CIFAR images are more complex than MNIST images and perturbation in test data generally affected all CIFAR models more compared to their MNIST counterparts. The only outlier here was R-MNIST-nor which showed lower than expected Perturbed accuracy.

We also expected that the -r models which went through robustness training during the fine tuning process to perform worse than the -nor models which did not go through robustness training since robustness training can dilute the learned probability distribution. This hypothesis was also supported by our evaluation results, with R-MNIST-nor being the only exception as above.

For the -aug fine-tuning setting, we added some of the label-invariant transformations we used to perturb test data to the fine-tuning data. For -aug, the transformation that were applied to the training data while fine tuning were random rotations, random translations, random scaling, Gaussian Blur and random erasing. That is all the transformations from the perturbed test data except Gaussian noise. Since, these models where already fine tuned on perturbed data, their accuracy drop was least significant on the perturbed test data. 



 §.§ Proflip



In this section, we present results for the Proflip <cit.> evaluations. The Proflip procedure inserts a backdoor into the target model by flipping parameter bits such that the prediction of all inputs with the set trigger will result in a pre-specified, incorrect target class. The ASR of Proflip is thus the proportion of trigger examples that manage to fool the model into predicting incorrectly. The paper presents two variants of Proflip: adaptive and non-adaptive <cit.>; we will limit ourselves to the latter.

r8cm
Final ASR values for -r, -nor, and -aug models on Proflip


Model     ASR
R-MNIST-r       22.4 

R-MNIST-nor      34.9

R-MNIST-aug      11.5
V-MNIST-r       14.5 

V-MNIST-nor      11.6

V-MNIST-aug      12.0
  
Model     ASR
R-CIFAR-r       13.4 

R-CIFAR-nor      14.9 

R-CIFAR-aug      12.7
 V-CIFAR-r       14.4 

V-CIFAR-nor      15.2 

V-CIFAR-aug      10.6
  

Table <ref> shows the final ASR for all the models which we attacked with ProFlip (using an attack budget of N_b = 50). As the results indicate, the augmented models tend to have the lowest ASR values (with the exception of the V-MNIST models). The next best class of models tends to be the -r models, while the -nor models are observed to have the highest ASR. Moreover, we tracked the number of exits made in the IC layers for each of the models when attacked with ProFlip. In general, we observed that the Resnet models seemed to have more exits in earlier layers as compared to the VGG models. The results for number of exits per layer for R-MNIST and V-MNIST are shown in Figures <ref>  and <ref>.



















We expected the -nor models to perform the worst out of all the three classes (-r, -aug, and -nor) since they have been trained with the least amount of resistance to bit flip attacks. However, what we do find surprising is that the -aug models perform better than the -r models in most cases. This confirms our hypothesis that augmentation serves a similar role to ROB. The improvement seen in the case of augmentation likely stems from the fact that label-invariant transformations are more informative for learning than the outputs of a flipped model. This increased generality would allow the model to fare better when it encounters an unfamiliar attack pattern. It is also interesting to note the ASR difference between R-MNIST and R-CIFAR models. This indicates that the more general features learned through fine-tuning makes the model more robust. However, the same cannot be said of the VGG models, and so more testing is necessary to verify this trend.

As is depicted in Figures <ref> and <ref>, the R-MNIST and R-CIFAR models tend to have a lower proportion of exits occurring in later layers, as compared to the V-MNIST and V-CIFAR models. We believe that one of the causes for this is that ResNet, owing to its name, uses residual connections as compared to VGG, which suffers from a vanishing gradients issue. MNIST being a low-entropy and "easy" dataset means that strong classifiers such as Resnet will be able to easily obtain very high accuracies within just a few layers. On the other hand, the vanishing gradients issue with VGG is likely to affect the amount of layers it takes for VGG to classify MNIST images with high confidence (as compared to Resnet). 

It is also interesting to note the skew towards earlier layers. As mentioned in the methods, DESDN randomly picks a set of q candidate classifiers and then early exits when it encounters the first classifier that achieves an accuracy above a specific threshold. Thus, it is likely that there is a bias towards the earlier layers, given that MNIST is an easy dataset to learn. If the modelling problem was in fact more challenging, it's likely that later layers are required to exceed the confidence threshold. In turn, this would provide a counter balance to the early-exit bias. Thus, we may conclude that the uniformity in early-exiting which Aegis shows in the original paper <cit.> is in fact contingent on a fragile balancing act between the early-exit bias, and the requirement of later layers to achieve high confidence on predictions.





 §.§ Adversarial Examples




Table <ref> shows the accuracies of the models we trained against various values of ϵ, which denotes the strength of perturbation on input data in FGSM attacks. We observe that the accuracies for the Resnet augmented models tend to be the highest among all other Resnet models. For the CIFAR models, we see that for ϵ = 0.2, the R-CIFAR-aug model achieves an accuracy of 37.6% while R-CIFAR-nor and R-CIFAR-r achieve less than 15% accuracy. The same goes for the MNIST Resnet models, where R-MNIST-aug achieves a very high accuracy of 73.1% on ϵ = 0.2 while the -r and -nor models achieve accuracies below 20%. As for the VGG models, the difference in accuracy doesn't seem to be very high across the models for higher values of ϵ in the case of CIFAR. However, in the case of MNIST, V-MNIST-aug seems to greatly outperform its -r and -nor counterparts, achieving an accuracy of 46.9% for ϵ = 0.2. We observe moreover that the baseline models tend to outperform the -r and -nor models, and are (in most cases) second only to the augmented models [We should also note the caveat that R/V-CIFAR models are tested on CIFAR10.].  







Let a "group" of models denote one the four groups of 4 models as shown in Table <ref> (for example, the first group is the group of all R-CIFAR models). We observe that in 3 out of the 4 groups, the augmented model vastly outperformed its baseline, -r, and -nor counterparts. It was only in the case of V-CIFAR that all models were observed to have a similar accuracy for ϵ = 0.2. Barring the outlier for V-CIFAR, we claim that the results we obtained are to be expected, for the following reasons:

    
  * The -nor models performing worse than the -aug models is expected since the -aug models have been trained with perturbations of the data in mind. The -aug models have been trained to correctly classify noisy and perturbed data, making them robust to a wide range of adversarial inputs. Moreover, the baseline models were expected to outperform the -nor and -r models, since the latter two models have been trained to specifically combat bit-flip attacks. In particular, we note that both the -nor and -r have been fine-tuned on the baseline models for the purpose of preventing bit-flip attacks. This in turn changes the parameters and weights in the classifiers. Thus, a significant portion of robustness that the baseline models possessed to adversarial data was lost when the models were fine-tuned. In the case of the -aug models, although they were trained on top of the -nor models and not the baseline, they regained this robustness as a result of the augmented training. We also observe that in two of the four groups, the -nor models outperform the -r models. In particular, this is observed to be the case in the R-CIFAR and V-CIFAR model groups. Thus, this unusual behavior seems to be a result of differences between the MNIST and CIFAR datasets and not a result of the baseline models (i.e., VGG and Resnet). We hypothesize that this is the result of MNIST being a low-entropy dataset as compared to CIFAR, and thus easier to classify.
    
  * The most intriguing result is that the -aug models perform significantly better than the -r models. Figures <ref> and <ref> showcase this stark difference in accuracies between the two models. While the -r models have been through robustness training, the training has specifically been for the prevention of bit-flip attacks. The use of adversarial examples is a different mechanism of attacking a neural network, it is thus expected that a model that has not built any resistance for this specific type of attack will prove to be vulnerable. The augmented models, however, are more general in the class of perturbations (and hence, attacks) they can resist. 





§ CONCLUSION, LIMITATIONS, AND FUTURE WORK


The results presented indicate that the defensive framework proposed in Aegis possesses significant defensive capabilities as shown by low ASR in Table <ref>, but also some notable drawbacks. From our experiments, we observed that ROB often stunts the model's ability to learn with sufficient generality. For instance, in Table <ref>, we see that -r models generally performed worse than its counterparts. Moreover, the protection ROB provides against BFAs comes at the cost of other adversarial attacks such as FGSM, as shown by its diminished accuracy in Table <ref>. In addition, DESDN also has its downsides. For instance, just by evaluating on low-entropy datasets such as MNIST, we are able to obtain a non-uniform exit distribution, contrary to the uniformity showcased in the original paper. This suggests that if an attacker is aware of the type of datasets a model is tested on, they will have an easier time attacking the model.

Our work also has its limitations. For instance, we claim in Section 4.3 that there is a balancing act between the number of layers needed to achieve the confidence threshold and the early-exit bias of DESDN. Although our experiments showcase this effect, more testing on different datasets is required to verify its validity. Therefore, future work should focus on performing further verification of the effects hinted at by our work. An interesting avenue involves conducting a wider array of adversarial attacks on Aegis, or using new methods to generate adversarial samples. And certainly, future work should also be dedicated to finding improvements to Aegis that mitigates some of the issues brought up in our work.




unsrt







