[KongchangAI]
· 2 min read· 1,143 words

Homomorphically Encrypted Llama3-8B Achieves 2 tokens/sec Inference Breakthrough

Homomorphically Encrypted Llama3-8B Achieves 2 tokens/sec Inference Breakthrough

Llama3-8B achieves 2 tokens/sec under homomorphic encryption, marking a key engineering validation step for privacy-preserving inference.

A Hacker News post demonstrated running Llama3-8B under fully homomorphic encryption (FHE) at 2 tokens per second, drawing attention to privacy-preserving inference. The article analyzes why FHE inference is expensive: ciphertext addition and multiplication incur huge overhead; matrix multiplications and nonlinear activations like GELU and Softmax in Transformers must be converted to homomorphic operations; and ciphertext expansion brings memory bandwidth pressure. 2 tokens/sec means generating 100 tokens takes about 50 seconds—still slow for real-time dialogue but preliminarily usable for offline batch processing and sensitive data analysis. The article also compares FHE with competing approaches like TEE, MPC, and differential privacy, noting that FHE's mathematical security does not depend on hardware but its performance is the weakest, and looks ahead to dedicated hardware acceleration, ciphertext packing optimization, and Transformer-specific operators.

Homomorphic Encryption Meets Large Models: A Key Step for Privacy-Preserving Inference

Recently, a Hacker News post titled "Homomorphically Encrypted Llama3-8B at 2 tokens/sec" sparked discussion. The post claims that running the Llama3-8B model in a fully homomorphic encryption (FHE) environment achieved an inference speed of 2 tokens per second. This means users can obtain the generative capabilities of a large model without exposing plaintext input to the service provider.

Hacker News original post screenshot

Although 2 tokens/sec is far slower than plaintext inference, this result marks an important advance of privacy-preserving inference from theory to engineering practice. Homomorphic encryption allows computations to be performed directly on ciphertext, and the decrypted result matches that of plaintext computation. Applying this technology to a billion-parameter language model presents challenges primarily in computational overhead and memory footprint.

Technical Challenges: Why FHE Inference Is So Expensive

The core operations of homomorphic encryption—ciphertext addition and multiplication—introduce significant computational overhead. In neural network inference, matrix multiplications and nonlinear activation functions (such as GELU, Softmax) all need to be translated into forms supported by homomorphic encryption. For a Transformer architecture like Llama3-8B, each layer contains numerous matrix multiplications and attention computations, and the cost of executing these operations in the ciphertext domain is far higher than in plaintext.

Achieving a throughput of 2 tokens/sec requires extensive algorithmic optimizations, such as pre-encrypting model weights, adopting batching strategies, and reducing ciphertext multiplication depth. The post itself does not disclose specific optimization details, but the result suggests the research team achieved a usable balance between latency and throughput.

Ciphertext multiplication depth and bootstrapping are two key concepts for understanding FHE overhead. Most practical FHE schemes (such as CKKS, BFV) are "leveled": there is a limit on the number of consecutive multiplications that can be performed on a ciphertext, known as the multiplication depth. The chain of matrix multiplications and activation functions in neural networks quickly consumes the depth budget; once exhausted, bootstrapping must be performed—refreshing noise on the ciphertext and restoring usable depth. Bootstrapping is one of the most expensive operations in FHE, potentially taking milliseconds to tens of milliseconds per invocation. Triggered repeatedly across dozens of Transformer layers, it directly cripples throughput. Therefore, engineering optimizations often focus on "reducing multiplication depth," for example by approximating GELU and Softmax with low-degree polynomials or adjusting model architecture to lower the depth requirements of nonlinear operations.

Ciphertext packing (packing/SIMD) is a core means of improving throughput. Schemes like CKKS allow thousands of values to be encoded into a single ciphertext, so that one homomorphic operation can process an entire batch of data in parallel. The efficiency of mapping matrix rows, columns, or attention heads to packing slots determines hardware utilization. The 2 tokens/sec result in the post likely relies on aggressive packing and batching strategies rather than simply throwing compute at the problem.

Significance and Limitations of 2 tokens/sec

2 tokens/sec means generating 100 tokens takes about 50 seconds. For real-time对话 scenarios, this speed is still slow; but for offline batch processing, sensitive data analysis, and privacy-first asynchronous tasks, it is already preliminarily usable.

Compared with plaintext inference, FHE inference costs several orders of magnitude more. This is not only a compute issue but also involves memory bandwidth pressure caused by ciphertext expansion. Therefore, in the short term, FHE inference is more suitable for vertical scenarios with strong privacy requirements rather than replacing conventional cloud inference.

The post received 10 points and 6 comments on Hacker News, indicating limited discussion heat, which suggests the direction is still in its early stages and community attention has not yet exploded.

Competing Approaches to Privacy-Preserving Inference

Homomorphic encryption is not the only path to privacy-preserving inference. Technologies such as trusted execution environments (TEE), secure multi-party computation (MPC), and differential privacy are also competing for this market. FHE's advantage is that its mathematical security does not depend on hardware vendors and it supports arbitrary computation on ciphertext; its disadvantage is enormous performance overhead.

The 2 tokens/sec result on Llama3-8B provides a reference benchmark for the FHE approach. If future breakthroughs can be made on larger models or lower latency, the commercialization space for FHE inference will expand significantly.

Trusted execution environments (TEE) , represented by Intel SGX, AMD SEV, and ARM CCA, partition encrypted memory regions within the CPU to let models run in hardware-isolated "enclaves." Their performance overhead is typically only single-digit to tens of percent, far lower than FHE, but security depends on hardware vendors' implementations and remote attestation mechanisms, and side-channel attacks have been repeatedly reported historically. Secure multi-party computation (MPC) splits computation across multiple mutually distrusting parties, completing inference through secret sharing and interactive protocols. Security does not depend on a single hardware vendor, but communication overhead amplifies with the number of parties and network latency, making it suitable for cross-institutional collaboration scenarios. Differential privacy takes a different path: it does not hide the computation process but injects noise into outputs or gradients to provide statistical privacy guarantees, commonly used in federated learning.

These approaches are not mutually exclusive. Combination schemes such as hybrid FHE+MPC and running FHE accelerators within TEEs have already emerged in practice. Which approach to choose depends on the threat model (defending against service providers, hardware vendors, or network eavesdropping), latency budget, and deployment cost. FHE's unique value lies in purely cryptographic security and support for arbitrary computation, at the cost of currently the weakest performance.

Outlook: From Usable to Good

The current result is more like a proof of concept: it demonstrates that a billion-parameter model can run under homomorphic encryption, but it is still far from production-grade deployment. Future optimization directions may include dedicated hardware acceleration, more efficient ciphertext packing schemes, and customized FHE operators for Transformer architectures.

For developers and enterprises concerned about AI privacy, this progress is worth tracking. When FHE inference speed improves to near-interactive levels, the fusion of privacy computing and generative AI will open up new application spaces.

Dedicated hardware acceleration is a key variable for FHE to become practical. Multiple directions have emerged in academia and industry: FPGA-based NTT (number theoretic transform) accelerators, ASIC designs for bootstrapping, and schemes leveraging GPUs for large-batch parallel processing of ciphertext multiplication. NTT is the core operation in polynomial multiplication in homomorphic encryption, and its throughput directly determines overall performance; dedicated pipelines can accelerate it by one to two orders of magnitude.

Another noteworthy direction is algorithm-model co-design. For example, replacing GELU with smoother activation functions that are easier to approximate with polynomials, reducing nonlinear operations in attention mechanisms, or constraining weight distributions during training to lower quantization and encryption errors. Such "FHE-friendly" model modifications may improve actual throughput faster than simply waiting for hardware advances. For developers, following the progress of open-source libraries for CKKS schemes (such as Microsoft SEAL, OpenFHE) and inference frameworks is the lowest-cost way to track this field.

#homomorphic encryption#Llama3-8B#privacy-preserving inference#FHE#large language models
Share:

Related articles