PriViT: Vision Transformers for Private Inference

Naren Dhyani, Jianqiao Cambridge Mo, Patrick Yubeaton, Minsu Cho, Ameya Joshi, Siddharth Garg, Brandon Reagen, Chinmay HegdeTMLR 2024

Abstract

The Vision Transformer (ViT) architecture has emerged as the backbone of choice for state-of-the-art deep models for computer vision applications. However, ViTs are ill-suited for private inference using secure multi-party computation (MPC) protocols, due to the large number of non-polynomial operations (self-attention, feed-forward rectifiers, layer normalization). We develop PriViT, a gradient-based algorithm to selectively Taylorize nonlinearities in ViTs while maintaining their prediction accuracy. Our algorithm is conceptually very simple, easy to implement, and achieves improved performance over existing MPC-friendly transformer architectures in terms of the latency-accuracy Pareto frontier.

The Privacy Bottleneck in Vision Transformers

Deep learning models are increasingly deployed in cloud environments, creating a tension between the need for high-performance inference and the necessity of data privacy. Private Inference (PI) using Secure Multi-Party Computation (MPC) offers a solution, allowing users to process sensitive data without revealing it to the provider, while the provider keeps their model weights confidential.

While Vision Transformers (ViTs) represent the current state-of-the-art in computer vision, they are notoriously "MPC-unfriendly." MPC protocols handle linear operations like additions and multiplications with relative efficiency. However, the nonlinear operations central to ViTs—specifically GELU activations, Softmax, and Layer Normalization—require expensive cryptographic protocols such as Garbled Circuits.

Cost breakdown of non-linear operations in ViT. The pie chart shows that GeLU and Softmax dominate the computational cost, while the bar chart illustrates that expensive exponential (exp) and division (div) operations are the primary drivers of this overhead.

A standard ViT-Base model contains hundreds of thousands of these operations. As shown in the cost analysis, the exponential and division operations required for Softmax and GELU lead to massive latency and communication overhead, making standard ViTs impractical for real-time private use. PriViT addresses this by "linearizing" or "Taylorizing" these models through a selective, gradient-based approach.

Switched Taylorization: A Surgical Approach

Rather than manually redesigning a transformer architecture from scratch, PriViT utilizes a technique called Switched Taylorization. The authors take a pre-trained ViT and surgically introduce learnable switches for every nonlinearity:

  • GELU Replacement: Each GELU unit is replaced by a weighted combination of the original GELU and a linear identity function: $c_i \text{GELU}(x_i) + (1 - c_i)x_i$.
  • Softmax Replacement: Each row-wise Softmax is replaced by a combination of the original Softmax and a "Squared Attention" mechanism (an unnormalized quadratic kernel): $s_i \text{Softmax}(X_i) + (1 - s_i) \text{SquaredAttn}(X_i)$.

The Training Process

The optimization follows a three-stage pipeline:

  1. Sparsity-Promoting Loss: The model is trained using a standard cross-entropy loss augmented with an $\ell_1$-penalty on the switch variables ($c_i, s_i$). This pressure encourages the optimizer to set as many switches to zero as possible, effectively choosing the "cheap" polynomial approximation over the expensive original operation.
  2. Knowledge Distillation (KD): To mitigate accuracy loss during linearization, a standard "teacher" ViT guides the "student" model.
  3. Binarization: Once the target "nonlinearity budget" is reached, the switches are frozen to 0 or 1, and the remaining model weights are fine-tuned to recover any lost performance.

Key Insights: Redundancy in Nonlinearities

One of the most significant findings of the PriViT research is that the vast majority of nonlinear operations in a ViT are superfluous for maintaining accuracy. The algorithm can remove nearly 83% of GELUs and 97% of Softmax operations with less than a 0.5% drop in accuracy on CIFAR-100.

Interestingly, the distribution of these remaining nonlinearities is non-uniform. Unlike convolutional networks, where later layers are often prioritized for linearization, PriViT tends to preserve nonlinearities in the earlier layers of the Transformer. This suggests that the initial feature extraction phase in ViTs is more sensitive to the loss of complex activations than the later stages of global information processing.

Performance and Pareto Frontiers

PriViT establishes a new state-of-the-art Pareto frontier for the latency-accuracy tradeoff in private Transformer inference. By using a conceptually simpler gradient-based pruning approach rather than complex Neural Architecture Search (NAS), PriViT achieves superior results across multiple benchmarks.

Accuracy vs. Latency Pareto frontier on CIFAR-10 and CIFAR-100. PriViT (orange line) consistently outperforms existing methods like MPCViT and MPCViT+, providing higher accuracy at lower latency levels.

Key Results Include: * TinyImageNet: Achieved a 5.77× speedup compared to the previous state-of-the-art (MPCViT) at an isoaccuracy of ~64%. * CIFAR-10/100: Achieved speedups of 1.14× and 1.05× respectively at high accuracy levels. * Training Efficiency: PriViT requires roughly 50% fewer training epochs than NAS-based approaches to reach comparable accuracy, making it a more practical tool for developers.

Limitations and Future Directions

While PriViT significantly reduces the cost of Softmax and GELU, Layer Normalization remains a challenge. Taylorizing LayerNorm often introduces training instability, so the current version of PriViT leaves these operations intact. Additionally, while the method is highly effective for image classification, its performance on other tasks like object detection or its application to Large Language Models (LLMs) remains an open area for research. Future work will likely focus on stabilizing the Taylorization of Layer Normalization to further push the boundaries of private inference latency.

Summary updated

BibTeX
@article{dhyani2024privit,
  author = {Naren Dhyani and Jianqiao Cambridge Mo and Patrick Yubeaton and Minsu Cho and Ameya Joshi and Siddharth Garg and Brandon Reagen and Chinmay Hegde},
  title = {{PriViT: Vision Transformers for Private Inference}},
  journal = {Accepted by TMLR},
  year = {2024},
  url = {https://openreview.net/forum?id=3CmPvcYJnm},
}
Figure