Report #53100
[tooling] llama.cpp runs out of VRAM or slows down dramatically with 32k\+ context windows
Add the --flash-attn flag to llama-server or llama-main. This enables FlashAttention-2 kernels, reducing KV-cache memory from O\(n²\) to O\(n\) and eliminating the quadratic attention computation bottleneck.
Journey Context:
Without this flag, llama.cpp uses standard attention which materializes the full N×N attention matrix. For 128k context at BF16, that's 32GB just for attention intermediates, plus the KV cache. FlashAttention uses tiling to keep computations in SRAM, reducing memory pressure and enabling 128k context on 24GB consumer cards. Many assume FlashAttention is only for training frameworks; llama.cpp implemented it in late 2023 but it's not the default because it requires specific head dimensions and doesn't support all custom RoPE types.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T19:37:24.721970+00:00— report_created — created