[论文解读] TurboTransformers: An Efficient GPU Serving System For Transformer Models
TurboTransformers 是一个针对 Transformer 模型的 GPU 优化推理系统,通过一种新颖的运行时和推理框架,解决了高计算需求和可变长度输入的问题。它通过动态编程批处理调度器、针对可变序列优化的内存分配器,以及 Softmax 和 LayerNorm 的并行批处理归约内核,实现了业界领先的吞吐量——最高比 PyTorch 提高 4.06 倍,同时保持低内存占用,并支持与 PyTorch 无缝集成。
The transformer is the most critical algorithm innovation of the Nature Language Processing (NLP) field in recent years. Unlike the Recurrent Neural Network (RNN) models, Transformers can process on dimensions of sequence lengths in parallel, therefore leading to better accuracy on long sequences. However, efficient deployments of them for online services in data centers equipped with GPUs are not easy. First, more computation introduced by transformer structures makes it more challenging to meet the latency and throughput constraints of serving. Second, NLP tasks take in sentences of variable length. The variability of input dimensions brings a severe problem to efficient memory management and serving optimization. This paper designed a transformer serving system called TurboTransformers, which consists of a computing runtime and a serving framework to solve the above challenges. Three innovative features make it stand out from other similar works. An efficient parallel algorithm is proposed for GPU-based batch reduction operations, like Softmax and LayerNorm, major hot spots besides BLAS routines. A memory allocation algorithm, which better balances the memory footprint and allocation/free efficiency, is designed for variable-length input situations. A serving framework equipped with a new batch scheduler using dynamic programming achieves the optimal throughput on variable-length requests. The system can achieve the state-of-the-art transformer model serving performance on GPU platforms and can be seamlessly integrated into your PyTorch code with a few lines of code.
研究动机与目标
- 为在线 GPU 推理中部署 Transformer 模型所面临的高计算成本和可变长度输入挑战提供解决方案。
- 在具有不同序列长度的数据中心环境中,提升推理吞吐量并降低延迟。
- 设计一种运行时和推理框架,使其在可变长度场景下优于现有解决方案(如 PyTorch、ONNX Runtime 和 TensorRT)。
- 在不牺牲分配速度或增加内存占用的前提下,实现高效的内存管理。
- 通过最小的代码修改,无缝集成到 PyTorch 工作流中。
提出的方法
- 提出一种针对 GPU 内存层次结构和线程级并行性的 Softmax 和 LayerNorm 操作并行批处理归约算法。
- 引入一种基于序列长度感知的内存分配器,以在可变长度输入下平衡内存占用和分配效率。
- 采用基于动态规划的批处理调度器,将可变长度请求分组,以最小化零填充并最大化 GPU 利用率。
- 通过最小代码修改与 PyTorch 集成,支持直接用 TurboTransformers 的优化运行时替换 PyTorch 后端。
- 利用 Tensor Core 加速混合精度推理,在不损失精度的前提下提升性能。
- 通过智能请求排序和动态批处理形成,避免固定长度填充,优化批处理效率。
实验结果
研究问题
- RQ1如何在 GPU 上高效并行化 Softmax 和 LayerNorm 操作,以减少 Transformer 推理中的延迟?
- RQ2针对可变长度的 Transformer 输入,哪种内存分配策略能最好地平衡内存占用和分配速度?
- RQ3基于动态规划的批处理调度器是否能在可变长度请求的吞吐量和延迟方面优于朴素批处理?
- RQ4在可变长度工作负载下,TurboTransformers 与 PyTorch、ONNX Runtime 和 TensorRT 相比,在推理吞吐量和内存效率方面表现如何?
- RQ5Tensor Core 优化能在多大程度上提升性能而不影响推理精度?
主要发现
- 在可变长度输入(序列长度 2–100)下,TurboTransformers 实现了每秒 402 个请求的峰值推理吞吐量,比 PyTorch-Nobatch 提高了 4.06 倍。
- 动态规划批处理调度器在 402 个请求/秒的吞吐量下,将平均延迟降低至 7.49ms,尽管长序列的延迟略高,但吞吐量仍优于朴素批处理。
- 在可变长度输入(5–500 个 token)下,TurboTransformers 通过 Tensor Core 优化实现了每秒 144 个请求的吞吐量,比 PyTorch-Nobatch 提高了 2.4 倍。
- 即使在处理长序列或大批次时,系统内存占用也小于 ONNX Runtime,避免了因未释放中间张量导致的内存膨胀。
- 在固定长度基准测试中,TurboTransformers 的运行时性能与 ONNX Runtime 和 TensorRT 相当或更优,同时支持可变长度输入。
- 内存分配器通过高效管理不同序列长度下的中间张量分配,减少了内存浪费,提升了整体系统可扩展性。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。