PriViT: Vision Transformers for Fast Private Inference

Naren Dhyani, Jianqiao Cambridge Mo, Minsu Cho, Ameya Joshi, Siddharth Garg, Brandon Reagen, Chinmay Hegde · Submission to ICLR 2024 · Rejected

TL;DR

PriViT is a gradient-based framework that makes Vision Transformers (ViTs) practical for privacy-preserving inference under secure multi-party computation (MPC). By selectively replacing expensive nonlinearities (GELUs and Softmax attention) with low-degree polynomial approximations using learnable sparsity switches, PriViT delivers up to a $6.6\times$ inference speedup over prior state-of-the-art methods while maintaining high task accuracy.

What Problem Does This Paper Address?

Running deep neural networks on sensitive user data via cloud APIs demands Private Inference (PI), typically implemented using two-party MPC. Under protocols such as Delphi, linear and low-degree polynomial operations are computed quickly using secret sharing and homomorphic encryption. However, nonlinear operations (like GELU, Softmax, and LayerNorm) must be evaluated using Yao’s Garbled Circuits (GC), which impose massive communication and latency overheads.

While prior work successfully minimized ReLUs in convolutional networks, applying MPC to Vision Transformers remains challenging. A standard 12-layer ViT-Base contains roughly 726,000 GELUs and 28,000 Softmax operations. Prior ViT methods (notably MPCViT) rely on complex neural architecture search (NAS) pipelines. PriViT addresses this gap with a conceptually simpler, gradient-based linearization strategy that drops non-linearities directly from pre-trained ViTs.

Methods

Rather than executing an expensive architectural search, PriViT introduces continuous relaxation switches into standard ViT modules and optimizes them end-to-end:

  1. Parametric GELU: Each GELU activation is blended with a linear identity connection using a learnable switch $c_i \in [0, 1]$: $$f(c_i, x_i) = c_i \cdot \text{GELU}(x_i) + (1 - c_i) \cdot x_i$$
  2. Parametric Attention via Squared Attention: Softmax requires expensive exponentiation and input-dependent division. PriViT introduces an MPC-friendly Squared Attention alternative and modulates it with a learnable switch $s_i \in [0, 1]$ per row: $$\text{SQUAREDATTN}(X) = \frac{(X W_q W_k^\top X^\top)^2}{N} X W_v$$ $$o = s_i \cdot \text{Softmax}(X_i) + (1 - s_i) \cdot \text{SQUAREDATTN}(X_i)$$
  3. $\ell_1$ Regularization & Homotopy Training: The switches are trained alongside network weights using cross-entropy, knowledge distillation (KD) from the unpruned teacher ViT, and $\ell_1$ sparsity penalties on $c$ and $s$. Penalty coefficients $\lambda_g$ and $\lambda_s$ dynamically scale up if sparsity progress stalls.
  4. Binarization and Fine-Tuning: Once target non-linearity budgets are met, switches are thresholded to $\{0, 1\}$ and frozen, followed by standard fine-tuning.
  5. Post-hoc ReLU Replacement: For additional speedups, surviving GELUs can optionally be replaced by cheaper ReLUs (PriViT-R).

Datasets

The authors evaluate PriViT on standard image classification benchmarks:

  • CIFAR-10 (10 classes, $32 \times 32$ images upsampled to $224 \times 224$)
  • CIFAR-100 (100 classes, $32 \times 32$ images upsampled to $224 \times 224$)
  • Tiny-ImageNet (200 classes, $64 \times 64$ images upsampled to $224 \times 224$)

Pre-trained weights are initialized from ViT-Tiny (and scaled up to ViT-Base in supplementary experiments), pre-trained on ImageNet-21k and fine-tuned on ImageNet-1k. No new datasets were introduced.

Key Insights and Ideas

  • Nonlinearities are heavily redundant: PriViT can prune nearly 83% of GELUs and 97% of Softmax operations on CIFAR-100 with less than a 0.5% drop in classification accuracy.
  • Opposite depth trends compared to CNNs: In convolutional networks, nonlinearities in earlier layers are typically pruned first. In contrast, PriViT consistently chooses to retain GELU and Softmax operations in the early encoder layers while linearizing later layers.
  • Squared Attention dominates other approximations: Compared to uniform or linear attention candidates, pointwise quadratic attention ($\text{SquaredAttn}$) matches original Softmax performance across nearly all budgets while eliminating exponential and division GC costs.
  • Pre-training is critical: Applying the mask optimization on pre-trained checkpoints yields a ~14% accuracy gain compared to training linearized architectures from scratch.

Key Results

  • Tiny-ImageNet: At ~63% isoaccuracy, PriViT achieves a $6.6\times$ latency reduction over MPCViT under the SecretFlow SEMI2k benchmark ($3\times$ to $4.7\times$ reduction measured in theoretical ReLU-equivalent operations).
  • CIFAR-100: PriViT achieves competitive accuracy-latency Pareto curves compared to MPCViT/MPCViT+ (e.g., reaching 78.5% accuracy vs. MPCViT's 77.8% at comparable latencies).
  • Training Efficiency: PriViT requires ~50% fewer training epochs than MPCViT (e.g., ~340 epochs vs. 600 epochs on Tiny-ImageNet, and ~450 vs. 900 epochs on CIFAR-100).

Limitations and Future Work

  • LayerNorm remains unaddressed: The authors report that attempting to Taylorize Layer Normalization introduces severe training instability. Consequently, LayerNorms are kept intact and continue to bottleneck GC execution.
  • Architecture Scope: Evaluation is primarily restricted to standard ViT backbones; extensions to hierarchical vision architectures (e.g., Swin Transformer, DeiT) or cross-attention encoder-decoder models are left for future work.
  • Per-class degradation: While overall accuracy remains stable, fine-grained analysis revealed that select individual classes experience accuracy drops of up to ~30%.

Summary updated

BibTeX
@misc{dhyani2023privit,
  author = {Naren Dhyani and Jianqiao Cambridge Mo and Minsu Cho and Ameya Joshi and Siddharth Garg and Brandon Reagen and Chinmay Hegde},
  title = {{PriViT: Vision Transformers for Fast Private Inference}},
  year = {2023},
  eprint = {2310.04604},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2310.04604},
}
Figure