Abstract
Foundation Models (FMs) display exceptional performance in tasks such as natural language processing and are being applied across a growing range of disciplines. Although typically trained on large public datasets, FMs are often fine-tuned or integrated into Retrieval-Augmented Generation (RAG) systems, which rely on private data. This access, along with their size and costly training, heightens the risk of intellectual property theft. Moreover, multimodal FMs may expose sensitive information. In this work, we examine the FM threat model and discuss the practicality and comprehensiveness of various approaches for securing against them, such as ML-based methods and trusted execution environments (TEEs). We demonstrate that TEEs offer an effective balance between strong security properties, usability, and performance. Specifically, we present a solution achieving less than 10% overhead versus bare metal for the full Llama2 7B and 13B inference pipelines running inside Intel SGX and Intel TDX. We also share our configuration files and insights from our implementation. To our knowledge, our work is the first to show the practicality of TEEs for securing FMs.
Introduction
Foundation Models (FMs) like Llama 2 are incredibly expensive to train and often handle highly sensitive data through fine-tuning or Retrieval-Augmented Generation (RAG). When these models are deployed in the cloud, they face significant security risks: intellectual property theft of model weights, data privacy breaches of user prompts or private documents, and model tampering intended to introduce bias or degrade performance.
Previous attempts to solve this using cryptographic methods like Homomorphic Encryption (HE) resulted in 10,000x slowdowns. Earlier research into Trusted Execution Environments (TEEs) often reported overheads of 100% or more, or only protected small parts of the model, leaving the rest vulnerable. This paper demonstrates that modern TEEs—specifically Intel SGX and TDX—can secure LLMs in the cloud with less than 10% performance overhead.
Methodology
The authors implemented a full Llama 2 inference pipeline (7B and 13B parameters) inside two types of TEEs:
- Intel SGX (Software Guard Extensions): An application-based TEE that isolates specific code and data in "enclaves." The authors used Gramine, a library OS, to run unmodified PyTorch and DeepSpeed workloads within these enclaves.
- Intel TDX (Trust Domain Extensions): A hardware-isolated Virtual Machine (VM) TEE. This is generally easier to deploy as it protects the entire OS environment.
Key Technical Optimizations: * Hardware Acceleration: Leveraging Intel AMX (Advanced Matrix Extensions) to speed up tensor operations inside the TEE. * Memory Management: Using TCMalloc to reduce memory pressure and huge pages in TDX to decrease translation lookaside buffer (TLB) misses. * NUMA Tuning: Optimizing performance by pinning workloads to a single NUMA domain per CPU to account for current TEE driver limitations.
Evaluation and Results
The study evaluated the Llama 2 model family (7B and 13B) using bfloat16 and int8 datatypes on a dual-socket Intel Xeon Platinum 6530 system. The authors achieved remarkably low overheads compared to "bare metal" (unsecured) performance:
- Throughput: TEEs incurred only a 4–7% reduction in tokens per second.
- Latency: The overhead for generating the next token was between 4–10%.
- SGX vs. TDX: Gramine-SGX overhead was roughly 4.5–6.5%, while TDX overhead was slightly higher at 5.8–11.1%.
- Human Perception: All tested TEE configurations maintained latencies significantly lower than the average human reading speed (~200ms/word), making the security features effectively invisible to the end user.
Key Insights
- The Memory Bottleneck Advantage: Surprisingly, the "heavy" nature of LLMs helps TEE performance. Because LLM inference is primarily limited by memory bandwidth rather than raw compute, the overhead of encrypting/decrypting memory in the TEE becomes a negligible fraction of the total processing time.
- Full Pipeline Protection is Practical: Putting the entire stack—from the OS/Library OS to the model weights—inside the TEE is both more secure and performant than offloading specific layers.
- Attestation is the "Root of Trust": A TEE is useless without Remote Attestation, a process where the hardware provides a signed proof that the correct, untampered model and software are actually running in a secure enclave.
Limitations and Future Work
While promising, the study notes that GPU TEEs (like Nvidia H100) are currently scarce and often suffer from high communication overhead. Additionally, scaling these security guarantees across a distributed cluster of TEEs remains a challenge. Future work may also address securing the training process, which is significantly more computationally intensive than inference.
Summary updated