Web Asset House Guides
Local AI

Cut Ollama's Memory Use: Flash Attention and K/V Cache Quantization (q8_0, q4_0)

By Web Asset House Studio ·

Note: Some future links on this site may be affiliate links. We never claim hands-on testing; guides are researched from the public sources listed in each article.

How we wrote this: A plain-English summary of the official Ollama FAQ, checked October 29, 2026. We haven't measured these settings ourselves. Effects depend on the model and task.

Long contexts eat memory because the model keeps a key/value (K/V) cache of everything in the conversation. Ollama offers two server settings to shrink it.

Flash Attention

The Ollama FAQ calls Flash Attention a feature of most modern models that can significantly reduce memory use as context grows. Ollama turns it on automatically when the backend and devices support it.

K/V cache quantization

With Flash Attention on, the K/V cache itself can be quantized using OLLAMA_KV_CACHE_TYPE:

Type Memory vs. default FAQ notes
f16 Baseline (default) High precision, highest memory
q8_0 About half Very small loss in precision, usually no noticeable impact. Recommended if not using f16
q4_0 About a quarter Small-to-medium loss, may be more noticeable at long context

Two caveats from the FAQ:

The FAQ says you may need to experiment to find the right balance between memory and quality.

How to set it

These are server environment variables. Set them, then restart Ollama:

When it helps

This is separate from the model's own quantization (for example a Q4_K_M GGUF). See what is a GGUF file and AI model memory calculator.

Sources

← All Local AI guides · All guides