Nimbus: Secure and Efficient Two-Party Inference for Transformers

Zhengyi Li, Kang Yang, Jin Tan, Wen-jie Lu, Haoqi Wu, Xiao Wang, Yu Yu, Derun Zhao, Yancheng Zheng, Minyi Guo, Jingwen Leng · DOI

TL;DR

This paper introduces Nimbus, a novel framework for secure two-party inference of Transformer models. Nimbus significantly boosts efficiency by optimizing both linear and non-linear layers, achieving up to 4.7x faster inference than existing methods while maintaining high accuracy, making private deployment of large language models more practical.

What Problem Does This Paper Address?

Transformer models, like BERT, are increasingly used for sensitive tasks, raising privacy concerns. Secure two-party computation (2PC) offers a way to perform inference without revealing private data or model details. However, current 2PC methods for Transformers are inefficient, primarily due to the computationally intensive matrix multiplications in linear layers and the complex non-linear activation functions (GELU, Softmax). These inefficiencies stem from the overhead of cryptographic operations, leading to slow inference times and high communication costs, hindering real-world deployment.

Methods

Nimbus tackles these challenges with two main innovations:

  • Client-Side Outer Product (COP) for Linear Layers: Instead of the traditional server-side inner product, Nimbus uses a client-side outer product approach. A key insight is that model weights are static. The server can pre-encrypt weights and send them to the client during a setup phase. This eliminates input communication during the online inference stage. The client then uses a novel row-wise encoding to perform homomorphic matrix multiplication with the encrypted weights. This approach significantly reduces computation and communication costs for linear layers.
  • Distribution-Aware Polynomial Approximation for Non-Linear Layers: For GELU and Softmax, Nimbus leverages the observation that activation distributions in Transformers are not uniform and exhibit regular patterns. Instead of approximating the entire function uniformly, Nimbus allocates more approximation "budget" to high-probability input ranges. This allows for lower-degree polynomials and fewer pieces to approximate the functions, leading to faster secure computation. This distribution-aware approach also enables using smaller rings for computation, further improving efficiency with minimal accuracy loss.

Datasets

The paper evaluates Nimbus using the BERTbase model. For training and evaluating the accuracy of non-linear approximations, they sample sentences from a training dataset until a token count of 512 is reached to capture input distributions. The evaluation is performed on eight datasets from the GLUE benchmark.

Key Insights and Ideas

  • Shifting Computation to the Client: By pre-encrypting weights and having the client perform the outer product, Nimbus shifts a significant portion of the computation to the client, which is often more feasible in a 2PC setting than requiring the server to handle complex homomorphic operations on all inputs.
  • Leveraging Static Weights: The static nature of model weights is a crucial advantage. Pre-encrypting and distributing them once allows for efficient reuse across multiple inference queries, amortizing the setup cost.
  • Input Distribution Matters: For non-linear functions, assuming a uniform input distribution is suboptimal. Understanding and exploiting the actual input distribution allows for more efficient and accurate approximations.
  • Smaller Rings for Efficiency: Using smaller rings for computations, enabled by more efficient approximations, drastically reduces the computational and communication overhead.

Key Results

  • Linear Layers: Nimbus achieves 2.9x to 12.5x performance improvements for secure matrix multiplication compared to SOTA protocols.
  • Non-Linear Layers: The distribution-aware polynomial approximation improves performance by 2.9x to 4.0x, with an average accuracy loss of only 0.08% compared to non-private inference.
  • End-to-End Performance: Nimbus improves the end-to-end performance of BERTbase inference by 2.7x to 4.7x across different network settings (LAN/WAN).
  • Communication Reduction: The framework reduces communication costs by up to 60%.

Limitations and Future Work

  • Client Burden: While Nimbus significantly improves overall efficiency, it does shift more computation to the client. The paper notes that the client's computational overhead remains similar to prior SIP protocols, but it's still a consideration for less powerful clients.
  • Asynchronous Weight Loading: To manage memory, Nimbus employs asynchronous loading of encrypted weights for subsequent layers, overlapping this with communication. This is a practical solution but relies on the network bandwidth being significantly higher than disk I/O.
  • Future Work: The paper mentions that activation multiplication in attention and layer normalization are not specially optimized and leaves them as future work. They also suggest that making the bo coefficient in the GELU protocol public could save a communication round and provide an approximate 8% speedup.

Summary updated

BibTeX
@inproceedings{li2024nimbus,
  author = {Zhengyi Li and Kang Yang and Jin Tan and Wen-jie Lu and Haoqi Wu and Xiao Wang and Yu Yu and Derun Zhao and Yancheng Zheng and Minyi Guo and Jingwen Leng},
  title = {{Nimbus: Secure and Efficient Two-Party Inference for Transformers}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=G7QS68ICPJ},
}
Figure