Table of Contents
Fetching ...

Fast and Accurate Homomorphic Softmax Evaluation

Wonhee Cho, Guillaume Hanrot, Taeseong Kim, Minje Park, Damien Stehlé

TL;DR

The main ingredient of the algorithms is a normalize-and-square strategy, which manages to interlace the (numerically unstable) exponential computation over a large range and (very expensive) normalization, decomposing both in stabler and cheaper smaller steps.

Abstract

Homomorphic encryption is one of the main solutions for building secure and privacy-preserving solutions for Machine Learning as a Service. This motivates the development of homomorphic algorithms for the main building blocks of AI, typically for the components of the various types of neural networks architectures. Among those components, we focus on the Softmax function, defined by $\mathrm{SM}(\mathbf{x}) = \left(\exp(x_i) / \sum_{j=1}^n \exp(x_j) \right)_{1\le i\le n}$. This function is deemed to be one of the most difficult to evaluate homomorphically, because of its multivariate nature and of the very large range of values for $\exp(x_i)$. The available homomorphic algorithms remain restricted, especially in large dimensions, while important applications such as Large Language Models (LLM) require computing Softmax over large dimensional vectors. In terms of multiplicative depth of the computation (a suitable measure of cost for homomorphic algorithms), our algorithm achieves $O(\log n)$ complexity for a fixed range of inputs, where $n$ is the Softmax dimension. Our algorithm is especially adapted to the situation where we must compute many Softmax at the same time, for instance, in the LLM situation. In that case, assuming that all Softmax calls are packed into $m$ ciphtertexts, the asymptotic amortized multiplicative depth cost per ciphertext is, again over a fixed range, $O(1 + m/N)$ for $N$ the homomorphic ring degree. The main ingredient of our algorithms is a normalize-and-square strategy, which interlaces the exponential computation over a large range and normalization, decomposing both in stabler and cheaper smaller steps. Comparing ourselves to the state of the art, our experiments show, in practice, a good accuracy and a gain of a factor 2.5 to 8 compared to state of the art solutions.

Fast and Accurate Homomorphic Softmax Evaluation

TL;DR

The main ingredient of the algorithms is a normalize-and-square strategy, which manages to interlace the (numerically unstable) exponential computation over a large range and (very expensive) normalization, decomposing both in stabler and cheaper smaller steps.

Abstract

Homomorphic encryption is one of the main solutions for building secure and privacy-preserving solutions for Machine Learning as a Service. This motivates the development of homomorphic algorithms for the main building blocks of AI, typically for the components of the various types of neural networks architectures. Among those components, we focus on the Softmax function, defined by . This function is deemed to be one of the most difficult to evaluate homomorphically, because of its multivariate nature and of the very large range of values for . The available homomorphic algorithms remain restricted, especially in large dimensions, while important applications such as Large Language Models (LLM) require computing Softmax over large dimensional vectors. In terms of multiplicative depth of the computation (a suitable measure of cost for homomorphic algorithms), our algorithm achieves complexity for a fixed range of inputs, where is the Softmax dimension. Our algorithm is especially adapted to the situation where we must compute many Softmax at the same time, for instance, in the LLM situation. In that case, assuming that all Softmax calls are packed into ciphtertexts, the asymptotic amortized multiplicative depth cost per ciphertext is, again over a fixed range, for the homomorphic ring degree. The main ingredient of our algorithms is a normalize-and-square strategy, which interlaces the exponential computation over a large range and normalization, decomposing both in stabler and cheaper smaller steps. Comparing ourselves to the state of the art, our experiments show, in practice, a good accuracy and a gain of a factor 2.5 to 8 compared to state of the art solutions.

Paper Structure

This paper contains 55 sections, 14 theorems, 54 equations, 2 figures, 5 tables, 4 algorithms.

Key Result

theorem 1

Let $M \ge \log n$. On input ${\mathbf x}\in[-M, 0]^n$, Algorithm alg:Softmax returns an approximation of $~{\mathrm{Softmax}}({\mathbf x})$ using $(\log n) (\log M) (1 + o(1))$ multiplicative levels and $O((\log M) \sqrt{n\log n})$ multiplications.

Figures (2)

  • Figure 1: High-level Overview of the Softmax Algorithm.
  • Figure 2: Time as a function of $\log n$.

Theorems & Definitions (27)

  • theorem 1
  • theorem 2
  • definition 1
  • lemma 1
  • lemma 2
  • proof
  • remark 1
  • remark 2
  • theorem 3
  • proof
  • ...and 17 more