TL;DR
Researchers have developed EncryptedLLM, a system that allows Large Language Models (LLMs) to process user queries while the data remains fully encrypted. By combining GPU acceleration with clever mathematical approximations, the team achieved a 200x speedup over traditional CPU-based methods, bringing private GPT-2 inference down from hours to just a few minutes.
The Privacy Tug-of-War
As LLMs become central to everyday software, we face a significant privacy dilemma. To get the best results, users must send sensitive data—such as financial records, medical queries, or proprietary code—to a cloud provider. This risks leaking the user's intent and private information. Conversely, model owners want to keep their proprietary weights secret and avoid downloading them to client devices.
Fully Homomorphic Encryption (FHE) is the "holy grail" solution to this problem. It allows a server to perform calculations on encrypted data without ever seeing the underlying information. However, FHE is notoriously slow—often orders of magnitude slower than "cleartext" computation. Porting a massive, computationally hungry LLM to FHE has historically been considered too slow for any practical use.
Overcoming the FHE Bottleneck
The authors tackle the FHE performance bottleneck through a two-pronged approach: hardware acceleration and algorithmic redesigns tailored for FHE.
- GPU-Accelerated CKKS: The researchers extended the popular OpenFHE library to support GPUs (specifically NVIDIA A100s). They focused heavily on accelerating "bootstrapping"—the most expensive part of FHE that "refreshes" an encrypted signal to allow for deeper computation.
- Polynomial Approximations: FHE natively only supports basic additions and multiplications. LLMs, however, rely on complex non-linear functions like GeLU, SoftMax, and LayerNorm. The researchers replaced these with low-degree polynomial approximations that FHE can handle efficiently.
- SoftMax Optimization: Instead of calculating a complex "Max" circuit (which is very expensive in FHE), they used a lookup table approach based on empirical data from the model, significantly reducing the depth of the computation.
- Goldschmidt’s Algorithm: They utilized this iterative method to handle the divisions required in LayerNorm and SoftMax, which are otherwise impossible to perform directly on encrypted values.
Key Insights and Results
To ensure their approximations didn't degrade the model's reasoning capabilities, the authors evaluated three sizes of GPT-2 (Small, Medium, and Large) across eight diverse NLP benchmarks, including HellaSwag, ARC-Easy, PIQA, and SST-2.
- Accuracy Preservation: A major insight from the paper is that LLMs are surprisingly robust to lower-precision math. Even though FHE-friendly approximations are less precise than standard calculations, the model's accuracy on benchmarks barely budged. For example, on the SST-2 sentiment task, the encrypted GPT-2 Small achieved 55.6% accuracy compared to the baseline's 55.1%.
- 200x Speedup: The GPU-accelerated implementation is over 200 times faster than the standard CPU-based OpenFHE baseline.
- Minutes, Not Hours: A full GPT-2 forward pass was reduced from a multi-hour ordeal to just a few minutes.
- Bootstrapping Efficiency: Their GPU implementation can refresh 45 levels of encryption in under one second, whereas a CPU takes several seconds per level. The paper confirms that while linear layers are relatively "cheap" in FHE, the real cost lies in the activation functions and the bootstrapping required to keep the ciphertext clean.
Limitations and Future Work
While a 200x speedup is a massive leap forward, the authors acknowledge several hurdles before this technology becomes ubiquitous:
- Scale: GPT-2 is tiny by modern standards. Scaling this approach to a 70B parameter model like Llama 3 would require significantly more memory and even faster bootstrapping.
- Latency: A "few minutes" per token is excellent for offline tasks like summarizing a document or drafting an email, but it remains too slow for a snappy, real-time chatbot experience.
- Precision Limits: Larger, more complex models might be more sensitive to polynomial approximations than GPT-2, potentially requiring higher-degree (and thus slower) polynomials to maintain accuracy.
The researchers suggest that future work should focus on tighter integration between FHE schemes and specialized hardware, such as ASICs, to close the remaining performance gap with cleartext AI.
Summary updated