SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Syed Talal Wasim
Mohamed bin Zayed University of AI
Kabila Haile Soboka
David Brooks
Abdulrahman Mahmoud
Gu-Yeon Wei
This paper presents a novel method to enhance the reliability of image classification models during deployment in the face of transient hardware errors. By utilizing enriched text embeddings derived from GPT-3 with question prompts per class and CLIP pretrained text encoder, we investigate their impact as an initialization for the classification layer. Our approach achieves a remarkable  $5.5 \times$  average increase in hardware reliability (and up to  $14 \times$ ) across various architectures in the most critical layer, with minimal accuracy drop ( $0.3\%$  on average) compared to baseline PyTorch models. Furthermore, our method seamlessly integrates with any image classification backbone, showcases results across various network architectures, decreases parameter and FLOPs overhead, and follows a consistent training recipe. This research offers a practical and efficient solution to bolster the robustness of image classification models against hardware failures, with potential implications for future studies in this domain. Our code and models are released at https://github.com/TalalWasim/TextGuidedResilience.
As transistors in hardware shrink in size, they become more susceptible to random bit-flips from environmental factors such as cosmic particle strikes [44], voltage droops [53], manufacturing defects [55], and/or aging effects [36]. This is particularly noticeable at scale, where even small error rates in hardware components can cause data corruptions that affect large-scale corporations such as Google [23] or Meta [13], prompting these corporations to deploy major resources to address the issue [56]. The problem of silent data corruptions, or SDCs, is further exacerbated in safety-critical domains (such as in autonomous vehicles, medical devices, or robotics), where even a few errors can lead to fatal and undesirable consequences.
At the same time, the rise of ML algorithms proliferating data centers and safety-critical domains means that hardware robustness to this particular domain is extremely important. Recent work has shown that as little as a single (non-adversarial) bit flip during a DNN's inference can cause wrong predictions by the model [34]. In the context of a self-driving car, this can potentially lead to consequential downstream decision making which can be fatal, such as accelerating instead of braking (e.g., by classifying a truck as a bird for instance) [34]. Thus, it is imperative to understand and mitigate the effect of hardware bit flips on an executing software application, where our focus here is on vision classification for its broad applicability and importance.
The current state-of-the-art technique to mitigate hardware errors is full modular hardware redundancy. This is the approach taken recently by Tesla in their Full Self-Driving (FSD) chip, where they employ a fully redundant co-processor with additional wiring, logic, and packaging to run two parallel inferences
for comparison (and rerunning on a mismatch) [64]. While this approach is effective in identifying and mitigating errors during inference, the associated  $2 \times$  overhead is excessive and potentially unscalable for many domains which may need to operate under stricter hardware, energy, and cost budgets.
While memory errors can be protected by traditional error-correcting code (ECC) or additional parity bits at a fraction of the cost of full redundancy, errors that occur during computation are more difficult to address at low cost. Further, they are also exceptionally difficult to detect, since they are many times silent and do not cause an application to crash but still result in incorrect outcomes. Recent research at the intersection of ML and silent data corruption (SDC) detection has explored the use of low-cost dynamic range detectors during deployment [7], selective feature-map duplication [40], and inference re-execution [41] to detect and mitigate single-bit flips at run time in order to avoid full modular redundancy while targeting high error coverage. While these techniques have shown promise, they are more reactive in that they target inference, with the objective of hardening a pre-existing model to function in a faulty environment. Instead, in this work, we introduce what we believe is the first training-side technique, with the objective of developing out-of-the-box models that are more resilient against transient bit-flips in hardware.
In this paper, we present a novel software-driven solution to improve hardware reliability in neural networks. Our approach combines textual information from the Contrastive Language-Image Pre-training (CLIP) [49] model with visual information from a traditional classification neural network to strongly attenuate the effect of single-bit hardware errors in the computational components of a model. The proposed method is based on the observation that textual information can often provide useful context to interpret visual data, thereby enhancing the accuracy of error detection and correction. Our experiments show that the combination of textual and visual information can improve the reliability of a neural network's classification layer by up to  $14\times$  compared to traditional error detection and correction techniques, with minimal changes to pre-existing training recipes and their corresponding training accuracy.
The primary contributions of this paper are:
1. Contribution 1: We propose a simple training methodology combining textual and visual information about an image to improve a model's robustness to hardware-based, transient computational errors which can occur during model deployment ( $\S 4$ ).
2. **Contribution 2:** We rigorously evaluate our proposed methodology using both traditional accuracy-based metrics from the ML community, as well as reliability-based metrics from the hardware resiliency community §5. Our results provide a favorable tradeoff, where, on average, a  $0.32\%$  validation accuracy loss on the ImageNet dataset translates to a hardware reliability improvement of up to  $14 \times (\S 6)$ . Furthermore, we show that the  $0.32\%$  average accuracy loss is statistically insignificant by analyzing the statistical distribution of predictions across both the original, unhardened model and our novel, robust model (§7).
3. Contribution 3: We provide a thorough discussion based on state-of-the-art visualization techniques and empirical data to explain why our method performs better, with ablation studies, intuitive explanations, and statistical validation (§7).
2 Scope and Limitations
This work is not about adversarial robustness, but rather focuses on hardware-based fault mitigation and analysis. Two high-level distinctions between these two are that (1) we do not assume a malicious adversary, but rather environmental effects which cause faults to occur in the hardware during the execution of a model [54, 33, 12, 58, 28, 6, 5], and (2) adversarial attacks typically corrupt the input of a model, while we focus on computational errors (i.e., neuron corruptions), which may occur in multiply-and-accumulate (MAC) operations during execution due to environmental- or manufacturing-based effects.
In the context of safety-critical systems and/or large-scale systems, these hardware errors are important to identify and mitigate to avoid data corruption at-scale, or fatally worse outcomes in real-time systems. While we believe the concept of resilience may be similar to adversarial robustness or Out-of-Domain (OOD) reliability (and in fact, our idea to use CLIP stems from this similarity), we focus our evaluation on improving hardware reliability. Exploring the correlation between hardware reliability and these other domain-specific reliability concepts is of particular interest for future work.
Unimodal Vision Models: The AlexNet [31] model, introduced in 2012, was a Convolutional Neural Network (CNN) that gained popularity by winning the ImageNet [10] competition. It was followed by other models like VGG [57], which emphasized smaller filter sizes and deeper networks, and ResNet [20], which addressed the vanishing gradient problem with skip connections, enabling the training of very deep networks. More recent models such as EfficientNet [59], and MobileNet [24] have further improved efficiency and accuracy by utilizing compound scaling and lightweight architectures for mobile devices. However, CNNs have limitations such as limited receptive field and spatial inductive biases. To overcome these limitations, transformer-based approaches have emerged in computer vision. Inspired by the Transformer [61] architecture in natural language processing, the Vision Transformer (ViT) [14] model was proposed. It processes image patches as sequences and achieves competitive performance on various benchmarks. Other studies, like the Swin Transformer [38, 37] and MaxViT [60], have built upon the success of ViTs, focusing on improving accuracy and computational efficiency. Additionally, there are hybrid works that take inspiration from both Transformers and CNNs, such as FocalNets [65], which propose an efficient alternative to the self-attention operator, focal modulation, based on Convolutions. These models are typically trained using a cross-entropy objective. However, they have shown high susceptibility and unreliability to hardware errors [45, 51, 34, 35, 39], such as bit flips in the weights and activations. To ensure trustworthy deployment for real-world applications, it is crucial to establish strong resilience and reliability.
Multi-Modal Vision-Language Models: Advances in Natural Language Processing (NLP) has led to the development of vision-language models like CLIP [49], Align [26], and Florence [66]. These models consist of image and text encoders and are trained using a contrastive approach with extensive image-text pairs. The goal is to establish a shared feature space between visual and textual features, allowing models like CLIP [49] to gain a nuanced understanding of visual concepts. This approach benefits various downstream tasks such as "zero-shot" image classification, semantic segmentation [50, 17, 68], object detection [15], point cloud classification [67], and video recognition [46]. Additionally, CLIP has demonstrated impressive generalization capabilities on out-of-distribution tasks, including evaluations on datasets like ImageNet-A [22], ImageNet-R [21], ImageNet-Sketch [62] and ImageNetV2 [52]. However, training a CLIP model from scratch is prohibitively expensive. To address this, researchers have employed techniques like using enriched text prompts from large language models [48] such as GPT-3 [4] or employing prompting/finetuning methods [70, 69, 27, 46, 63] to enhance performance on out-of-distribution tasks.
The impact of such text-guided classification on hardware resilience and reliability is an unexplored topic in literature. The strong generalization capabilities demonstrated by text-guided classification models like CLIP suggest the potential for improved resilience to hardware errors. By leveraging the semantic supervision provided by text, these models can acquire a nuanced understanding of visual concepts, which may help them to better handle and adapt to errors or inconsistencies in hardware.
Hardware Resilience and Reliability: As NN-based image classification models begin to take off in vision-based tasks (such as for autonomous driving, or AV, systems), their robustness to hardware perturbations has become of paramount importance for practical deployment and government certification [25]. For example, Tesla's FSD uses the simplistic full duplication method to achieve high resilience, effectively allocating double the silicon to detect and correct errors [64]. However, due to the high associated costs of full modular duplication, an open call for cheaper yet equally accurate techniques has surfaced in recent years [45].
Rather than relying on hardware solutions for hardware faults, software-based solutions have risen to prominence due to their comparatively lower overhead in this fast-moving field. Proposed techniques leverage unique insights about the application domain (namely, neural networks) to systematically detect and recover from errors. Selective duplication of feature maps in CNNs [40], value attenuation in the form of range-detectors [7], and temporal re-execution of inferences [41] have all shown to be adept at identifying errors in a low-cost manner, with reasonable guarantees on error coverage.
However, all prior research in the field assumes a model is already trained and ready for deployment and only then does the task of making it more resilient to hardware errors come into play (by using some of the aforementioned techniques above). In contrast to prior work, our focus in this paper is to provide a training routine that generates robust models directly using textual-visual information ( $\S 4$ ). Effectively, our technique is a training-based method for designing robust image classification models, evaluated for its robustness to single-bit, transient hardware errors at run-time.
Figure 1: The proposed Architecture:  $D$  questions for each class (total  $C$ ) are hand-crafted. These are fed to a GPT-3 [4] model, to obtain  $D$  detailed descriptions per class. A CLIP text encoder is used to produce text embeddings, which are averaged across descriptions. The text embeddings initialize a projection layer which is then trained alongside the randomly initialized backbone.
4 Our Approach
Multimodal pretrained models like CLIP [49], which are used for image classification, have demonstrated the ability to learn generalized representations. These models are trained on vast datasets of language-image pairs in a contrastive manner, resulting in impressive zero-shot capabilities and effective transfer learning to various downstream tasks.
Given this strong generalization, we ask the following question: can the generalized representations of these Vision-Language models help improve hardware reliability?. Our method augments the standard training of image classification models by utilizing textual context from the CLIP text encoder, allowing us to improve hardware resilience with minimal train and test time overhead.
We start by providing a brief overview of vision-language pre-training, specifically focusing on CLIP in §4.1. However, our methodology can be applied to other vision-language models that share similarities with CLIP, such as ALIGN and Florence. Following the overview, we provide a detailed explanation of our text-guided classification scheme in §4.2.
4.1 Overview of the CLIP Model
Conventional methods of image classification have traditionally used the common Cross-Entropy loss-based training for a closed-set classification problem [57, 20, 38, 37]. However, recently there has been a trend to employ text supervision for image classification rather than one-hot labels such as major works on contrastive language-image pretraining like CLIP [49]. The CLIP model is composed of two encoders that encode the visual content of images and their corresponding text descriptions, respectively. These encoded representations are then compared using a cosine similarity objective.
4.2 Proposed Text-Guided Classification
Consider an input image  $I \in \mathbb{R}^{H \times W \times 3}$  of spatial size  $H \times W$  with 3 channels Red, Green, and Blue (R, G, and B). A standard image classification model [57, 20, 37] maps the input image to the classification domain  $\mathbb{R}^C$ , where  $C$  is the number of classes. However, it has been shown that such a model is unreliable and susceptible to bit errors [8, 41], especially in the classification layer [43].
To counter this problem we propose our text-guided image classifier which modifies the last layer of the image classification model to incorporate text features. Hence, this modification applies to any image classification model, regardless of the underlying architecture. Given an input image  $I \in \mathbb{R}^{H \times W \times 3}$ , we first map it to a latent dimension  $\mathbb{R}^E$  where  $E$  is the embedding length of the CLIP Text Encoder. We then apply a classification projection  $\mathbf{P}_{class}$  which maps the latent dimension  $\mathbb{R}^E$  to  $\mathbb{R}^C$ . We initialize the projection layer  $\mathbf{P}_{class}$  using features obtained from the CLIP text encoder for each class.
A naive way to obtain the text features would be to simply pass each class name through the text encoder. However, this is less robust to distribution shifts [70], and we argue that it would therefore be less reliable. Instead, we follow [48] and augment the class labels using a large question-answering language model like GPT-3 [4]. We ask GPT-3 a total of  $D$  questions for each class in the total number of classes  $C$ , making a total of  $C \times D$  questions. For each question, GPT-3 outputs detailed text descriptions, forming  $D$  number of descriptions per class, which we then pass through the CLIP text encoder to produce embeddings of shape  $C \times D \times E$ . We then average over the descriptions per class, to form the final embedding tensor of shape  $C \times E$ , where each class  $c \in 1, \dots, C$  has an embedding vector in  $\mathbb{R}^E$ . This tensor is then used to initialize the projections layer  $\mathbf{P}_{class}$ . Figure 1 summarizes our proposed approach.
5 Evaluation Methodology
We evaluate our approach on two fronts: first, the impact of our technique on the classification accuracy of the model; and second, the hardware reliability impact of our new technique.
5.1 Evaluation Infrastructure
For each backbone, we train a baseline model (the default architecture), and our modified classification model on the ImageNet training set. For both methods, we follow the standard PyTorch [47] training recipe. We then report accuracy and resilience on the ImageNet validation set and compare across multiple architecture families. We train our models on  $4 \times$  A100 GPUs and run the training routine for both the original and our modified models to the same number of epochs and with the same hyperparameters as described in the PyTorch Github repository  ${}^{1}$  for a fair comparison. Our results are presented in §6, in Table 1. For the ablation study presented in Table 3, we train each model on  $8 \times$  V100 GPUs.
5.2 Hardware Reliability Evaluation Methodology
To evaluate the reliability of the proposed model compared to the original model, we use the GoldenEye [43] testbed for error analysis. We describe how this testbed works in more detail in this section. Due to the exponentially large number of potential hardware error sites (e.g., a single bit flipping in a random register during any dynamic cycle for any image during inference at deployment time), it is impractical to explore all possible error locations and values for a given error model to perform an exhaustive evaluation of a DNN. Instead, error injection mechanisms are used to statistically evaluate the likelihood of errors propagating and corrupting an application's output [34, 8, 39, 40].
In this work, we use a transient single-bit flip error model for evaluation, a commonly used abstraction for modeling hardware faults [34, 18, 35, 2, 19]. In particular, we focus on errors that occur in activation values (i.e., neurons), during inference. We assume that memory is protected via ECC or parity (which is common in commercial and safety-critical systems [42]), allowing us to focus on computational errors in hardware (i.e., MAC operations).
An error injection experiment involves flipping a single bit in the entire network (i.e., from  $0 \rightarrow 1$  or  $1 \rightarrow 0$ ), and then comparing the final classification of the network with respect to the original, baseline correct output. We use PyTorchFI [39] to perform the random bit flip, and we perform 4096 unique error injection experiments per layer, totaling more than 4.3 million experiments across all our models and corresponding to a  $99\%$  confidence level with less than  $0.23\%$  confidence interval [32].
To measure reliability, we calculate the rate of all errors which led to an image misclassification, as a function of all the injections performed. Recent work [41] has proposed a more accurate metric called  $\Delta$  Loss, which captures the same information as mismatches but converges asymptotically faster. Conceptually, the  $\Delta$  Loss metric calculates the difference in cross entropy (CE) between a fault-free inference and an erroneous inference, rather than purely looking at a binary mismatch. Consequently, it provides more granular information per error injection experiment. We use the  $\Delta$  Loss metric for comparing the reliability of each layer in the network for the original, baseline training routine and our proposed, textual-augmented technique. To gather overall network-level reliability improvement, we average the  $\Delta$  Loss information gathered from each layer, producing a singular value to compare the baseline model and our proposed text-guided model. We note that it is a simple mapping to go
<sup>1</sup>https://github.com/pytorch/vision/tree/main/references/classification
back to the mismatch-based metric and ground this in a hardware-centric FIT-rate, while this work leverages the  $\Delta$  Loss metric for it's drastically faster speed and accuracy [41].
Prior work has shown that the activation values of the final layer of a network are typically the most vulnerable to single-bit perturbation, as this layer directly impacts the final classification [43]. For this reason, we target our technique and analysis on the last layer, in an effort to mitigate errors at this stage. To ensure a fair comparison, we compare the last layer of the baseline model with the weighted average of the last two layers of our proposed model. This is because our proposed technique technically splits the original last layer into two fully connected layers: the latent representation  $(\mathrm{B} \times \mathrm{E})$  and a projection layer  $(\mathrm{E} \times \mathrm{C})$ . We combine these last two layers into a single layer  $(\mathrm{B} \times \mathrm{C})$  for efficiency and a fair head-to-head evaluation during inference (we keep them separate during training for initializing the projection layer).
We further show the necessity of the rich GPT-3 initialization of our method through an ablative study in Table 3. Finally, we provide a qualitative analysis using Ablation-CAM [11] as well as quantitative analysis for per-image inferences in §7 to further validate the benefits and trade-offs of our textual-visual-based approach for improved hardware reliability. We use the concept of the Top2Diff from the hardware reliability literature [41] to build intuitive arguments on the reliability of our model. The Top2Diff metric is simply the difference in classification accuracy between the top inferred class and the second-highest class. A large Top2Diff directly translates to better reliability, as the catalyst required by a single bit flip to overcome and flip the classification from the correct class to a different class is larger.
Our main results across various backbones are summarized in Table 1. For each model backbone, we trained a baseline version using the training recipe provided by PyTorch, followed by our own method trained using the text-guided initialization via GPT-3, again with the same recipe. We used the same set of hyperparameters for both models (detailed hyperparameters are reported in Appendix A). We report the accuracy of the baseline model, the accuracy of our proposed approach, the difference in the number of parameters of the two versions, the difference in FLOPs, and the improvement in reliability on the last layer and across the entire backbone. We observe multiple takeaways in our results, which are described below.