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]
The top 3
- 23x Speedup: Constrained Dynamic Shapes Redefine LLM Prefill: The shift from simple operation-level padding to input-level constrained dynamic shapes, where prompts are padded once to hardware-friendly multiples, has boosted LLM prefill throughput by over 23 times on GPUs and NPUs, enabling efficient edge inference.
- Bucketing Strategy: Reducing Padding Waste for Varied Inputs: Bucketing optimizes dynamic input handling by grouping sequences of similar lengths into 'buckets' and then padding only within those groups, significantly reducing memory waste and unnecessary computation compared to padding all inputs to a single maximum length.
- Beyond Static Zeros: Learnable Padding & Sequence Packing Gains: Advanced padding now includes 'learnable padding modules' that adaptively extend input data for better downstream task performance, outperforming zero padding by up to 1.23% in classification accuracy. Additionally, 'sequence packing' combines multiple examples to eliminate padding waste, boosting GPU utilization with proper masking.
Sources
Open the full topic