TL;DR
This paper introduces Nimbus, a novel framework for secure two-party inference of Transformer models. Nimbus significantly boosts efficiency by optimizing both the matrix multiplications in linear layers and the approximation of non-linear activation functions, achieving up to a 4.7x speedup over existing methods with minimal accuracy loss. This advancement brings us closer to deploying sensitive AI models in privacy-conscious environments.
What Problem Does This Paper Address?
Transformer models, like BERT, have revolutionized fields from natural language understanding to computer vision. However, their widespread use, especially in sensitive domains like healthcare, raises significant privacy concerns. When a client (e.g., a hospital) wants to use a model owned by a server (e.g., an AI company) for inference on private data, traditional methods of secure two-party computation (2PC) become prohibitively slow. This inefficiency stems from two main bottlenecks: the computationally intensive matrix multiplications in linear layers and the complex non-linear activation functions (like GELU and Softmax). Existing 2PC approaches struggle to balance privacy with performance, often leading to high communication and computation costs.
Methods
Nimbus tackles these challenges with two key innovations:
- Client-Side Outer Product (COP) for Linear Layers: Instead of the traditional server-side inner product, Nimbus shifts computation to the client. This is enabled by the static nature of model weights, allowing the server to send encrypted weights during a one-time setup. The client then uses a novel row-wise encoding to perform homomorphic matrix multiplication via an outer product. This approach significantly reduces communication and computation overhead compared to prior methods that often result in sparse ciphertexts.
- Distribution-Aware Polynomial Approximation for Non-Linear Layers: The paper observes that activation distributions in Transformers are not uniform. Nimbus leverages this by allocating approximation "budget" more effectively, focusing on high-probability input ranges. This allows for the use of lower-degree polynomials and fewer pieces to approximate GELU and Softmax, leading to improved efficiency. Crucially, this approach maintains high accuracy, with an average loss of only 0.08% compared to non-private inference. They also introduce a protocol for efficient conversion between different ring sizes, further optimizing performance.
Datasets
The paper evaluates Nimbus on the widely used BERTbase model. For accuracy evaluation, they use eight datasets from the GLUE benchmark. To obtain input distributions for non-linear functions, they sample sentences from the training dataset until a token count of 512 is reached.
Key Insights and Ideas
- Shifting Computation for Efficiency: The core insight for linear layers is that by leveraging the static nature of model weights, computation can be shifted to the client, enabling a more efficient outer-product based approach. This rebalancing of work is key to overcoming the limitations of previous methods.
- Exploiting Data Distribution for Approximation: The non-uniformity of activation distributions is not just an observation but a powerful tool. By tailoring polynomial approximations to these distributions, Nimbus achieves better efficiency without sacrificing accuracy, a significant improvement over methods that assume uniform distributions.
- Trade-offs in Secure Computation: The paper highlights the inherent trade-offs between privacy, accuracy, and efficiency in secure computation. Nimbus demonstrates that by carefully designing protocols and leveraging model-specific properties, these trade-offs can be significantly improved.
Key Results
- Linear Layers: Nimbus achieves performance improvements of 2.9x to 12.5x for secure matrix multiplication compared to state-of-the-art (SOTA) protocols.
- Non-Linear Layers: The distribution-aware approximation improves performance by 2.9x to 4.0x over SOTA polynomial approximations, with an average accuracy loss of just 0.08%.
- End-to-End Performance: Nimbus improves the overall end-to-end performance of BERTbase inference by 2.7x to 4.7x across various network settings.
- Communication Reduction: The framework reduces communication costs by 60%.
Limitations and Future Work
- Client Computation: While Nimbus significantly reduces overall computation, the client still performs a substantial amount of computation, particularly for non-linear layers. The paper suggests this is acceptable for a "powerful client in MPC" but acknowledges it as a potential area for further optimization.
- Asynchronous Weight Loading: The paper addresses the memory burden of storing encrypted weights by loading them asynchronously. While effective, this introduces complexity in managing weight swapping.
- Future Work: The authors mention that activation multiplication in attention and layer normalization were not specially optimized and could be future work. They also suggest further exploring the potential of their distribution-aware approximation for other non-linear functions.
Summary updated