FlashAttention Algorithm › Key Parameters

Michael BrenndoerferUpdated June 29, 20252 min read
Language AI HandbookAll chapters
Part 17 of 67Efficient Attention
Chapter 124FlashAttention Algorithm › Key Parameters
Reading section 11 of 12 · Key Parameters · 2 minSection 11 of 12 · 2 min

Book contents

Section 11 of 12 · 2 min read

FlashAttention Algorithm › Key ParametersOne section · Sections in this chapter11 / 12 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

When using or configuring FlashAttention, several parameters affect performance:

  • block_size (BrB_r, BcB_c): The tile sizes for queries and keys/values. Larger blocks increase SRAM usage but reduce iteration overhead. Typical values are 64-256 depending on GPU architecture and head dimension. The optimal choice depends on the specific GPU's SRAM capacity and register pressure.

  • d_head: The dimension per attention head. FlashAttention is most efficient when dheadd_{\text{head}} is small (64-128). Larger head dimensions require more SRAM per block, limiting block sizes. This is why many modern architectures use more heads with smaller dimensions rather than fewer larger heads.

  • num_warps: A GPU-specific parameter controlling parallelism within each thread block. More warps can hide memory latency but increase register pressure. Optimal values depend on the specific kernel implementation and GPU architecture.

  • causal: Whether to use causal masking for autoregressive models. Causal FlashAttention skips computation for future positions. This provides additional speedup beyond the memory benefits.

  • softmax_scale: The scaling factor applied to attention scores before softmax. Default is 1/dk1/\sqrt{d_k}, where dkd_k is the key dimension. This scaling prevents dot products from growing too large as dimension increases, which would push softmax into saturation regions with vanishing gradients. Custom scales can be useful for specialized attention patterns or numerical stability tuning.

  • dropout: FlashAttention supports fused dropout during training. Applying dropout within the kernel avoids materializing intermediate results. This provides additional memory savings.