Constrained Shapes: Resolving LLM Dynamic Input vs. Hardware Mismatch
Constrained dynamic shapes tackle the fundamental conflict between variable LLM prompt lengths and hardware optimized for fixed-size computations. By applying padding once at the input and propagating these guarantees, this method allows downstream operations to utilize efficient fixed-size instructions, achieving up to 23x higher prefill throughput compared to baselines without dynamic shape optimizations.
The top 3
- Why LLMs Struggle: Hardware Prefers Fixed Inputs: Modern hardware, particularly GPUs and NPUs, is optimized for fixed-size vector and tensor instructions to achieve peak performance. This creates a fundamental mismatch with Large Language Models, which inherently process user prompts of unpredictable, dynamic lengths, leading to significant inefficiencies during the initial 'prefill' inference stage. [1]
- Padding's Evolution: From Simple Fix to Smart Optimization: Padding is a core technique to resolve dynamic input shapes by adding special tokens to shorter sequences, making all inputs in a batch uniform for efficient GPU processing. While basic padding can waste computation, advanced 'input-level padding' combined with 'constrained dynamic shapes' applies padding once at the input and propagates hardware-friendly shape guarantees throughout the network, significantly boosting prefill throughput by up to 23x. [1, 3]
- Beyond Padding: Dynamic Batching & Compiler-Driven Shape Control: More sophisticated solutions for dynamic shapes include dynamic and continuous batching, which group varied-length requests to maximize GPU utilization and throughput. Additionally, compiler-level strategies introduce 'constrained dynamic shape' infrastructure that provides global shape guarantees, reducing the need for costly runtime recompilation and enabling efficient execution across diverse hardware targets like GPUs and NPUs. [1, 7, 8, 14]
Sources
Open the full topic