Abstract
TurboTransformers is a high-performance GPU serving system designed specifically for Transformer models. It overcomes the dual challenges of massive computational demand and variable-length inputs by introducing fused GPU kernels, a graph-aware memory allocator, and a dynamic programming-based batch scheduler that minimizes the "padding tax." Evaluation shows that TurboTransformers achieves up to a 2.44x speedup over PyTorch and significantly reduces peak memory usage, making it a highly efficient solution for real-time NLP production environments.
Introduction
Transformer-based models, such as BERT, GPT, and XLNet, have revolutionized Natural Language Processing (NLP). However, deploying these models in production environments presents significant engineering hurdles. First, they are computationally intensive, requiring billions of floating-point operations (Gflops) even for relatively short sequences. Second, unlike image data which can be resized to fixed dimensions, natural language is inherently variable in length.
Standard serving systems often handle variable-length inputs by "padding" shorter sentences with zeros to match the longest one in a batch. This approach wastes memory and forces the GPU to perform useless calculations on zeros, significantly hurting both throughput and latency. TurboTransformers addresses these issues through innovations at the computing, memory, and serving layers.
System Design and Innovations
TurboTransformers introduces three major technical innovations to optimize the inference pipeline:
1. Kernel Fusion and Optimized Reductions
The system reorganizes the model's computation graph by fusing multiple small operations into single, efficient GPU kernels. This reduces the overhead associated with launching numerous small tasks and minimizes slow data transfers to main memory. Specifically, the system redesigns "Batch Reduction" operations, such as Softmax and LayerNorm, to exploit three levels of hardware parallelism: streaming processors, warps, and instructions.
2. Sequence-Length-Aware Memory Allocator
Rather than relying on a generic memory manager, TurboTransformers utilizes the model's computation graph to predict the lifecycle of every intermediate tensor. It organizes memory into "chunks" and employs a specialized algorithm to reuse these chunks based on the specific length of the current request. This graph-aware approach drastically reduces the overall memory footprint.
3. DP-Based Batch Scheduler
To maximize throughput, the system groups incoming requests into batches. Instead of a simple first-come-first-served approach, TurboTransformers uses a Dynamic Programming (DP) algorithm to find the mathematically optimal way to group requests of different lengths. This minimizes the total amount of zero-padding required, effectively reducing the "padding tax" that plagues traditional systems.
Experimental Evaluation
The system was evaluated using several popular Transformer variants, including BERT-base, Albert-large, DistilBert, and a Seq2Seq Decoder for translation tasks. Testing was performed on an NVIDIA RTX 2060 GPU using sequence lengths ranging from 5 to 500 tokens to simulate real-world variability.
Key Results
- Speedups: TurboTransformers achieved up to a 2.44x speedup over PyTorch for BERT inference on short sequences.
- Memory Efficiency: Peak GPU memory usage for BERT was reduced to 663 MB, compared to 1307 MB for PyTorch and 1653 MB for ONNX Runtime.
- Throughput: The DP-based batching strategy improved serving throughput by 4.06x compared to unbatched PyTorch.
- Usability: The system is designed for ease of use, allowing integration into existing PyTorch workflows with minimal code changes.
Discussion and Conclusion
TurboTransformers demonstrates that optimizing "non-GEMM" kernels (like Softmax and LayerNorm) is essential for state-of-the-art performance, as these can occupy up to 38% of execution time in standard implementations. By leveraging graph-awareness, the system manages memory more intelligently than general-purpose allocators.
While TurboTransformers excels at handling variable-length inputs in real-time, it currently does not utilize some of the "offline" hardware-specific tuning found in systems like NVIDIA's TensorRT. Future work may incorporate these hardware-specific optimizations while maintaining the system's flexibility for dynamic workloads. Overall, TurboTransformers provides a robust and efficient framework for serving heavy Transformer models at scale.
Summary updated