Dynamic Shape's Top Challenge in LLM Inference
Historically, dynamic input shapes in LLMs, such as varying sequence lengths, posed significant challenges for compilers like TVM's older Relay IR, leading to limited expressibility, deferred memory allocation, and performance degradation during AOT (ahead-of-time) compilation.
The top 3
- Top Memory Drain: KV Cache Fragmentation: Dynamic input and output lengths in LLMs cause severe memory fragmentation and waste in the Key-Value (KV) cache, with studies showing only 20.4%–38.2% of allocated KV cache memory is actually utilized, leading to out-of-memory errors and limiting concurrent requests.
- Hardware Underutilization from Fixed-Size Operations: Edge accelerators like GPUs and NPUs are optimized for fixed-size tensor instructions, but LLMs' dynamic shapes create a mismatch, forcing compilers to generate less efficient general code. This can lead to significantly lower throughput, with some solutions yielding up to 23x higher prefill throughput by addressing this bottleneck.
- Complexities of Dynamic Batching & Scheduling: The unpredictable length of LLM prompts and generated outputs makes efficient batching and scheduling extremely challenging. Traditional static or dynamic batching often results in GPU underutilization and increased latency, as shorter requests must wait for the longest sequence in a batch to complete.
Sources
Open the full topic