TL;DR
This paper introduces vAttention, a novel memory management system for Large Language Models (LLMs) that significantly improves serving throughput and reduces programming complexity compared to the dominant PagedAttention approach. By decoupling virtual and physical memory allocation and leveraging CUDA virtual memory APIs, vAttention achieves better performance and portability without sacrificing KV cache contiguity.
What Problem Does This Paper Address?
Serving Large Language Models (LLMs) efficiently is crucial due to their increasing deployment in various applications. A major bottleneck is managing the GPU memory required for the KV cache, which stores intermediate computations for each request. PagedAttention, a popular solution, dynamically allocates GPU memory to mitigate fragmentation and improve batch sizes. However, PagedAttention introduces significant programming overhead by requiring attention kernels to handle non-contiguous memory blocks and adds runtime latency. This paper addresses the need for a more performant, portable, and simpler dynamic memory management system for LLM serving that avoids these drawbacks.
Methods
vAttention tackles the problem by:
- Decoupling Virtual and Physical Memory Allocation: Unlike PagedAttention, which tightly couples these, vAttention first reserves a large contiguous virtual memory buffer for the KV cache and then allocates physical memory on demand using CUDA Virtual Memory Management (VMM) APIs. This preserves the virtual contiguity of the KV cache.
- Leveraging CUDA VMM APIs: vAttention utilizes low-level CUDA VMM APIs to manage memory, allowing for fine-grained control over physical memory allocation.
- LLM-Specific Optimizations: To overcome the inherent latency of CUDA VMM APIs and the large page size granularity (2MB), vAttention implements:
- Overlapping Memory Allocation with Compute: Memory allocation for upcoming iterations is performed in a background thread during current computation, hiding latency.
- Deferred Reclamation: For prefill phases, physical memory from completed requests is reused for new requests, avoiding re-allocation.
- Custom Page Sizes: By modifying open-source NVIDIA drivers, vAttention supports smaller page sizes (e.g., 64KB) to reduce fragmentation, without incurring TLB thrashing.
- Extending PyTorch Caching Allocator: vAttention integrates with existing deep learning frameworks by allowing tensors to be reserved as "virtual tensors" without immediate physical memory commitment.
Datasets
The paper evaluates vAttention using the arXiv-Summarization dataset for both offline and online inference scenarios.
Key Insights and Ideas
- Virtual Contiguity is Key: The paper argues that maintaining virtual contiguity of the KV cache is crucial for simplifying programming and enabling efficient use of optimized attention kernels. PagedAttention's approach of breaking this contiguity introduces complexity.
- CUDA VMM is Powerful but Needs Optimization: While CUDA VMM offers the necessary primitives for decoupling memory allocation, its raw latency and large page sizes necessitate significant optimizations for practical LLM serving.
- Portability is a Major Win: vAttention's design allows it to seamlessly support new attention kernels (like FlashAttention-3) that may not have PagedAttention support built-in, demonstrating its portability advantage.
- Smaller Pages Don't Hurt Performance: The use of smaller page sizes (64KB) for KV cache allocation did not negatively impact performance due to TLB thrashing, contrary to potential concerns.
Key Results
- Throughput Improvements: vAttention improves LLM serving throughput by up to 1.23x compared to PagedAttention-based kernels of FlashAttention-2 and FlashInfer.
- Prefill Performance: vAttention-backed systems outperform PagedAttention counterparts in prefill throughput, with gains up to 1.36x for longer contexts.
- Decode Performance: vAttention is on par with the best PagedAttention implementations for decode throughput and significantly outperforms vLLM's native decode kernel.
- Reduced Programming Burden: vAttention requires minimal code changes (a few lines) to integrate new attention kernels, unlike PagedAttention which demands substantial modifications.
- Portability Benefit: vAttention enables dynamic memory allocation for FlashAttention-3, providing up to 1.5x higher throughput over PagedAttention-2.
- Latency Hiding: Overlapping memory allocation with compute effectively hides CUDA VMM API latency, preventing significant spikes in decode iteration times.
Limitations and Future Work
- CPU Runtime Overhead: While vAttention mitigates GPU overhead, the paper acknowledges that CPU runtime overhead can still be an issue, though it can be addressed by moving to a C++ runtime.
- Swapping to CPU Memory: More sophisticated memory management policies, such as swapping out KV cache to CPU memory, are mentioned as future work.
- Virtual Memory Fragmentation: While vAttention avoids physical memory fragmentation, it could potentially fragment virtual memory. However, the authors note that virtual memory is abundant on modern systems.
Summary updated