TL;DR
MOAI is a high-performance framework for secure Transformer inference that uses Homomorphic Encryption (HE) to process data without ever decrypting it. By introducing a "rotation-free" design and consistent data packing strategies, it achieves a 50%+ speedup over current state-of-the-art methods, bringing us closer to practical, privacy-preserving AI.
What Problem Does This Paper Address?
When you send a prompt to a cloud-based Large Language Model (LLM), you are essentially handing over your private data to the service provider. For sensitive industries like healthcare or finance, this is a dealbreaker.
Fully Homomorphic Encryption (FHE) is the "holy grail" solution: it allows a server to perform math on encrypted data and return an encrypted result that only the user can unlock. The server never sees the actual text. However, FHE is notoriously slow—often orders of magnitude slower than standard computing.
The primary bottleneck in FHE is the "rotation." Because FHE packs multiple data points into a single "ciphertext" (like a vector), shifting those data points to perform operations like sums or matrix multiplications requires a "rotation" operation, which is computationally expensive and slow. Previous attempts at secure Transformers either required constant, slow format changes between layers or forced developers to retrain models with simplified, "HE-friendly" functions.
Methods
The authors introduce MOAI (Module-Optimizing Architecture), which focuses on three core optimizations to drastically reduce computational overhead:
1. Consistent Matrix Packing
MOAI uses a specific flow of "column packing" and "diagonal packing." By aligning these formats across the entire Transformer architecture, they eliminate the need for expensive format conversions between the Attention, Softmax, and Feed-Forward layers.
2. Rotation-free Softmax and LayerNorm
This is the "aha" moment of the paper. Traditionally, calculating a sum across a ciphertext requires multiple rotations. MOAI aligns the data across different ciphertexts so that the values to be summed occupy the same "slot" position. This allows the server to sum them using simple additions, completely bypassing 2,448 rotations in a standard BERT-base model.
3. Interleaved Batching
To maximize the efficiency of the GPU, MOAI uses a batching technique that packs multiple input sequences into the same ciphertext in a way that remains compatible with their rotation-free matrix multiplication algorithms.
Datasets
The researchers evaluated MOAI using:
- BERT-base-uncased: Fine-tuned on the GLUE benchmark (specifically SST-2, QNLI, and RTE tasks) to test both speed and accuracy.
- LLaMA-3-8B: Used to demonstrate that the framework scales to modern, decoder-only large language models.
Key Insights and Ideas
- The "Rotation Tax" is avoidable: Most researchers focus on making rotations faster; MOAI proves that with clever data alignment, you can often avoid them entirely in non-linear layers like Softmax.
- Plug-and-Play Privacy: Unlike some competitors (like Powerformer) that require "knowledge distillation" or retraining a model to use simpler math, MOAI works with standard, off-the-shelf pre-trained models. This makes it much easier for engineers to adopt.
- Strategic Bootstrapping: In FHE, "noise" builds up with every calculation. Eventually, you must perform a "bootstrapping" operation to reset the noise, which is very slow. MOAI strategically places this operation inside the Softmax module to minimize its impact on the rest of the network.
Key Results
The quantitative improvements are substantial:
- 52.8% Faster than THOR: Compared to the previous state-of-the-art non-interactive framework (THOR), MOAI cut evaluation time by more than half.
- 55.7% Faster than Powerformer: Even when compared to models that were specifically retrained to be HE-friendly, MOAI’s architectural optimizations were more efficient.
- Amortized Speed: On a single NVIDIA H200 GPU, MOAI processes BERT-base at an amortized rate of 2.36 minutes per input.
- Accuracy Preservation: The "encrypted" scores on GLUE tasks were nearly identical to the "plaintext" scores (e.g., 93.8% vs 93.9% on SST-2), proving that the polynomial approximations used for complex math don't degrade performance.
Limitations and Future Work
While MOAI is a massive leap forward, "practical" is a relative term. Taking two minutes to process a single sentence is still too slow for a real-time chatbot.
The authors identify several paths forward:
- Memory Constraints: Large models like LLaMA-3-8B push the limits of GPU memory when using FHE; further work is needed to optimize memory tiling.
- Advanced Inference Techniques: Standard LLM tricks like KV-caching (which saves previous computations) and token pruning haven't been fully integrated into the FHE world yet. Combining these with MOAI’s rotation-free logic could lead to the next big speed breakthrough.
Summary updated