A Length Adaptive Algorithm-Hardware Co-design of Transformer on FPGA Through Sparse Attention and Dynamic Pipelining

Hongwu Peng, Shaoyi Huang, Shiyang Chen, Bingbing Li, Tong Geng, Ang Li, Weiwen Jiang, Wujie Wen, Jinbo Bi, Hang Liu, Caiwen Ding · DOI

Abstract

Transformer models are the cornerstone of modern Natural Language Processing (NLP), yet their deployment is often constrained by the quadratic complexity of self-attention and the computational waste associated with variable-length input sequences. This paper presents a hardware-algorithm co-design that addresses these challenges through a quantization-based sparse attention mechanism and a dynamic, length-adaptive hardware pipeline. Implemented on a Xilinx Alveo U280 FPGA, the proposed system achieves a 2.6× speedup and 4× higher energy efficiency compared to high-end GPUs, with minimal impact on model accuracy.

Introduction

While Transformers have revolutionized NLP, they remain resource-intensive. Two primary bottlenecks impede their efficient deployment:

  1. The Attention Bottleneck: Standard self-attention mechanisms exhibit $O(n^2)$ computational complexity relative to sequence length $n$. In long-sequence tasks, attention can account for over 60% of total inference time.
  2. The Padding Problem: Parallel architectures like GPUs typically require fixed-length inputs. Real-world datasets often feature highly variable sequence lengths, necessitating "zero-padding" to the maximum length in a batch. This leads to significant redundant computation, sometimes exceeding 5.7× overhead.
Transformer architecture and computational breakdown.

Methodology

The researchers developed a two-pronged co-design approach to mitigate these bottlenecks.

Sparse Attention via Q & K Quantization

The authors observe that the Softmax operation in self-attention is primarily sensitive to the relative rank of attention scores rather than their absolute precision. By quantizing the Query (Q) and Key (K) matrices into ultra-low precision (1-bit or 4-bit), the hardware can perform a rapid "pre-selection" to identify the Top-k most important candidates. Full-precision computation is then reserved for these selected tokens, effectively reducing the complexity from $O(n^2)$ to $O(n)$.

Length-aware Hardware Scheduling

To address the padding problem, the design moves away from static pipelining in favor of a dynamic, length-adaptive approach.

State machine for dynamic hardware scheduling.

The Transformer encoder is decomposed into three coarse-grained stages. A dedicated state machine dynamically manages hardware resources and buffers to "fill" idle pipeline slots (bubbles) created by varying sequence lengths. Furthermore, the design utilizes loop fusion for operators such as scaling, masking, and exponential functions. This strategy keeps data on-chip, significantly reducing the overhead of moving data to and from off-chip High-Bandwidth Memory (HBM).

Experimental Results

The system was evaluated using standard NLP benchmarks, including SQuAD v1.1, RTE, MRPC, and WikiText-2, on a Xilinx Alveo U280 FPGA.

  • Performance Gains: The design achieved an 80.2× speedup over CPUs and a 2.6× speedup over optimized GPU implementations (Tesla V100).
  • Energy Efficiency: The FPGA-based accelerator demonstrated 4× higher energy efficiency than state-of-the-art GPU solutions.
  • Accuracy Preservation: The sparse approximation introduced a minor accuracy loss of approximately 1.8%, representing a favorable trade-off for the substantial performance improvements.

Conclusion

This research highlights the advantages of FPGA-based co-design for Transformer acceleration. By leveraging rank-preserving quantization and dynamic scheduling, the proposed architecture effectively eliminates the primary computational inefficiencies of standard Transformer models. Future work will explore dynamic adjustment of the Top-k parameter and the application of these techniques to auto-regressive decoder models.

Summary updated

BibTeX
@inproceedings{peng2022length,
  author = {Hongwu Peng and Shaoyi Huang and Shiyang Chen and Bingbing Li and Tong Geng and Ang Li and Weiwen Jiang and Wujie Wen and Jinbo Bi and Hang Liu and Caiwen Ding},
  title = {{A Length Adaptive Algorithm-Hardware Co-design of Transformer on FPGA Through Sparse Attention and Dynamic Pipelining}},
  booktitle = {DAC},
  year = {2022},
  doi = {10.1145/3489517.3530585},
}
Figure