# FlashAttention

> Canonical: https://skillalmanac.com/glossary/flash-attention | Last verified: 2026-11-24 | Index status: not offered to search engines

FlashAttention is an exact attention algorithm for Transformers that is aware of how data moves between GPU memory levels. It processes attention in blocks, called tiling, to reduce reads and writes to slower memory.

Also called: flash attention, FlashAttention-2, FlashAttention-3, flash attention 2, flash attention 3, flash-attn.

## In plain language

Attention is the step where a language model looks back over the text it has been given. Done the plain way, it moves a lot of data around inside the graphics chip, and that movement, not the arithmetic, can be the slow part. FlashAttention is a way of doing the same calculation in small blocks that fit in the chip's fastest memory, so there is less back-and-forth. It is like cooking with ingredients on the counter instead of walking to the pantry for each one. It gives the same answer as ordinary attention, so it does not make a model smarter. It also depends on the hardware and the software library you use, so it may not be available in every setup.

## Technical definition

The original paper (Dao et al., arXiv 2205.14135, submitted May 2022) argues that attention algorithms should account for data movement between levels of GPU memory, and presents FlashAttention as an exact algorithm that uses tiling to reduce reads and writes between GPU high-bandwidth memory and on-chip SRAM. FlashAttention-2 (arXiv 2307.08691, July 2023) changes work partitioning and parallelism to use the GPU better. FlashAttention-3 (arXiv 2407.08608) targets Hopper GPUs by overlapping computation and data movement and adding FP8 support. Hugging Face's Transformers documentation says FlashAttention tiles attention computations and avoids large intermediate tensors to reduce memory footprint, and shows it selected with the attn_implementation argument.

## How it shows up when you use agents

In Claude Code, Codex or Cursor you do not choose an attention algorithm. The service that runs the model does. FlashAttention matters when you run models yourself, for example a local model behind a coding agent, or when you fine-tune one. There it appears as a setting or a package: Hugging Face's Transformers documentation shows it chosen through the attn_implementation argument when a model is loaded, and describes it as lowering memory traffic.

The practical point is that FlashAttention aims at the same output as standard attention, computed with less data movement. It targets the cost of attention on [long inputs](/glossary/context-window), which grows with sequence length. It does not enlarge a model's context window, and it does not change what the model has learned. The [KV cache](/glossary/kv-cache) is a different memory cost: it stores values from earlier tokens during generation, while FlashAttention changes how the attention calculation is carried out.

What breaks when this is misunderstood: people install it expecting a fix for out-of-memory errors that come from model weights or the cache, or expect different answers. Support depends on the model, the GPU and the library version, as the three papers describe different GPU targets. Next action: read your serving library's documentation for the supported attention backends, enable one setting at a time, and compare memory use and output quality on your own workload. See [Attention mechanism](/glossary/attention-mechanism) and [Transformer](/glossary/transformer).

## Common confusions

- **FlashAttention versus approximate attention.** The first paper presents FlashAttention as exact attention. Its abstract contrasts it with approximate methods that reduce compute.
- **FlashAttention versus the KV cache.** One is a way of computing attention with fewer memory reads and writes. The other stores earlier keys and values for reuse during generation. A setup can use both.
- **FlashAttention versus FlashAttention-2 and -3.** They are separate papers with different focus: the second reworks parallelism and work partitioning, and the third targets Hopper GPUs. The version you can use depends on your hardware and software.
- **Myth.** FlashAttention gives a model a longer context window. A window is a property of the model and service; the algorithm changes how attention is computed, and the first paper reports that it enables longer context in Transformers.

## Worked examples in this catalogue

### [local-model-sizing](https://skillalmanac.com/skills/skill-almanac/local-model-sizing)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The skill works out whether an open-weight language model will run on a given GPU, Mac or PC, with a script that computes weight, KV-cache and overhead memory per quantization.

Why it exercises the concept: The catalogue has no attention-kernel skills, so this is a contrast case. Its one-line description does not mention attention kernels; it shows the kind of memory budgeting that kernel choices such as FlashAttention relate to.

### [Self-Hosting an AI Agent: What You Take On](https://skillalmanac.com/learn/self-hosted-ai-agent-considerations)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A guide to what you take on when an AI agent runs on your own machine, including the model server and the check that a model fits your hardware.

Why it exercises the concept: Attention kernels are a server-side setting you meet only when you run models yourself. The guide does not name FlashAttention, so it is a contrast case about the self-hosting context.

### [What Is an LLM? The Facts Agent Users Need](https://skillalmanac.com/learn/what-is-an-llm-for-agent-users)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A guide explaining that an LLM predicts text one token at a time inside a fixed context window, and the context, cost and error facts that follow.

Why it exercises the concept: The papers motivate FlashAttention by the cost of attention on long sequences. The guide explains the context-window side from a user's view and does not discuss the algorithm.

## Related terms

- [Attention mechanism](https://skillalmanac.com/glossary/attention-mechanism.md)
- [Transformer](https://skillalmanac.com/glossary/transformer.md)
- [Inference](https://skillalmanac.com/glossary/inference.md)
- [Context window](https://skillalmanac.com/glossary/context-window.md)
- [Large language model (LLM)](https://skillalmanac.com/glossary/large-language-model.md)
- [KV cache](https://skillalmanac.com/glossary/kv-cache.md)

## Sources

- [FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness — Dao et al.](https://arxiv.org/abs/2205.14135), arXiv (accessed 2026-11-24)
- [FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning — Dao](https://arxiv.org/abs/2307.08691), arXiv (accessed 2026-11-24)
- [FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision — Shah et al.](https://arxiv.org/abs/2407.08608), arXiv (accessed 2026-11-24)
- [Inference optimization overview](https://huggingface.co/docs/transformers/perf_infer_gpu_one), Hugging Face (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-24. [Glossary index](https://skillalmanac.com/glossary.md).
