Accelerating Transformer Pre-training with 2:4 Sparsity

Yuezhou Hu, Kang Zhao, Weiyu Huang, Jianfei Chen, Jun Zhu
4/2/2024
cs.LG

No official code found. Best implementation: yuezhouhu/2by4-pretrain (63 stars, BSD-3-Clause, last commit 2024-12-08). 1 more below.

Abstract

Training large transformers is slow, but recent innovations on GPU architecture give us an advantage. NVIDIA Ampere GPUs can execute a fine-grained 2:4 sparse matrix multiplication twice as fast as its dense equivalent. In the light of this property, we comprehensively investigate the feasibility of accelerating feed-forward networks (FFNs) of transformers in pre-training. First, we define a ``flip rate'' to monitor the stability of a 2:4 training process. Utilizing this metric, we propose three techniques to preserve accuracy: to modify the sparse-refined straight-through estimator by applying the masked decay term on gradients, to determine a feasible decay factor in warm-up stage, and to enhance the model's quality by a dense fine-tuning procedure near the end of pre-training. Besides, we devise two techniques to practically accelerate training: to calculate transposable 2:4 masks by convolution, and to accelerate gated activation functions by reducing GPU L2 cache miss. Experiments show that our 2:4 sparse training algorithm achieves similar convergence to dense training algorithms on several transformer pre-training tasks, while actual acceleration can be observed on different shapes of transformer block apparently. Our toolkit is available at https://github.com/huyz2023/2by4-pretrain.

View on arXivView PDF

Code Implementations(2)

BSD-3-Clause

Efficient 2:4 sparse training algorithms and implementations

631Cuda, PythonMay 27, 20241 years agoBSD-3-Clause
BSD-3-Clause

Code for "Accelerating Transformer Pre-training with 2:4 Sparsity"

280Shell, PythonMay 27, 20241 years agoBSD-3-Clause

Similar Papers

Cite this paper

@article{hu2024accelerating,
  title  = {Accelerating Transformer Pre-training with 2:4 Sparsity},
  author = {Yuezhou Hu and Kang Zhao and Weiyu Huang and Jianfei Chen and Jun Zhu},
  year   = {2024},
  eprint = {2404.01847},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2404.01847v3},
  journal = {ICML 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2404.01847.svg)](https://codeofpaper.com/paper/2404.01847)

Discussion