TL;DR
Researchers have developed the first "Polynomial Transformer," a breakthrough that allows state-of-the-art Transformer models to run directly on encrypted data using Homomorphic Encryption (HE). By redesigning core components like Softmax and LayerNorm into polynomial forms and using a novel "range-minimization" training recipe, they achieved competitive performance on language and vision tasks while keeping data completely confidential.
What Problem Does This Paper Address?
In the world of Privacy-Preserving Machine Learning (PPML), Homomorphic Encryption (HE) is the "holy grail." It allows a server to perform computations on data while it is still encrypted, meaning the model owner never sees the user's raw information.
However, HE has a massive technical catch: it only supports polynomial operations (addition and multiplication). This is a nightmare for Transformers, the architecture behind GPT and ViTs. Transformers rely heavily on non-polynomial functions:
- Softmax: Involves exponentials and division.
- LayerNorm: Involves square roots and division.
- GELU/ReLU: Non-linear activation functions.
Previously, researchers successfully converted Convolutional Neural Networks (CNNs) to polynomial forms, but Transformers remained elusive due to their inherent instability when these complex functions are replaced by simple polynomials.
Methods
The authors propose a three-stage "recipe" to create a PolyTransformer:
- HE-Friendly Architecture: They replace problematic layers with "HE-friendly" alternatives. Most notably, they swap the standard Softmax-based attention for $\sigma$-attention (pointwise activation). To prevent the model's weights from exploding during training, they introduce length scaling (dividing by the sequence length $L$ or $\sqrt{L}$).
- Range-Minimization Training: Polynomial approximations are only accurate within a specific range (e.g., between -2 and 2). To ensure the model's internal values stay within these "safe zones," the authors add a specialized Range Loss and Variance Minimization Loss during a supplementary training phase. This "squashes" the distribution of data flowing through the network.
- Polynomial Substitution: Finally, they replace the remaining non-polynomial parts (like the inverse square root in LayerNorm) with high-precision polynomial approximations derived via the Remez algorithm or Newton-Raphson iterations.
Datasets
The team evaluated their approach across both Natural Language Processing (NLP) and Computer Vision (CV) domains:
- NLP: Wikitext-103, text-8, and enwik8 (focused on Next Token Prediction).
- Vision: CIFAR-10, CIFAR-100, and Tiny-ImageNet.
- Secure Inference Test: A financial news classification dataset was used to validate the model's performance specifically within an HE framework (HElayers).
Key Insights and Ideas
- The Stability Secret: The biggest hurdle wasn't just finding a polynomial for Softmax; it was keeping the model from crashing. The "aha moment" was realizing that pointwise attention combined with sequence length scaling provides the necessary stability that Softmax usually offers.
- Range is Everything: You don't need a polynomial that works everywhere—you just need one that works on the specific range of values your model actually produces. By forcing the model to have a narrow internal "dynamic range" through specialized loss functions, simple polynomials become incredibly effective.
- Non-Interactive Privacy: Unlike other secure protocols that require constant back-and-forth communication between the client and server, this polynomial approach is non-interactive. The client sends the data once, and the server does the rest.
Key Results
The PolyTransformer bridges the gap between privacy and performance:
- Competitive Accuracy: On Wikitext-103, a 6-layer polynomial model achieved a perplexity of 19.89, compared to 18.98 for a standard vanilla Transformer—a remarkably small performance hit for total privacy.
- Vision Success: On CIFAR-100, the polynomial ViT reached 70.8% accuracy, trailing the original model (73.4%) by only a few percentage points.
- Real-World Feasibility: Using the HElayers SDK, the researchers demonstrated that secure inference for a BERT-like model (6 layers, 128 tokens) takes approximately 211 seconds. While slower than plaintext, this is a massive step toward practical, secure cloud-based AI.
Limitations and Future Work
- Latency: While 211 seconds is a milestone for HE, it is still too slow for real-time applications like chatbots. Further optimization in HE hardware and compilers is needed.
- Scaling: The authors noted that as models get deeper and wider, they become harder to stabilize. Future work will need to explore how to scale these polynomial techniques to "Large" Language Models (LLMs) with billions of parameters.
- Approximation vs. Alternative: The method doesn't directly approximate Softmax; it replaces it with a different mechanism ($\sigma$-attention). While effective, there may be specific tasks where the original Softmax behavior is irreplaceable.
Summary updated