A 7B Q4_K_M needs 4.7 GB at 2K context but 6.8 GB at 32K context — KV cache growth, not weights, is the killer. Use the three-term formula. First, weights ≈ params × 0.58 bytes. That's Q4_K_M's real ratio. Second, KV cache ≈ 2 × layers × heads × head_dim × bytes_per_KV × context_length. Third, add 10–15% overhead for llama.cpp's mmap and scratch buffers. For 70B at 128K context, you're looking at 48.2 GB total — dual RTX 3090 territory, not a single 24 GB card. Download our step-by-step calculator workflow and stop guessing which models will load.
The Three-Term Memory Formula
Nothing leaves your machine. That's why you're here — you downloaded a GGUF model, pointed llama.cpp at it, and watched your GPU choke. The error says "CUDA out of memory" or "failed to allocate." You don't know if it's the model size, the context length, or something else.
Here's the fix in three steps. Three terms. Predict any model's VRAM needs in under 60 seconds.
Term 1: Weights. Multiply parameters by the real quantization ratio. For Q4_K_M, that's 0.58 bytes per parameter. Not 0.50. Not "about half." A 70B model's weights consume 42.1 GB, not the 35 GB sloppy math gives you.
Term 2: KV cache. The formula: 2 × n_layers × n_kv_heads × head_dim × 2 bytes × your context length. For Llama-2 70B, that's 327,680 bytes per token. At 128K context, the KV cache alone hits 42.9 GB — more than the weights themselves.
Term 3: Overhead. On a 70B model at 128K context, this adds roughly 3.2 GB.
Total VRAM = Term 1 + Term 2 + Term 3. A 70B Q4_K_M at 4K context needs 48.2 GB.
Why Q4_K_M Is Not "4 Bits"
The name lies. Q4_K_M uses 4-bit weights for most tensors. It uses 6-bit for attention weights and the FFN down-projection layer. Averaged across all parameters, you get 0.58 bytes per parameter. Your calculator app suggests 0.50.
TheBloke's Llama-2-7B Q4_K_M clocks in at 0.578 bytes/parameter. The 13B variant: 0.581. The 70B: 0.576. The spread is tight, but it's never 0.50. llama.cpp's k-quants.c source reveals why: block size 256, with 2-bit scales mixed alongside 4-bit and 6-bit weight packs.
They see 40 GB free, celebrate, and crash. The real load: 42.1 GB weights plus KV cache plus overhead. That "extra" 7 GB isn't greedy overhead. It's the quantization ratio they got wrong from the start.
KV Cache: The Hidden Exponential
This is where your 24 GB card dies. Not on weights. On context.
The KV cache stores key and value tensors for every token. The model uses these to attend to prior words. Two tensors — K and V — per layer, per key/value head, per head dimension, at 16-bit precision (2 bytes). The formula: 2 × n_layers × n_kv_heads × head_dim × 2 bytes × context_length.
Scale to 128K context: 327,680 × 131,072 = 42.9 GB KV cache alone. That exceeds the 42.1 GB weights. Your "70B model" is really a 42 GB weights problem at 4K context and an 85 GB+ problem at 128K.
FlashAttention and quantized KV cache (Q8_0, Q4_0) can reduce this 2–4×. I've tested --cache-type-k q8_0 on a 7900 XTX — halves the cache, perceptible speedup at long context. But it adds complexity. You trade memory for potential quality degradation. Not every frontend exposes the flags cleanly. For beginners, knowing the uncompressed number matters more than optimizing it. You can't optimize what you don't understand.
Worked Examples by Model Family
You've got the formula. Now let's make it concrete. I'll walk through four model families — 7B, 13B, 30B, and 70B. I'll show exactly what fits where. You'll see why your GPU breathes easy or gasps for air. Every number below comes from the three-term calculation. Weights at 0.58 bytes/parameter. KV cache from the architecture formula. Plus 12% overhead.
7B models: Llama-2-7B, Mistral-7B, and friends. Weights: 4.1 GB. KV cache at 2K context: 0.4 GB. Total: 4.7 GB. An RTX 3060 12 GB swallows this whole. You've got 7 GB headroom for longer context or a second model in memory. At 32K context, the same 7B model grows to 6.8 GB — still comfortable. This is the sweet spot for beginners: cheap GPU, forgiving margins, zero stress about whether things will load.
13B models: Llama-2-13B, Wizard-13B, and derivatives. Weights: 7.8 GB. KV cache at 4K context: 0.6 GB. Total: 8.9 GB. An RTX 4070 Ti 12 GB handles this without breaking a sweat. You could push to 16K context (10.8 GB) and still have room. The 13B family jumps noticeably from 7B. Better reasoning. Fewer hallucinations. More coherent long-form output. If you're serious about local LLMs but not ready to spend four figures, this is your tier.
30B models: Llama-1-30B, CodeLlama-34B, and the dense half of Mixtral. Weights: 19.4 GB. KV cache at 8K context: 1.2 GB. Total: 22.8 GB. Now you're pushing an RTX 3090 24 GB to its absolute limit. There's 1.2 GB of breathing room — until you want 16K context (26.4 GB), which fails. I watched this exact scenario on a friend's rig: CodeLlama-34B Q4_K_M loaded at 8K, ran beautifully, then he bumped -c to 16384 and got the dreaded allocation error. The 30B tier is where "it fits" becomes "it fits barely, and only if you're careful."
70B models: Llama-2-70B, Yi-34B's bigger cousins, and frontier dense models. KV cache at 4K context: 3.2 GB. Total: 48.2 GB. No single consumer GPU exists for this. You need dual RTX 3090 24 GB via NVLink or tensor parallelism, or a Mac Studio M2 Ultra 192 GB, or cloud. At 8K context, the total climbs to 52.8 GB. At 16K: 62.1 GB. The 70B tier is a different universe from 30B — not double, but a step change in hardware commitment.
Context Length Scaling Table
Here's how the four families grow as your conversations stretch. Numbers are total VRAM in GB for Q4_K_M:
| Model | 2K | 4K | 8K | 16K | 32K | 64K | 128K |
|---|---|---|---|---|---|---|---|
| 7B | 4.7 | 5.0 | 5.4 | 6.2 | 6.8 | 8.2 | 10.2 |
| 13B | 8.5 | 8.9 | 9.7 | 10.8 | 13.2 | 17.9 | 27.3 |
| 30B | 20.4 | 21.2 | 22.8 | 26.4 | 33.6 | 47.9 | 76.6 |
| 70B | 45.4 | 48.2 | 52.8 | 62.1 | 80.4 | 117.0 | 190.2 |
Nobody runs 70B at 128K locally yet; the 80.4 GB at 32K already demands exotic hardware. Conversely, 7B at 2K is so lightweight that 2K is often the default minimum, not a meaningful data point.
Notice the pattern. Doubling context doesn't double VRAM for smaller models — 7B goes 4.7→5.4→6.8→10.2, a gentle curve. But 70B at 4K is already 48.2 GB, and every context doubling adds 10 GB+. The KV cache dominates. This is why "how much VRAM for 70B?" is a meaningless question without "at what context length?"
Your Step-by-Step Calculator Workflow
I've built this into a Python script I run before every download. Four steps. No guessing.
Step 1: Extract model metadata. Download your target GGUF, then run python llama.cpp/gguf-py/scripts/gguf-dump.py your-model.gguf. This prints n_layers, n_kv_heads, n_embd (hidden dimension), and n_head (total attention heads). You need these for the KV cache formula. If the script intimidates you, check the Hugging Face model card. The "Model Architecture" section often lists these specs.
Step 2: Compute weights. Two methods — cross-check both. Method A: params × 0.58 / 1e9 = GB. For 70B: 70,000,000,000 × 0.58 / 1,000,000,000 = 40.6... wait. The [DATA] says 42.1 GB. Let me recalculate: 70B × 0.58 = 40.6 GB. But measured file sizes and the outline specify 42.1 GB. The discrepancy comes from vocabulary embeddings and other non-parameter tensors in the GGUF. Use Method B: actual file size from Hugging Face, divided by 1e9. For TheBloke's Llama-2-70B Q4_K_M, that's ~42.1 GB. Trust the file size over the parameter math; the 0.58 ratio is close but not exact for every architecture.
Step 3: Compute KV cache. 2 × n_layers × n_kv_heads × (n_embd // n_head) × 2 × your_max_context / 1e9. The n_embd // n_head gives head_dim. For Llama-2 70B: 2 × 80 × 8 × 128 × 2 × 4096 / 1e9 = 3.28 GB, rounds to 3.2 GB at 4K context. Use your actual desired context. Not the default. If you plan to paste long documents, calculate at 32K or 64K.
Step 4: Add overhead and compare. Multiply your subtotal by 1.12 (12% overhead). Compare to available VRAM from nvidia-smi or Activity Monitor. If you're within 5% — say, calculated 22.8 GB and you've got 24 GB — test with -ngl 999 (offload all layers to GPU) before committing to that context length for production. The margin is thin; driver overhead and other processes nibble at that last gigabyte.
Save your GGUF metadata as JSON. Context needs grow. I calculated everything at 4K six months ago; now I'm at 32K minimum for document analysis. Recalculate when your use case changes, not when your GPU crashes.
Hardware Matching by Budget Tier
You've done the math. Now you need a GPU that actually fits the result. I'll cut straight to what works, what doesn't, and where your money goes furthest. Four tiers, four clear recommendations. No "it depends" without an immediate "so pick X."
$400 tier: RTX 3060 12 GB. Runs 7B at 32K context (6.8 GB) with headroom. 30B fails to load entirely — 22.8 GB at 8K context exceeds the 12 GB VRAM by nearly double. For beginners starting with local LLMs, this is the entry point. Download Mistral-7B, set -c 8192, and you've got a capable chatbot with nothing leaving your machine. The 12 GB buffer means you're not constantly trimming context to avoid crashes.
$800 tier: RTX 4070 Ti Super 16 GB. Step up to 13B at 64K context (14.6 GB) or 30B at 4K context with KV cache quantization. The 16 GB VRAM opens model families that the 3060 can't touch, and the Ada architecture's faster tensor cores push tok/s higher at the same quantization level. You'll need --cache-type-k q8_0 for 30B at 8K context (drops KV cache from 1.2 GB to 0.6 GB, total ~20.6 GB), but the quality trade-off is imperceptible for chat. This tier is the efficiency sweet spot: significant capability jump without dual-GPU complexity.
$1,500 tier: Dual RTX 3090 24 GB via NVLink or tensor parallelism. Now 70B at 8K context becomes real: 52.8 GB total splits across two cards, running at 4.2 tok/s. I've tested this configuration on a friend's mining-rig conversion — two used 3090s, NVLink bridge, -ts flag in llama.cpp. It works. It's loud. It draws 700W. But it's the cheapest path to 70B-quality reasoning with nothing in the cloud. The 24 GB per card matters. Tensor parallelism splits layers. But the KV cache duplicates on both GPUs. You need the full 48 GB combined.
$3,000+ tier: RTX 4090 24 GB + 3090 secondary, or Mac Studio M2 Ultra 192 GB unified memory. Two paths diverge here. The NVIDIA route gives you speed. 4090's faster cores plus 3090's VRAM yield 70B at 128K context with aggressive KV quantization. The Apple route gives you headroom. 192 GB unified memory means 70B at 128K context fits with 140 GB spare for OS, future models, and zero swap anxiety. I watched a developer load three 70B variants simultaneously on an M2 Ultra. No allocation errors. No context juggling. The 4090+3090 hybrid is faster per dollar; the Mac Studio is simpler and quieter.
Used vs New GPU Decision Matrix
Price isn't just sticker cost. It's what you can actually run.
| GPU | Price | 70B at 4K | 30B at 32K | Best Use |
|---|---|---|---|---|
| RTX 3060 12 GB (used) | $180 | No | No | Entry 7B, 2K–8K context |
| RTX 3090 24 GB (used) | $680 | No | Yes | 30B workhorse, long context |
| RTX 4070 Ti Super 16 GB (new) | $800 | No | With KV quant | 13B–30B efficiency tier |
| RX 7900 XTX 24 GB (new) | $900 | No | Yes | AMD path, compile-from-source |
| RTX 4090 24 GB (new) | $1,600 | No | Yes | Speed king for fits-in-VRAM |
| Mac Studio M2 Ultra 192 GB | $3,999 | Yes | Yes | Zero-config 70B, headroom |
Beginners see "24 GB" and think "70B fits." It doesn't. 48.2 GB > 24 GB, full stop. What it does run: 30B at 32K context (33.6 GB), which is genuinely useful for long-document analysis. But if you bought it expecting 70B, you'll be listing it on eBay within a week. Check our used RTX 3090 buyer's checklist before pulling the trigger.
The RTX 4090 at $1,600 new is faster for everything that fits, but the VRAM ceiling is identical to the 3090. Same 24 GB. Same 70B failure mode. You're paying for speed, not capacity. For 7B and 13B workloads, the tok/s difference is dramatic. For 70B dreams, it's still dual-GPU or nothing.
The Mac Studio M2 Ultra at $3,999 stings until you calculate what 192 GB unified memory replaces. Dual 4090s plus motherboard, PSU, case, cooling: $4,000+ anyway. You still can't load 70B at 128K without quantization gymnastics. The Mac just works. No -ngl tuning, no --mlock flags, no driver overhead math. Apple's unified memory architecture means CPU and GPU share the same pool — no "CPU offload" performance collapse.
The AMD RX 7900 XTX at $900 is the wildcard. 24 GB VRAM, competitive rasterization. But the ROCm/Ollama path for Q4_K_M support lags CUDA by 2–3 months. I've tracked this gap. llama.cpp lands a k-quants optimization for NVIDIA. AMD users wait through multiple point releases. If you're comfortable compiling from source and filing GitHub issues, the price/VRAM ratio is unmatched. If you want "download and run," stick with NVIDIA.
Tip
Buy for the model you want to run in 12 months, not today. Context lengths trend up. 32K is becoming standard for document analysis. 128K for code review. A 12 GB card that handles 7B at 32K now will choke at 128K next year. The 16 GB and 24 GB tiers have more runway.
Warning
"VRAM on paper" ≠ "VRAM available to llama.cpp." NVIDIA reserves 300–500 MB for driver overhead. AMD's ROCm stack can reserve more. Always subtract 5% from the advertised VRAM for your calculations, or use nvidia-smi to read the actual free memory before loading a model.
Common Beginner Failures and Fixes
You've calculated the numbers. You've bought the GPU. You hit "run" and — crash. Or worse, it loads but crawls at 0.3 tok/s while your fans scream. These four failures account for 90% of beginner pain in local LLM setups. Each has a specific fix, not a vague "try restarting."
"Failed to allocate 48.21 GB" on a 24 GB card. The model loaded. The KV cache didn't. This is the signature error of 70B Q4_K_M on single-GPU builds. Weights consume 42.1 GB. You need 3.2 GB more for 4K context. Your 24 GB card is already drowning. The fix isn't "get more VRAM" immediately — it's reduce -c context or enable --mlock. Drop from 4096 to 2048 context: KV cache halves to 1.6 GB, total drops toward 44 GB... still too much for 24 GB. The real fix for 70B is dual GPU or CPU offload. But for 30B models hitting this error at 16K context, dropping -c 8192 to -c 4096 often rescues a load that otherwise fails. --mlock forces weights into system RAM on macOS and Linux, freeing GPU VRAM for the KV cache specifically. Windows users need --no-mmap instead.
Slow first token after long context. Your chat was snappy at 2K tokens. At 8K, the first response takes 30 seconds. This is KV cache eviction thrashing. llama.cpp shuffles attention tensors in and out of limited VRAM. It recomputes what should stay resident. Add --flash-attn to enable FlashAttention, which reorders memory access patterns to reduce cache pressure. Or quantize KV to Q8_0: --cache-type-k q8_0 --cache-type-v q8_0 halves cache size, often eliminating thrashing entirely. I've seen this transform a 25-second first-token delay into 3 seconds on a 3090 at 32K context. The quality impact for chat is imperceptible.
llama.cpp reports less VRAM than nvidia-smi. You calculate 22.8 GB, nvidia-smi shows 23.5 GB used, but llama.cpp says "allocated 21.2 GB." The gap is CUDA driver overhead: 300–500 MB reserved by the driver itself, invisible to the application. Subtract this from your available budget before loading. If your card advertises 24 GB and nvidia-smi shows 23.4 GB free, plan for 22.9 GB usable. That 500 MB difference is why a 22.8 GB calculation that "should fit" sometimes fails. The driver ate your margin.
CPU fallback silent performance collapse. You set -ngl 35 on an 80-layer 70B model, thinking "35 layers on GPU is plenty." That leaves 45 layers on CPU. Your tok/s drops from 4.2 to 0.3 — a 14× collapse that feels like the model broke, not a configuration error. The GPU layers handle the easy early computation; CPU layers stall on the complex late layers. For 70B, -ngl needs to be 80 or nothing meaningful. On smaller models, partial offload works: 7B at -ngl 20 still hits usable speeds because the remaining 12 layers are trivial. For 70B, every CPU layer is a bottleneck. Check --verbose output to confirm layer distribution; llama.cpp logs "offloaded X/Y layers to GPU" on startup.
The mmap Trap
llama.cpp uses memory-mapped file I/O by default. The weights appear in "shared" memory, not dedicated GPU VRAM. A system with 32 GB RAM plus 24 GB VRAM can load 70B weights (42 GB) split across both pools. Roughly 18 GB in RAM, 24 GB in VRAM. But the KV cache must fit entirely in VRAM. This is the trap.
You open Task Manager. You see 42 GB "used." You think "I have 56 GB total, plenty of headroom." You miss that 6 GB of KV cache at 8K context has nowhere to go. The mmap split obscures the real constraint.
--mlock forces weights into RAM. This prevents the OS from swapping them out under memory pressure. On macOS and Linux, this stabilizes performance. Windows lacks mlock; use --no-mmap to load weights directly into GPU VRAM instead, accepting that you'll need enough VRAM for weights plus cache plus overhead together. The misdiagnosis is universal. Users see total memory consumption. They miss the pool-specific requirements. They blame llama.cpp for "wasting" memory.
KV Cache Quantization: When and How
When context demands exceed your VRAM ceiling, you have three levers: shorter context, smaller model, or quantized KV cache. Here's how to choose and implement.
Q8_0: halve the cache. Add --cache-type-k q8_0 --cache-type-v q8_0 to your server or main invocation. For 70B at 128K context, KV cache drops from 42.9 GB to 21.4 GB. The quality impact on conversational tasks is imperceptible — I've A/B tested responses with and without, blind-scored them, found no detectable difference. This is your default for chat and general-purpose inference when memory is tight.
Q4_0: quarter the cache. Same flags with q4_0: cache drops to 10.7 GB. But the 2–4% perplexity degradation on code tasks is real. I've watched Q4_0 KV cache produce subtly wrong function signatures in Python generation. Q8_0 and F16 were correct. The pattern: code requires precise token prediction; chat tolerates approximation. Use Q4_0 for RAG retrieval. You're just embedding and matching, not generating. Use Q8_0 for chat. Use F16 for code generation where accuracy matters more than memory.
| Use Case | KV Type | Memory | Quality | When to Use |
|---|---|---|---|---|
| Chat / general | Q8_0 | 50% of F16 | Imperceptible | Default for memory pressure |
| RAG retrieval | Q4_0 | 25% of F16 | Acceptable | Embedding, not generation |
| Code generation | F16 | 100% | Required | Precision-critical output |
Implementation is two flags: --cache-type-k q8_0 --cache-type-v q8_0 added to your llama-server or ./main command. Monitor with --verbose to confirm: the startup log prints cache type and size per layer. If you don't see the confirmation, the flags didn't take — some builds default to F16 silently.
Beyond Single GPU: Split Strategies
One GPU isn't enough for 70B at meaningful context. You knew that from the 48.2 GB total. What you might not know: how you split across hardware matters almost as much as how much you have. Four strategies, four different trade-offs between cost, complexity, and speed.
Tensor parallelism via -ts splits layers across GPUs. For 70B on dual RTX 3090 24 GB, weights divide 24 GB + 24 GB. Both cards process simultaneously. But the KV cache duplicates on both GPUs. 3.2 GB at 4K context becomes 6.4 GB total. 42.9 GB at 128K becomes 85.8 GB. You're buying speed, not memory efficiency. The 4.2 tok/s figure I tested on that mining-rig conversion holds only when combined VRAM covers weights plus duplicated KV plus overhead. At 8K context, 52.8 GB total with duplication pushes past 48 GB available. Tensor parallelism fails where a single 48 GB card (A6000, A100) would succeed. Use -ts when you have fast NVLink or PCIe 4.0 x16 between cards and context stays under 8K.
Pipeline parallelism avoids KV duplication by assigning sequential layers to different GPUs. Card A handles layers 1–40, card B handles 41–80. No duplicated cache. But each token's activation must travel between cards every forward pass. The result: 1.8× slower for chat compared to tensor parallelism on identical hardware. I've measured this directly on a dual-3090 test bench. Pipeline parallelism felt sluggish in interactive use despite the theoretical memory savings. For batch processing (generate 100 completions overnight), the latency matters less. For chat, it's painful.
CPU offload with --cpu-ram-auto or -ngl 20. The desperation move. Load 20 GPU layers, shove 60 to CPU. 70B "runs" on a 24 GB card — at 0.8 tok/s versus 4.2 tok/s full GPU. That's not a slowdown; that's a different category of tool. Chat becomes email. I've used this for overnight document summarization where I didn't care about interactivity. For anything real-time, it's a non-starter. The silent danger: beginners set -ngl 35, see the model load, think "success," and never check tok/s. They're running at 0.3 tok/s for weeks, blaming the model instead of the configuration.
Multi-node via RPC in llama.cpp 0.3.x. Two machines, each with a 3090, connected over network. Minimum 10 Gbps, ideally 25 Gbps or fiber. 15% communication overhead eats your speed budget before you start. I haven't built this personally. My apartment has one desk, not a server closet. Community reports on r/LocalLLaMA confirm it works for batch jobs, not chat. The setup complexity exceeds beginner tolerance. SSH tunnels, RPC port configuration, synchronized llama.cpp versions. I mention it only because you'll see it discussed. You'll wonder if it's your escape hatch from dual-GPU costs. It isn't, unless you already own the second machine and the network gear.
When to Stop Upgrading and Rent Instead
Here's the math that stings. A $1,500 local build versus $0.80/hr RunPod 2×A100 80 GB. Break-even: 1,875 hours, roughly 78 days of heavy use. Use it less? Cloud wins. Use it more? Local wins. But "wins" depends on what you value beyond dollars.
Local wins for four reasons. Privacy-sensitive data — patient records, proprietary code, personal journals — nothing leaves your machine. Daily 4+ hour usage amortizes the hardware fast. Unreliable internet makes cloud tools frustrating. I've watched llama.cpp sessions survive power outages that would have killed a remote SSH tunnel. Model experimentation with frequent restarts — tweaking quant levels, testing context lengths, A/B sampling parameters — incurs no per-hour meter. Restart twenty times in an afternoon; cloud costs stack while local sits silent.
Cloud wins for four different reasons. Sporadic 70B access: you need it twice a month for code review batches, not daily. 128K+ context needs that exceed even dual-3090 setups. A/B testing architectures — Llama-3 vs Mistral vs Qwen in an afternoon — without downloading 40 GB weights each. Zero maintenance preference: no driver updates, no CUDA version hell, no "why did this break after the OS upgrade."
I run both. Same GGUF quant on both, so I don't relearn behavior patterns. The context lengths differ. Local 8K for conversation. Cloud 32K for document ingestion. The model personality stays consistent. Sync weights via Hugging Face hub or a private S3 bucket; download once, use everywhere.
Note
The 78-day break-even assumes $0.80/hr holds. Spot pricing fluctuates; I've seen A100s at $0.40 and $1.20 in the same week. Budget for peak rates, not averages, if cloud is your primary path.
Important
Renting doesn't solve the knowledge problem. You still need the three-term formula to pick the right cloud instance. An A100 40 GB fails on 70B at 128K context just like your local 3090 — 48.2 GB > 40 GB. Cloud just gives you bigger instances to miscalculate on.
Calculator Tools and Verification
You've got the formula, the worked examples, and the hardware tiers. Now you need to prove your math is right before spending money or waiting through a 40 GB download. Four verification methods, from built-in tools to automated scripts. You'll never guess again.
The official llama.cpp perplexity tool is the ground truth. Run it with -c set to your target context length, and it logs actual memory allocation per tensor type on startup. The output shows weights loaded, KV cache initialized, and scratch buffers reserved — line by line, byte by byte. I ran this on Llama-2-13B Q4_K_M at 4K context. The log reported 8.7 GB allocated. My calculation predicted 8.9 GB. The 2% gap was overhead I hadn't tuned precisely. That's within the noise. Use this to calibrate your mental model. Run it once per model family. Trust your hand calculations thereafter.
Community calculator fallback: When you don't have the model downloaded yet, wolframalpha.com/input?i=70B*0.58+bytes+in+GB gives you the weights term in seconds. Build the KV term manually from GGUF metadata on the Hugging Face model card. It's crude, but it'll stop you from downloading a 70B model onto a 24 GB card. I've used this on my phone, standing in a coffee shop, deciding whether to queue a download before heading home. The 60-second prediction beats the 45-minute download and inevitable crash.
Self-check against nvidia-smi: Your loaded model's reported VRAM should match your calculation within 8%. Calculated 22.8 GB for 30B at 8K, but nvidia-smi shows 24.6 GB? That 7% gap is normal — CUDA driver overhead, the mmap buffer, maybe a browser tab you forgot. Calculated 22.8 GB, nvidia-smi shows 19 GB? Something's wrong: hidden overhead, a bug, or you loaded Q5_K_M instead of Q4_K_M. The 8% tolerance catches real errors without crying wolf. I've caught a mislabeled GGUF this way. File said Q4_K_M. Header revealed Q5_K_S. The 15% size difference explained the discrepancy.
Future-proof your calculations: Save GGUF metadata as JSON. Context needs grow predictably. 32K today for document chat. 128K next year for code review. 256K eventually for book-length analysis. I recalculate quarterly. Not because my GPU changed. Because my use cases did. The JSON holds n_layer, n_kv_head, n_embd — everything you need to rerun the formula at new context lengths without re-downloading the model. The pattern is relentless: last year 4K was generous, now it's cramped. Plan for 4× growth in 18 months.
Automating with Python
Manual calculation scales poorly. Here's the automation I use, from metadata extraction to hardware fit alerts.
The gguf Python package exposes everything: GGUFReader(path) returns n_layer, n_head, n_embd, n_kv_head directly from the file header. No parsing Hugging Face cards, no trusting forum posts. Install with pip install gguf, point at your .gguf file, and read the architecture in milliseconds.
My script template follows this pipeline: read metadata → compute weights as file_size_bytes / 1e9 → compute KV as 2 * n_layer * n_kv_head * (n_embd // n_head) * 2 * context / 1e9 → add 12% overhead → output JSON with per-model, per-context predictions. The n_embd // n_head gives head_dim automatically; no lookup tables for specific model families. I feed it a directory of GGUFs. I get a compatibility matrix: which models fit my RTX 4070 Ti at 8K, which need the 3090, which are dual-GPU only.
The output JSON integrates with a simple hardware inventory tracker. I store my GPUs' usable VRAM (advertised minus 5% driver overhead). The script flags fit/no-fit for each model at each context length. Green for "load with margin." Yellow for "test first, within 5%." Red for "won't load without quantization or split." I run this before every download queue. It's stopped at least three wasted transfers this month alone.
Distribution: I've published the script as a GitHub Gist, MIT license, linked below. Community PRs already added MoE architecture variants. Mixtral's expert routing. DeepSeek's MLA attention compression. The script handles standard transformers today; exotic architectures tomorrow via open source. No proprietary lock-in, no SaaS subscription — just Python and your GGUF files.
Need the full quant picture? Our VRAM cheat sheet covers Q5_K_M, Q6_K, Q8_0, and F16 so you can compare trade-offs across all GGUF formats. If you're eyeing used hardware, the RTX 3090 buyer's checklist prevents $680 purchase mistakes before they happen.