LightSeq: A High Performance Inference Library for Sequence Processing and Generation

Xiaohui Wang, Ying Xiong, Yang Wei, Mingxuan Wang, Lei LiarXiv 2020

Introduction

Transformer-based models like BERT and GPT have set new benchmarks in Natural Language Processing (NLP). However, their massive parameter counts and complex computational graphs lead to significant latency during inference. In industrial settings, where real-time response is critical, standard deep learning frameworks often fall short. LightSeq, an open-source CUDA library from ByteDance, addresses these challenges by providing a highly optimized inference engine for sequence processing and generation. It achieves up to a 14x speedup over TensorFlow and consistently outperforms specialized libraries like NVIDIA’s Faster Transformer.

Optimization Methods

LightSeq's performance gains are rooted in three core engineering strategies designed to minimize overhead and maximize GPU utilization.

1. Operation Fusion

Standard frameworks execute layers by launching multiple small GPU kernels, incurring overhead for each launch and requiring frequent reads/writes to slow video memory (VRAM). LightSeq fuses these operations into custom CUDA kernels. By keeping intermediate data in fast GPU registers, it minimizes memory I/O and kernel launch overhead.

2. Hierarchical Video Memory Reuse

To eliminate the latency associated with dynamic memory allocation, LightSeq pre-calculates the maximum memory required based on a predefined sequence length. It then multiplexes this memory, allowing non-dependent intermediate results to share the same physical space, thereby reducing the overall memory footprint and allocation lag.

3. Decoding Optimization

Text generation is often bottlenecked by the decoding step, where the model selects the next token from a large vocabulary. LightSeq introduces a "retrieve and re-rank" strategy that avoids full Softmax calculations for the entire vocabulary when only the top candidates are needed. This significantly reduces the computational cost of beam search and sampling.

Key Insights: The GEMM Bottleneck

Analysis of LightSeq’s performance reveals that General Matrix Multiplication (GEMM) operations account for 82% to 88% of total latency. This indicates that the library has effectively minimized non-computational overheads like memory movement and kernel management. Consequently, the remaining latency is primarily driven by the fundamental mathematical operations required by the model architecture.

Performance Results

LightSeq demonstrates substantial improvements across various benchmarks compared to both general-purpose frameworks and other specialized libraries:

  • Framework Comparison: It delivers up to a 14x speedup compared to TensorFlow for machine translation tasks.
  • Specialized Library Comparison: LightSeq provides a 1.4x speedup over NVIDIA’s Faster Transformer in both beam search and sampling scenarios.
  • Scalability: Unlike many libraries that degrade with larger batches, LightSeq maintains high efficiency, making it ideal for high-throughput production environments.

Conclusion and Future Work

LightSeq offers a comprehensive and high-performance solution for deploying Transformer, GPT, and VAE models. While it has pushed non-computational efficiency to its limits, the dominance of GEMM operations suggests that future optimizations will need to target core mathematical kernels. The development team plans to expand support for additional model architectures and further refine decoding strategies for even broader industrial and research applicability.

Summary updated

BibTeX
@misc{wang2020lightseq,
  author = {Xiaohui Wang and Ying Xiong and Yang Wei and Mingxuan Wang and Lei Li},
  title = {{LightSeq: A High Performance Inference Library for Sequence Processing and Generation}},
  year = {2020},
  eprint = {2010.13887},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2010.13887},
}
Figure