Flash attention is a faster way to compute attention, and it matters most on long prompts where the attention cost grows with context. Ollama has an OLLAMA_FLASH_ATTENTION setting that turns it on for models that support it. This guide enables it and shows how to tell whether it made a difference.
Before you start
- Ollama installed and running.
- A GPU with flash attention support (a recent NVIDIA card) or an Apple Silicon Mac; on plain CPU the gain is small.
- A terminal and a long prompt to test with.
Check the current setting
Ollama reads the variable at startup. Check whether it is already set in your shell:
echo $OLLAMA_FLASH_ATTENTION
An empty result means the default (off) is in use.
Set the variable and restart
Set it to 1 and restart Ollama so the change takes effect:
OLLAMA_FLASH_ATTENTION=1 ollama serve
On Linux with the systemd service, stop the service, add the variable to the service environment, and start it again. A running server does not pick the change up.
Test with a long prompt
Load a model and send a prompt of a few thousand tokens, for example by pasting a long document and asking for a summary. Time the first token and the total run, then repeat with the variable unset and compare. Keep the model, the prompt and the machine load the same for both runs.
Worked example
Worked example: paste a 3,000-word meeting note into a chat with qwen3:8b and ask for a five-bullet summary. With flash attention on, the prompt processing step should finish sooner; the exact saving depends on the GPU and the prompt length, and on a small prompt you may see no difference at all.
Expected result
UNTESTED in this guide: no server was restarted while writing it. The expected result is that Ollama starts normally with the variable set and a long prompt processes faster than with the default setting.
Limitations
Not every model or backend supports flash attention, and Ollama may ignore the setting silently for those models. Flash attention changes speed, not answer quality, so do not expect different replies.
