[Paper Review] Converting Transformers to Polynomial Form for Secure Inference Over Homomorphic Encryption
This paper introduces the first polynomial-form transformer model compatible with homomorphic encryption (HE), enabling secure inference without exposing data or model weights. By replacing non-polynomial operations like Softmax and LayerNorm with polynomial approximations—specifically via a scaled-σ attention mechanism and BatchNorm-based normalization—the authors achieve competitive performance on WikiText-103 (59.1% accuracy) and CIFAR-100/Tiny-ImageNet, demonstrating the first feasible HE-secure transformer inference with minimal performance gap to standard models.
Designing privacy-preserving deep learning models is a major challenge within the deep learning community. Homomorphic Encryption (HE) has emerged as one of the most promising approaches in this realm, enabling the decoupling of knowledge between the model owner and the data owner. Despite extensive research and application of this technology, primarily in convolutional neural networks, incorporating HE into transformer models has been challenging because of the difficulties in converting these models into a polynomial form. We break new ground by introducing the first polynomial transformer, providing the first demonstration of secure inference over HE with transformers. This includes a transformer architecture tailored for HE, alongside a novel method for converting operators to their polynomial equivalent. This innovation enables us to perform secure inference on LMs with WikiText-103. It also allows us to perform image classification with CIFAR-100 and Tiny-ImageNet. Our models yield results comparable to traditional methods, bridging the performance gap with transformers of similar scale and underscoring the viability of HE for state-of-the-art applications. Finally, we assess the stability of our models and conduct a series of ablations to quantify the contribution of each model component.
Motivation & Objective
- To enable secure inference over homomorphic encryption (HE) for transformer models, which have previously been infeasible due to non-polynomial operations like Softmax and LayerNorm.
- To bridge the performance gap between HE-protected transformers and their non-encrypted counterparts by developing HE-friendly architectural alternatives.
- To demonstrate the feasibility of deploying full transformer models under HE, including both language modeling and image classification tasks.
- To provide a stable, scalable framework for polynomial transformation of attention and normalization layers, enabling broader adoption of privacy-preserving deep learning.
Proposed method
- Propose a scaled-σ attention mechanism that replaces Softmax with a polynomial approximation using the σ function, enabling HE-compatible computation.
- Replace LayerNorm with BatchNorm in both the multi-head attention and MLP sublayers to ensure compatibility with polynomial representations.
- Introduce a two-stage training procedure: first pre-train a standard transformer, then fine-tune it with polynomial activation functions and BatchNorm to preserve performance.
- Apply length scaling and 2D BatchNorm across attention heads to stabilize training and improve accuracy in polynomial transformer variants.
- Use HE-SDK (HElayers v1.52) with HEaaN backend, setting parameters for 128-bit security, 2^15 coefficients, 12 multiplication depth, and 42 fractional precision.
- Leverage CPU-GPU hybrid architecture (AMD EPYC 7763 + NVIDIA A100) to accelerate HE inference, achieving 305s per inference on a 6-layer BERT-like model.
Experimental results
Research questions
- RQ1Can transformers be effectively converted into polynomial form to enable secure inference under homomorphic encryption?
- RQ2How can non-polynomial operations like Softmax and LayerNorm be approximated with polynomial functions without significant performance degradation?
- RQ3What architectural modifications are necessary to stabilize polynomial transformers during training and inference under HE constraints?
- RQ4To what extent can polynomial transformers match the performance of standard transformers on NLP and vision benchmarks under HE?
- RQ5What is the impact of each component (e.g., BatchNorm, length scaling) on the stability and accuracy of HE-secure transformer models?
Key findings
- The proposed polynomial transformer achieves 59.1% accuracy on WikiText-103 using a σ-attention mechanism with all stabilizing techniques, closely approaching the original Swin Transformer’s 59.4%.
- On Tiny-ImageNet, the best-performing polynomial ViT variant (B+QK+A+S) reaches 59.1% accuracy with σ-attention, matching the original Swin’s performance.
- The addition of 2D BatchNorm across attention heads (B+QK) improves accuracy from 39.0% to 49.8% (GELU) and 38.4% to 50.1% (ReLU), demonstrating its critical role in stability.
- Length scaling (S) further improves performance, closing the gap with the original model and enabling the model to generalize better under HE constraints.
- Secure inference on a 6-layer BERT-like model (53.3M parameters) takes 305 seconds on CPU+GPU hardware, outperforming ResNet-152 (432s) under the same HE setup.
- The ablation study confirms that combining BatchNorm in MLP, attention normalization, and length scaling is essential for achieving high accuracy in polynomial transformers.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.