KV 캐시 원리: 컨텍스트 길이가 VRAM을 소모하는 방식
FP16 KV 공식을 단계별로 적용해 긴 컨텍스트가 여유 메모리를 줄이는 과정을 확인.
추정 공식 및 가용 메모리 계수
kv_cache_gb = (2 × layers × kv_heads × head_dim × context_tokens × bytes_per_val) / 1e9
Reference GQA 32-layer / 8 KV heads / 128 head_dim (FP16 KV)
| Configuration | Result | 상태 |
|---|---|---|
| 4,096 tokens (FP16 KV) | 0.54 GB KV cache | 추정 |
| 32,768 tokens (FP16 KV) | 4.29 GB KV cache | 추정 |
| 131,072 tokens (FP16 KV) | 17.18 GB KV cache (exceeds 16 GB cards alone) | 추정 |
| 131,072 tokens (Q8_0 / FP8 KV) | 8.59 GB KV cache (50% reduction) | 추정 |
- Model weights are fixed once loaded, while KV cache grows linearly with active context length.
- Inkling 2 Mini supports up to 1,000,000 official context tokens (Thinking Machines release), but filling long contexts on 24GB hardware requires KV quantization or much larger RAM.
- Grouped-Query Attention (fewer kv_heads) and 8-bit KV cache quantization are the two primary levers for keeping long contexts inside consumer VRAM.
FAQ
Why does a 16GB model fail on a 24GB GPU when I paste a long repo?
On a 24GB card (21.6GB usable), 16.2GB weights leave only ~5.4GB for runtime overhead and KV cache. At FP16, 32k–64k tokens can consume 4–8GB and trigger OOM or slow CPU spill.
How much memory does FP8 / Q8_0 KV cache save?
Switching KV precision from 16-bit (2 bytes/value) to 8-bit (1 byte/value) cuts KV cache memory exactly in half.
관련 모델
Inkling 2 Mini
looped-moe · 26.4B (3.4B 활성) 권장 양자화 nvfp4
가중치 크기 16.2GB
최소 메모리 24GB
Apache-2.0 모델 상세 →
Qwen 3.8 27B
dense · 27B 권장 양자화 Q4_K_M
가중치 크기 17GB
최소 메모리 24GB
— 모델 상세 →
Gemma 4 31B
dense · 31B 권장 양자화 Q4_K_M
가중치 크기 19.5GB
최소 메모리 24GB
Gemma Terms 모델 상세 →