GPU Memory Calculator
Calculate GPU VRAM needed to run or train large language models. Estimate memory for any model size, precision (FP32/FP16/INT8/INT4), batch size.
GPU Memory Calculator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser — no data is sent to any server.
Formula: VRAM = Model Weights + KV Cache + Activations + Overhead
Worked example — ~14.7 GiB — fits a 16 GB RTX 4080; an RTX 4090 (24GB) leaves ample headroom
Formula
VRAM = Model Weights + KV Cache + Activations + Overhead
Model weights = parameters × bytes per parameter. KV cache = 2 × layers × batch × seq × kv_heads × head_dim × precision. Add ~10% for CUDA/framework overhead. Training additionally requires gradients (same as weights) and optimizer states (2× weights for AdamW in FP32).
Worked Examples
Example 1: 7B Model in FP16
Problem:Estimate VRAM needed to serve a 7B-parameter model in FP16 with batch size 1 and a 2,048-token context.
Solution:Model weights: 7B × 2 bytes = 14.0e9 bytes = 13.0 GiB KV cache with grouped-query attention (8 KV heads): 2 × 32 layers × 2048 seq × 8 kv_heads × 128 head_dim × 2 bytes = 0.25 GiB Activations: ~0.1 GiB Subtotal: 13.4 GiB, plus ~10% framework overhead Total: ~14.7 GiB With full multi-head attention (32 KV heads) the cache would be 1.0 GiB and the total ~15.5 GiB
Result:~14.7 GiB — fits a 16 GB RTX 4080; an RTX 4090 (24GB) leaves ample headroom
Example 2: 70B Model in INT4
Problem:Can a 70B model run on consumer hardware with 4-bit quantization?
Solution:Model weights: 70B × 0.5 bytes = 35 GB KV cache: ~2-4 GB at 2048 context Total: ~40 GB No consumer GPU reaches 40 GB — the largest, an RTX 5090, has 32 GB
Result:Requires ~40 GB — best on an 80GB A100/H100, or split across 2× RTX 3090/4090 with model parallelism
Frequently Asked Questions
How is GPU memory (VRAM) calculated for LLMs?
LLM VRAM consists of: (1) Model weights — parameters × bytes per parameter (4B for FP32, 2B for FP16, 1B for INT8, 0.5B for INT4). A 7B parameter model in FP16 needs ~14 GB just for weights. (2) KV cache — stores key/value pairs for attention, scaling with batch size and sequence length. (3) Activations — intermediate computation results. (4) Framework overhead — CUDA context, memory fragmentation (~10%). Total VRAM = weights + KV cache + activations + overhead.
What is quantization and how does it reduce VRAM?
Quantization reduces the precision of model weights from their original format (usually FP16/BF16) to lower-bit representations. INT8 quantization (8-bit) halves memory vs FP16. INT4 quantization (4-bit, via GPTQ/AWQ) quarters it. A 70B model needs ~140 GB in FP16 but only ~35 GB in INT4. Quality loss is generally small at INT8 and more noticeable at INT4, but it varies by model, by quantization method and by task, so measure it on your own evaluation set rather than assuming a fixed penalty. Quantization is nonetheless the primary technique for running large models on consumer hardware.
Why does training need much more VRAM than inference?
Training requires storing: (1) Model weights (same as inference). (2) Gradients — same size as weights. (3) Optimizer states — AdamW stores momentum and variance for each parameter (8 bytes/param in FP32). (4) Activations — must be stored for backpropagation through all layers. A 7B model needs ~14 GB for FP16 inference but ~120+ GB for full FP32 training with AdamW. Techniques like gradient checkpointing, mixed precision, and DeepSpeed ZeRO can reduce training memory.
Can I run large models on consumer GPUs?
Yes, with quantization. A 7B model fits on an 8GB GPU with INT4. A 13B model fits on 12-16 GB with INT4. A 70B model needs ~35 GB for weights alone in INT4, which exceeds every current consumer card — an RTX 4090 (24GB) or even an RTX 5090 (32GB) cannot hold it on its own, though an Apple M2 Ultra with 192GB of unified memory can. For models larger than 70B, you typically need multi-GPU setups or datacenter GPUs. Tools like llama.cpp, GPTQ, AWQ, and bitsandbytes make quantization easy.
Why does a model that should fit still run out of memory?
The weights are only the floor. Loading can peak near twice the final footprint when a checkpoint is materialised in host memory or converted to another precision on the fly. The CUDA context, cuBLAS workspaces and the allocator itself claim several hundred megabytes before your model exists. Long prompts spike activation memory well above the steady-state figure, and PyTorch's caching allocator fragments over time, so a card reporting free VRAM can still fail a large contiguous allocation. Size for the peak rather than the average and keep ten to fifteen percent of the card in reserve.
Why does long-context serving run out of VRAM before the weights do?
The KV cache holds one key and one value vector per token, per layer, per key-value head, so its size is 2 × layers × batch × sequence × kv_heads × head_dim × bytes. It grows linearly in both batch size and context length while the weights stay fixed. Attention compute scales quadratically with sequence length, but the cache does not — it is this linear term that eventually swamps the card. Doubling the context window and doubling concurrent users cost exactly the same memory.
What is grouped-query attention and how much KV cache does it save?
Classic multi-head attention keeps a separate key and value projection for every attention head. Grouped-query attention lets several query heads share one key-value head, and multi-query attention reduces it to a single shared pair. Cache size scales with the number of key-value heads rather than query heads, so a model with 32 query heads and 8 key-value groups stores a quarter as much. Estimates based on query-head count therefore overshoot badly — check num_key_value_heads in the model config.
What is the difference between FP16 and BF16 if both use two bytes?
They divide those 16 bits differently. FP16 allocates 5 exponent bits and 10 mantissa bits; BF16 allocates 8 exponent bits and 7 mantissa bits, giving it the same dynamic range as FP32 with coarser precision. Memory is identical, so GPU Memory Calculator reports the same figure for both. The difference shows up in training: BF16 rarely needs loss scaling because gradients do not underflow its exponent range, while FP16 usually does. FP16's extra mantissa bits can help inference numerics.
How can I cut training memory without buying a larger GPU?
Four levers, roughly in order of payoff. Parameter-efficient fine-tuning such as LoRA freezes the base weights and trains small adapters, so gradients and optimizer state cover a tiny fraction of the parameters. Gradient checkpointing keeps only a few activation boundaries and recomputes the rest, trading about one extra forward pass for a large activation saving. ZeRO-style sharding partitions optimizer state, then gradients, then parameters across ranks. Gradient accumulation shrinks the micro-batch while preserving the effective batch size.
How is a model split when it will not fit on a single GPU?
Two schemes, frequently combined. Pipeline parallelism assigns contiguous ranges of layers to different devices, so each holds a slice of the weights and activations travel along the chain; it tolerates slower links but leaves idle bubbles unless you feed it micro-batches. Tensor parallelism splits individual weight matrices across devices and all-reduces inside every layer, which demands a fast interconnect such as NVLink. Weights divide by the device count, but each GPU still carries its own KV cache and framework overhead.
References
Background & Theory
History
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer · Editorial policy
Related Calculators
🧮Kubernetes Pod Resource Calculator
Calculate CPU and memory requests and limits for Kubernetes pods based on application profiling.
🧮Bandwidth Time Transfer Calculator
Calculate bandwidth time transfer with inputs, formulas, and instant results.
🧮Download Time Calculator
Calculate download time with inputs, formulas, and instant results.
🧮Throughput Efficiency Calculator
Calculate throughput efficiency with inputs, formulas, and instant results.
🧮Base64 Encode & Decode Calculator
Calculate base64encode decode with inputs, formulas, and instant results.
🧮Hash Checksum Calculator
Calculate hash checksum with inputs, formulas, and instant results.
🧮Urlpercent Encoding Calculator
Calculate urlpercent encoding with inputs, formulas, and instant results.
🧮Cron Expression Builder Calculator
Calculate cron expression builder with inputs, formulas, and instant results.