Efficient Decoding Methods for Language Models on Encrypted Data

Matan Avitan, Moran Baruch, Nir Drucker, Itamar Zimerman, Yoav GoldbergarXiv 2025 · DOI

Abstract

As Large Language Models (LLMs) become central to digital interaction, the need to protect sensitive user prompts has never been more urgent. Homomorphic Encryption (HE) offers a promising path by allowing servers to process data without decryption, but it is computationally restricted to polynomial operations. Standard decoding strategies, such as argmax and nucleus sampling, rely on non-polynomial comparisons that create severe latency bottlenecks in HE environments. This paper introduces CutMax, a novel decoding algorithm that utilizes iterative polynomial "stretching" to identify the maximum logit. CutMax achieves up to a 35x speedup over existing state-of-the-art methods, maintains 100% token recovery accuracy, and is the first method to enable nucleus sampling under encryption.

Introduction

When users interact with LLMs, they often share private information, ranging from medical queries to proprietary code. While standard encryption protects data in transit, the data must typically be decrypted on the server for processing, exposing it to potential breaches or provider misuse. Homomorphic Encryption (HE) addresses this by enabling computation on ciphertext. However, HE's "math budget" is limited to additions and multiplications.

A significant challenge in private LLM inference is the decoding stage. To generate text, the model must select the most likely next word from a vocabulary that can exceed 150,000 tokens. Standard methods like argmax (finding the highest value) or top-p sampling (selecting from the cumulative top probability mass) involve logical comparisons (e.g., "is A > B?"). In HE, these operations are typically implemented using "tournament trees" that compare every token pair, a process that is computationally grueling and scales poorly with vocabulary size.

Figure 1: The architecture of private LLM inference, highlighting the role of CutMax in the encrypted decoding stage.

Methodology

The authors propose a shift from comparison-based logic to statistical distribution manipulation.

CutMax: The Argmax Alternative

CutMax replaces the discrete argmax operation with a sequence of polynomial transformations. The algorithm treats the list of word probabilities (logits) as a distribution and iteratively applies two steps:

  1. Standardization: The logits are shifted by their mean and scaled by their variance. This centers the distribution, making it predictable for further polynomial operations.
  2. Distance Amplification: The standardized values are raised to a high odd power (e.g., $x^{11}$).

Mathematically, this "stretches" the distribution: the highest value (the "winner") is pushed toward 1, while all other values (the "losers") are suppressed toward 0. After 3–5 iterations, the result is an encrypted "one-hot" vector where only the winning token remains active. Because CutMax relies on global statistical properties rather than pairwise comparisons, its complexity is only weakly dependent on vocabulary size.

HE-Friendly Nucleus Sampling

Nucleus (top-p) sampling is essential for maintaining creativity in LLM outputs, yet it has remained elusive in encrypted settings due to the need for sorting. The authors introduce a "Beta-cut" noise trick. By perturbing the encrypted logits with specific noise distributions, they ensure that only tokens within the top-p cumulative mass have a high probability of being selected by the subsequent CutMax operation. This allows for creative, non-deterministic generation without compromising privacy.

Differentiability and Training

Unlike standard argmax, which is a step function with zero gradients, CutMax is a smooth, differentiable polynomial. This allows researchers to integrate CutMax directly into the training loop. Models can be fine-tuned to produce logit distributions that are specifically optimized for the CutMax "stretching" process, potentially improving robustness in noisy HE environments.

Experimental Setup and Results

The researchers evaluated CutMax using realistic LLM outputs from QWEN2.5-0.5B (150k vocabulary), Mistral-7B (32k vocabulary), and GPT-2 (50k vocabulary). Evaluation data included 100 paper abstracts from the ccdv/arxiv-summarization dataset and the GLUE benchmark.

Performance Benchmarks

CutMax demonstrated dramatic improvements in latency compared to the previous state-of-the-art, Nexus:

  • Mistral-7B: Latency dropped from 79.36 seconds to 3.37 seconds.
  • Qwen-0.5B: Latency dropped from 162.8 seconds to 4.6 seconds, representing a 35x speedup.

Accuracy and Efficiency

In tests across 400 different prompts, CutMax achieved 100% next-token recovery, meaning the encrypted model's output was identical to that of a standard, unencrypted model. Furthermore, CutMax is more efficient in its use of "bootstraps"—expensive HE operations required to refresh the noise budget of ciphertexts. By maintaining a lower multiplicative depth, CutMax reduces the overall cryptographic overhead of the inference pipeline.

Conclusion and Future Directions

CutMax represents a major step toward making private, real-time AI a reality by removing the decoding bottleneck. While the Transformer layers themselves still pose a significant computational challenge under HE, the efficiency and differentiability of CutMax provide a foundation for future "privacy-aware" model architectures. Future work will explore end-to-end optimization of the LLM pipeline and the adaptation of CutMax to other encryption schemes like BGV or TFHE.

Reference: Avitan, M., Baruch, M., Drucker, N., Zimerman, I., & Goldberg, Y. (2025). Efficient Decoding Methods for Language Models on Encrypted Data. arXiv:2509.08383v2.

Summary updated

BibTeX
@misc{avitan2025efficient,
  author = {Matan Avitan and Moran Baruch and Nir Drucker and Itamar Zimerman and Yoav Goldberg},
  title = {{Efficient Decoding Methods for Language Models on Encrypted Data}},
  year = {2025},
  eprint = {2509.08383},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.08383},
}
Figure