Privacy-Preserving Large Language Model Inference via GPU-Accelerated Fully Homomorphic Encryption

Leo de Castro, Antigoni Polychroniadou, Daniel EscuderoSafeGenAi @ NeurIPS 2024 · OpenReview

TL;DR

This paper tackles the challenge of running large language models (LLMs) on sensitive data without compromising privacy. They achieve this by developing a GPU-accelerated Fully Homomorphic Encryption (FHE) implementation for LLM inference, resulting in a significant speedup (over 150x) compared to CPU-based FHE while maintaining minimal accuracy loss.

What Problem Does This Paper Address?

As LLMs become increasingly powerful and integrated into various applications, a critical privacy concern arises: how to use these models on sensitive data without exposing it. Often, users must send their queries to a third-party cloud provider to leverage these computationally intensive models. This outsourcing can leak confidential information like intellectual property or personal data. Fully Homomorphic Encryption (FHE) offers a theoretical solution by allowing computations on encrypted data, but two major hurdles have prevented its practical use for LLMs: FHE's incompatibility with complex LLM activation functions and its prohibitively slow performance. This paper aims to overcome these barriers.

Methods

The authors address the two main challenges of FHE for LLMs:

  1. GPU Acceleration for FHE: They extend the popular OpenFHE library with GPU support, specifically optimizing critical operations like bootstrapping. This GPU implementation is presented as the first open-sourced GPU-accelerated FHE extension.
  2. FHE-Friendly Activation Function Approximations: LLMs rely on non-linear activation functions (like GeLU, SoftMax, LayerNorm) that are not directly supported by FHE. The researchers developed and analyzed novel approximations for these functions using low-degree polynomials. They carefully tuned these approximations to balance computational efficiency under FHE with minimal impact on model accuracy.

They modified the HuggingFace transformers library to incorporate these FHE-friendly approximations and then benchmarked the performance and accuracy of this modified GPT-2 model.

Datasets

The paper uses the following datasets for evaluating the accuracy of their FHE-approximated GPT-2 model:

  • Lambada: For evaluating text continuation and next-word prediction.
  • HellaSwag: For testing commonsense reasoning.
  • ARC (AI2 Reasoning Challenge): For assessing multi-step reasoning in question answering.

The LLM used for evaluation is GPT-2 (small variant), trained on WebText.

Key Insights and Ideas

  • GPU is Crucial for FHE Performance: The significant speedup achieved by moving FHE computations to the GPU highlights its necessity for making FHE practical for computationally demanding tasks like LLM inference.
  • Activation Function Approximations are Key: The success hinges on finding the right balance between approximating complex activation functions with simple polynomials and maintaining model accuracy. The paper demonstrates that LLMs are surprisingly robust to these approximations.
  • Bootstrapping is the Bottleneck: The paper emphasizes that bootstrapping, a process to refresh ciphertexts and extend their computational lifespan, is the primary performance bottleneck in FHE, consuming the majority of runtime. Accelerating this operation is therefore critical.
  • Minimal Accuracy Degradation is Achievable: The research shows that with careful approximation, the accuracy of GPT-2 can be preserved to a remarkable degree, making FHE-based inference a viable option without sacrificing too much performance.

Key Results

  • Significant Speedup: The GPU-accelerated FHE implementation of GPT-2 achieves forward pass times over 150x faster than the CPU-based FHE baseline.
  • GPU Acceleration Factor: The GPU implementation of critical FHE functions, including bootstrapping, shows roughly 200x performance improvement.
  • Accuracy Preservation: Benchmarks on Lambada, HellaSwag, and ARC datasets show minimal accuracy/perplexity degradation compared to the original GPT-2 model.
  • Practical Runtimes: The forward pass time is reduced to a range where non-real-time applications become practical, such as document summarization or fine-tuning on private data.

Limitations and Future Work

Limitations:

  • Accuracy vs. Precision Trade-off: The approximations used for activation functions have a direct impact on performance and accuracy. While GPT-2 is robust, other models (e.g., image recognition) might require higher precision, necessitating more complex approximations and potentially more bootstrapping operations.
  • Real-time Chatbots Remain Challenging: While significant progress is made, real-time chatbot applications requiring very low latency are still out of reach with current FHE capabilities.

Future Work:

  • Simplifying Activation Functions: Exploring models with activation functions inherently simpler to approximate with low-degree polynomials could further reduce FHE costs. Replacing SoftMax with a trainable parameter or using Batch Norm instead of LayerNorm are suggested avenues.
  • Broader Applications: The developed GPU-accelerated FHE framework can benefit other privacy-preserving machine learning tasks beyond LLM inference, including fine-tuning models on proprietary data.
  • Optimizing for Other LLMs: The techniques are applicable to other transformer-based LLMs, suggesting future work in scaling these methods to larger models.

Summary updated

Abstract

As large language models (LLMs) become more ubiquitous, security concerns regarding sensitive queries grow. Due to the complexities of deploying these models, LLM evaluation is often outsourced to a third-party cloud, which leaks the clients' queries to this external provider. These queries could contain sensitive information such as intellectual property, medical information, and proprietary data. Protecting this data while maintaining the LLM's functionality is a major privacy challenge. Fully homomorphic encryption (FHE) presents a natural solution to this problem: simply encrypt the query and evaluate the LLM homomorphically on the cloud machine. The result remains encrypted and can only be learned by the client who holds the secret key. There are two barriers to this solution: (1) FHE operations do not easily support the LLM activation functions and (2) FHE implementations remain too slow to evaluate an LLM in a reasonable time. In this work, we address both of these barriers to present a fully encrypted version of GPT-2 with forward pass times over $150\times$ faster than the CPU baseline. This result builds on two main technical contributions. First, we present the first open-sourced implementation of GPU-accelerated FHE as an extension to the popular OpenFHE library, achieving roughly $200\times$ performance improvement for many critical functions including bootstrapping. Second, we present novel and extensive experimental analysis of approximations of LLM activation functions to maintain accuracy while achieving this performance. We run extensive benchmarks using the HellaSwag, LAMBADA and ARC datasets, and our results show that the accuracy/perplexity degradation with respect to ``out-of-the-box'' GPT-2 is minimal.
BibTeX
@inproceedings{castro2024privacy,
  author = {Leo de Castro and Antigoni Polychroniadou and Daniel Escudero},
  title = {{Privacy-Preserving Large Language Model Inference via GPU-Accelerated Fully Homomorphic Encryption}},
  booktitle = {SafeGenAi @ NeurIPS},
  year = {2024},
  url = {https://openreview.net/forum?id=Rs7h1od6ov},
}
Figure