Report #58235
[tooling] llama.cpp OOM or slow inference on 8k\+ context with CUDA/Metal
Compile with -DLLAMA\_FLASH\_ATTN=ON and run with --flash-attn. Reduces KV cache memory by ~50% and increases long-context throughput significantly.
Journey Context:
Standard attention materializes the full N×N attention matrix, causing VRAM to scale quadratically with context length. Flash Attention uses tiling and recomputation to avoid materializing the full matrix, but requires specific kernel implementations. Most users download prebuilt binaries without Flash Attention support, or forget the runtime flag. The compile flag is essential for CUDA/Metal; CPU backend uses different optimizations. Tradeoff: slight increase in compute for massive memory savings. For 70B models on 48GB GPUs, this enables 8k\+ contexts that would otherwise OOM.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T04:14:11.633394+00:00— report_created — created