Striped Attention: Faster Ring Attention for Causal Transformers

William Brandon, Aniruddha Nrusimha, Kevin Qian, Zachary Ankner, Tian Jin +2 more
11/15/2023
cs.LGcs.CL

Official code: exists-forall/striped_attention (50 stars, Apache-2.0, last commit 2023-11-10).

Abstract

To help address the growing demand for ever-longer sequence lengths in transformer models, Liu et al. recently proposed Ring Attention, an exact attention algorithm capable of overcoming per-device memory bottle- necks by distributing self-attention across multiple devices. In this paper, we study the performance characteristics of Ring Attention in the important special case of causal transformer models, and identify a key workload imbal- ance due to triangular structure of causal attention computations. We propose a simple extension to Ring Attention, which we call Striped Attention to fix this imbalance. Instead of devices having contiguous subsequences, each device has a subset of tokens distributed uniformly throughout the sequence, which we demonstrate leads to more even workloads. In experiments running Striped Attention on A100 GPUs and TPUv4s, we are able to achieve up to 1.45x end-to-end throughput improvements over the original Ring Attention algorithm on causal transformer training at a sequence length of 256k. Furthermore, on 16 TPUv4 chips, we were able to achieve 1.65x speedups at sequence lengths of 786k. We release the code for our experiments as open source

View on arXivView PDF

Code Implementations(1)

Apache-2.0
503Shell, PythonOct 24, 20232 years agoApache-2.0

Similar Papers

Cite this paper

@article{brandon2023striped,
  title  = {Striped Attention: Faster Ring Attention for Causal Transformers},
  author = {William Brandon and Aniruddha Nrusimha and Kevin Qian and Zachary Ankner and Tian Jin and Zhiye Song and Jonathan Ragan-Kelley},
  year   = {2023},
  eprint = {2311.09431},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2311.09431v1}
}

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/2311.09431.svg)](https://codeofpaper.com/paper/2311.09431)

Discussion