Abstract
Private inference (PI) serves an important role in guaranteeing the privacy of user data when interfacing with proprietary machine learning models such as LLMs. However, PI remains practically intractable due to the massive latency costs associated with nonlinear functions present in LLMs. Existing works have focused on improving latency of specific LLM nonlinearities (such as the Softmax, or the GeLU) via approximations. However, new types of nonlinearities are regularly introduced with new LLM architectures, and this has led to a constant game of catch-up where PI researchers attempt to optimize the newest nonlinear function. We introduce TruncFormer, a framework for taking any LLM and transforming it into a plaintext emulation of PI. Our framework leverages the fact that nonlinearities in LLMs are differentiable and can be accurately approximated with a sequence of additions, multiplications, and truncations. Further, we decouple the add/multiply and truncation operations, and statically determine where truncations should be inserted based on a given field size and input representation size. This leads to latency improvements over existing cryptographic protocols that enforce truncation after every multiplication operation. We open source our code for community use.
Introduction
Interfacing with proprietary Large Language Models (LLMs) usually requires sending sensitive data to a provider. Private Inference (PI) uses cryptographic techniques like Multi-Party Computation (MPC) to ensure neither the user nor the provider learns the other's data. However, PI is notoriously slow. The "latency tax" comes primarily from out-of-field operations—nonlinear functions like Softmax, LayerNorm, and GeLU that don't fit naturally into the fixed-size integer fields used by cryptography.
Currently, researchers are stuck in a "game of catch-up," designing custom cryptographic protocols for every new activation function. Furthermore, existing protocols are overly cautious, performing a "truncation" (dropping bits to prevent overflow) after every single multiplication, which adds massive communication overhead. TruncFormer addresses these challenges by optimizing the underlying arithmetic rather than specific functions.
Methods
TruncFormer shifts the strategy from optimizing specific functions to optimizing the underlying arithmetic through three main pillars:
- Differentiable Approximation: Almost all LLM nonlinearities are differentiable. TruncFormer replaces complex functions with iterative approximations (like Newton-Raphson or Taylor series) consisting only of additions, multiplications, and truncations.
- Static Truncation Analysis: Instead of truncating after every multiplication, TruncFormer represents the LLM as a Directed Acyclic Graph (DAG). It tracks the maximum possible bit-width at every step and only inserts a truncation operation when the bit-width is guaranteed to exceed the cryptographic field size (e.g., 64-bit or 128-bit).
- Fixed-Point Optimization: Floating-point weights are converted to integers using a scaling factor. Empirical testing identified 13-bit precision as the optimal threshold for maintaining accuracy while minimizing bit-growth.
Key Insights
- Truncation is the Real Bottleneck: A surprising 90% to 99% of total private inference time is spent on truncation operations, not matrix multiplications.
- The "Over-Truncation" Problem: Standard cryptographic libraries are overly conservative. By decoupling multiplication from truncation and only performing the latter when mathematically necessary, a significant portion of the most expensive operations can be skipped.
- Generality over Specialization: By breaking everything down into basic arithmetic, TruncFormer is future-proof. New activation functions can be handled without needing new cryptographic protocols.
Key Results
TruncFormer was evaluated across standard LLM benchmarks including HumanEval, GSM8K, MMLU, and WikiText-2.
- Speedups: TruncFormer consistently outperformed PUMA (the previous state-of-the-art), achieving a 1.92x speedup on WikiText-2 for Llama-7B and a 1.84x speedup for Gemma-2B.
- Accuracy Preservation: The "TruncFormer-T" versions of models showed negligible accuracy loss. For example, on MMLU, Llama-7B scored 29.92%, while the TruncFormer version scored 29.94%.
- Field Size Impact: While moving from a 64-bit to a 128-bit field allows for fewer truncations, the individual truncations become more expensive. Consequently, 64-bit fields are often more efficient for current LLM architectures.
Limitations and Future Work
Despite these relative speedups, PI remains practically intractable for real-time use; a single inference can still take hours in a real-world MPC setting. Future work will focus on improving the "initial guess" for iterative approximations to reduce iterations and testing the framework across a broader range of MPC protocols beyond Delphi.
Summary updated