passdrill
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 023/024 medium

Dao et al. (2022), "FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness," speed up the standard self-attention computation on GPUs without changing the attention mechanism's mathematical result. What kind of optimization does FlashAttention make, and what does it NOT do?

  1. It reduces the number of reads and writes between the GPU's high-bandwidth memory and its much faster on-chip SRAM by tiling the computation and avoiding materializing the full attention-score matrix, while still computing exactly the same attention output as the standard formula, not an approximation of it
  2. It approximates the full quadratic attention computation with a sparse or low-rank attention pattern, trading some accuracy in the attention output for a reduction in the number of floating-point operations performed
  3. It reduces the number of floating-point operations attention requires by lowering the numerical precision of the query and key vectors, at the cost of a less numerically exact attention output
  4. It restructures the attention computation to run entirely within CPU memory instead of GPU memory, trading GPU compute for cheaper CPU compute
Next card → Shuffle