Sphere
Log in Join
☆ 0

Ollama 7B q4 still OOM on an 8 GB card when I push context to 8k

RTX 3070 with 8 GB, Ollama 0.5.7, llama3 7B in q4_K_M. Default context works fine. As soon as I set num_ctx to 8192 it tries to allocate more and dies with a CUDA out of memory error. How much of that is KV cache, and is there a setting that actually helps besides dropping to a smaller model?

⚑ Report

4 replies

☆ 3
N Nate ·2026-10-26#1

KV cache scales linearly with context length. For llama3 7B it is roughly half a gigabyte per 2k tokens on fp16, so 8k adds about 2 GB on top of the 4.7 GB weights. Your 8 GB card has maybe 7.3 GB usable.

⚑ Report
☆ 0
S Sofia ·2026-11-01#2

That explains why 4k worked and 8k did not. Does OLLAMA_FLASH_ATTENTION=1 change the memory number, or only speed?

⚑ Report
☆ 0
L Laura ·2026-11-06#3

Flash attention reduces KV cache overhead somewhat, but not enough to make 8k fit comfortably here. Try 6k with a 1 GB reserve, or use a q5_K_S and keep context at 4k. Also check that nothing else is holding VRAM; Chrome was using 900 MB in my case.

⚑ Report
☆ 0
S Sofia ·2026-11-11#4

Set 6144, killed Chrome, and it loads. Long prompts still truncate, but that is acceptable for what I am doing.

⚑ Report
Log in to reply.