TL;DR
Large Language Model (LLM) inference is bottlenecked by the distinct computational demands of its prefill and decode phases. This paper introduces POD-ATTENTION, a novel GPU kernel that unifies these phases, achieving significant speedups (up to 59%) by maximizing GPU resource utilization and enabling more efficient LLM serving.
What Problem Does This Paper Address?
Serving Large Language Models (LLMs) efficiently is a major challenge, especially as demand for these models grows. LLM inference involves two distinct phases: a prefill phase that processes the initial prompt in parallel (compute-bound) and a decode phase that generates tokens autoregressively (memory-bound). Current LLM serving systems often use "hybrid batching" to combine prefill and decode requests within the same batch, aiming to improve GPU utilization. However, existing attention kernels are specialized for either prefill or decode, leading to underutilization of GPU resources when these kernels are run sequentially in a hybrid batch. For instance, prefill kernels might leave memory bandwidth idle, while decode kernels might not fully utilize compute resources. This paper addresses the inefficiency of this sequential execution by proposing a unified attention kernel that can handle both prefill and decode operations concurrently.
Methods
The core innovation is POD-ATTENTION, a single GPU kernel designed to fuse prefill and decode attention computations. Instead of running separate kernels, POD-ATTENTION integrates both operations. The key techniques employed are:
- CTA-Parallel Fusion: The kernel fuses computation along the Cooperative Thread Array (CTA) dimension. This allows different CTAs to start and finish independently, avoiding straggler effects and making programming easier.
- SM-Aware CTA Scheduling: To ensure prefill and decode CTAs are co-located on the same Streaming Multiprocessor (SM), a software-based scheduling mechanism is introduced. Each CTA, upon being dispatched to an SM, queries its SMID and checks the activity of other CTAs on that SM to decide whether to perform a prefill or decode operation. This runtime decision-making allows the kernel to adapt to the dynamic nature of hybrid batches.
- Optimized Tile Sizes: For decode operations, smaller tile sizes (16 for QSL dimension) are used to free up tensor cores for prefill computations, improving overall compute utilization.
- Virtual Decode CTAs: To manage shared memory requirements, decode CTAs are divided into virtual CTAs, ensuring that prefill and decode operations have balanced shared memory allocations.
- Limited Prefill Splits: The number of splits for chunked prefills is limited to avoid excessive memory bandwidth contention with concurrent decodes.
Datasets
The paper evaluates its approach using the arXiv-Summarization dataset [4]. They also use an internal enterprise workload and benchmark on models trained on various datasets.
Key Insights and Ideas
- Suboptimality of Independent Kernels: The paper convincingly demonstrates that using separate, optimized kernels for prefill and decode attention in hybrid batches is suboptimal, leading to significant GPU resource underutilization.
- The Power of Co-location: Achieving true concurrency requires not just running operations in parallel but ensuring they are co-located on the same SM to maximize resource sharing and minimize overheads.
- SM-Aware Scheduling is Crucial: Dynamic, runtime scheduling based on SM activity is essential for effectively managing heterogeneous workloads like hybrid prefill-decode batches.
- Attention is the Bottleneck: As context lengths increase, attention computation becomes the dominant performance bottleneck, making optimizations in this area critical for LLM inference.
Key Results
- Attention Speedup: POD-ATTENTION accelerates attention computation by up to 59% (mean 28%) compared to using independently optimized prefill and decode attention kernels (like FlashAttention and FlashInfer).
- End-to-End Inference Improvement: Integrating POD-ATTENTION into the Sarathi-Serve framework leads to significant improvements in LLM serving:
- Throughput: Up to 22% higher throughput in offline inference scenarios.
- Latency: Significantly reduced Time-To-First-Token (TTFT) and Time-Between-Tokens (TBT), leading to a better overall user experience. For example, P99 TTFT is reduced by up to 4.3x, and tail TBT latency is minimized, drastically reducing request stalls.
- Energy Efficiency: POD-ATTENTION reduces energy consumption by up to 35% over serial execution.
Limitations and Future Work
- Hardware Dependency: The artifact and experiments are primarily tested on NVIDIA A100 GPUs. While the principles are general, specific performance tuning might be needed for other architectures.
- Future Work: The authors mention extending POD-ATTENTION support to newer architectures like NVIDIA Hopper and exploring its integration with other advanced attention kernels like FlashAttention-3. They also suggest further investigation into optimizing scheduling policies and CTA configurations for different workload characteristics.
Summary updated