Table of Contents
Fetching ...

Efficient Softmax Reformulation for Homomorphic Encryption via Moment Generating Function

Hanjun Park, Byeong-Seo Min, Jiheon Woo, Min-Wook Jeong, Jongho Shin, Yongwoo Lee, Young-Sik Kim, Yongjune Kim

TL;DR

This work tackles the challenge of evaluating softmax under homomorphic encryption by introducing MGF-softmax, a reformulation based on the moment generating function that replaces the traditional softmax denominator with a moment-based term. By expressing the denominator as $n M_X(1)$ and leveraging the cumulant generating function, the method eliminates the need for max-subtraction and division, substantially reducing multiplicative depth and the associated bootstrapping burden. The authors provide theoretical properties, including shift invariance and a data-adaptive domain scaling, and derive an error bound showing the relative error vanishes as the input size grows. Empirically, MGF-softmax achieves near-plaintext accuracy on large language models and Vision Transformers while requiring much lower depth (7–10) and runtime, outperforming softmax approximation baselines and softmax replacements on challenging benchmarks. This approach offers a scalable, privacy-preserving pathway for efficient encrypted inference in transformer-based architectures.

Abstract

Homomorphic encryption (HE) is a prominent framework for privacy-preserving machine learning, enabling inference directly on encrypted data. However, evaluating softmax, a core component of transformer architectures, remains particularly challenging in HE due to its multivariate structure, the large dynamic range induced by exponential functions, and the need for accurate division during normalization. In this paper, we propose MGF-softmax, a novel softmax reformulation based on the moment generating function (MGF) that replaces the softmax denominator with its moment-based counterpart. This reformulation substantially reduces multiplicative depth while preserving key properties of softmax and asymptotically converging to the exact softmax as the number of input tokens increases. Extensive experiments on Vision Transformers and large language models show that MGF-softmax provides an efficient and accurate approximation of softmax in encrypted inference. In particular, it achieves inference accuracy close to that of high-depth exact methods, while requiring substantially lower computational cost through reduced multiplicative depth.

Efficient Softmax Reformulation for Homomorphic Encryption via Moment Generating Function

TL;DR

This work tackles the challenge of evaluating softmax under homomorphic encryption by introducing MGF-softmax, a reformulation based on the moment generating function that replaces the traditional softmax denominator with a moment-based term. By expressing the denominator as and leveraging the cumulant generating function, the method eliminates the need for max-subtraction and division, substantially reducing multiplicative depth and the associated bootstrapping burden. The authors provide theoretical properties, including shift invariance and a data-adaptive domain scaling, and derive an error bound showing the relative error vanishes as the input size grows. Empirically, MGF-softmax achieves near-plaintext accuracy on large language models and Vision Transformers while requiring much lower depth (7–10) and runtime, outperforming softmax approximation baselines and softmax replacements on challenging benchmarks. This approach offers a scalable, privacy-preserving pathway for efficient encrypted inference in transformer-based architectures.

Abstract

Homomorphic encryption (HE) is a prominent framework for privacy-preserving machine learning, enabling inference directly on encrypted data. However, evaluating softmax, a core component of transformer architectures, remains particularly challenging in HE due to its multivariate structure, the large dynamic range induced by exponential functions, and the need for accurate division during normalization. In this paper, we propose MGF-softmax, a novel softmax reformulation based on the moment generating function (MGF) that replaces the softmax denominator with its moment-based counterpart. This reformulation substantially reduces multiplicative depth while preserving key properties of softmax and asymptotically converging to the exact softmax as the number of input tokens increases. Extensive experiments on Vision Transformers and large language models show that MGF-softmax provides an efficient and accurate approximation of softmax in encrypted inference. In particular, it achieves inference accuracy close to that of high-depth exact methods, while requiring substantially lower computational cost through reduced multiplicative depth.
Paper Structure (45 sections, 4 theorems, 21 equations, 2 figures, 7 tables, 1 algorithm)

This paper contains 45 sections, 4 theorems, 21 equations, 2 figures, 7 tables, 1 algorithm.

Key Result

Proposition 3.1

MGF-softmax is shift-invariant. For any constant $c \in \mathbb{R}$,

Figures (2)

  • Figure 1: Top-1 accuracy of LLaMA-3.2-1B across NLP benchmarks (Clinc150, Banking77, and SST-2).
  • Figure 2: Top-1 accuracy of ViT and DeiT models on the ImageNet-1k dataset.

Theorems & Definitions (7)

  • Proposition 3.1
  • proof
  • Proposition 3.2
  • Proposition 3.3
  • proof
  • Proposition 3.4
  • proof