Dynamic Shapes' Performance Cost: Up to 23x Throughput Loss
Without dynamic shape optimization, LLM inference on GPUs can experience dramatically reduced throughput; for instance, applying constrained dynamic shapes has been shown to boost prefill throughput by over 23 times compared to unoptimized baselines on hardware like NVIDIA RTX 3070.
The top 3
- Top Hardware Bottlenecks for Dynamic LLM Shapes: Dynamic input shapes in LLMs primarily bottleneck GPUs and NPUs by disrupting their fixed SIMD vector and tensor widths, leading to inefficient utilization of Tensor Cores. This variability also exacerbates memory bandwidth limitations and causes memory waste through fragmentation and duplication, especially in managing the KV cache, which dynamically grows with sequence length.
- Beyond Throughput: Dynamic Shapes' Hidden Costs: In addition to up to 23x throughput loss, dynamic shapes introduce significant hidden costs, including increased inference latency due to Just-In-Time (JIT) compilation overheads and kernel re-specialization. They also lead to higher memory consumption and waste through padding and inefficient KV cache management, alongside reduced energy efficiency as hardware cannot be optimally utilized.
- Compiler's Toughest Dynamic Shape Challenges: Compilers face major hurdles with dynamic LLM shapes, primarily in efficient kernel fusion and memory allocation when tensor dimensions are unknown at compile time. Generating optimized code and scheduling operations for arbitrary input sizes is challenging, often necessitating runtime specialization or recompilation, which adds significant latency and complexity.
Sources
Open the full topic