How to use this calculator
Estimate model-weight and KV-cache memory for an LLM serving configuration before adding a runtime reserve.
- Enter Model parameters (billions), Weight precision (bits per parameter), Transformer layers, Key-value heads per layer, then complete the remaining labeled fields. Match the units shown beside each field and review the result together with the assumptions below.
- Read the worked example below to check the expected input format and result.
- Compare another scenario by changing one input at a time. Use Reset to return to the starting values.
How this calculation works
GPU planning for generation has two different memory terms: the parameters loaded for the model and the key-value cache retained for active contexts. Enter the architecture and serving assumptions you know; the page computes those terms separately so a long context or larger batch is visible in the estimate.
Inputs and units
parametersB— Model parameters (billions)- Enter the parameter count in billions, such as 7 for a 7-billion-parameter model.
weightBits— Weight precision (bits per parameter)- Packed weight precision; this does not include quantization scales or padding.
layers— Transformer layers- Number of transformer blocks in the model.
kvHeads— Key-value heads per layer- Use the model's KV-head count, which may be smaller than its attention-head count.
headDimension— Head dimension- Dimension of each key or value head.
contextTokens— Cached context tokens per sequence- Number of tokens retained in the key-value cache for each active sequence.
activeSequences— Concurrent active sequences- Sequences whose cache is resident at the same time.
cacheBits— KV-cache precision (bits per value)- Precision of each cached key and value element, before cache-specific metadata.
reservePct— Additional runtime reserve (%)- A user-selected allowance for runtime allocations beyond the raw weight and cache arrays.
Formula
Weight memory (GiB) = parameters × 10⁹ × weight bits ÷ 8 ÷ 2³⁰. KV cache (GiB) = 2 × layers × KV heads × head dimension × context tokens × active sequences × cache bits ÷ 8 ÷ 2³⁰. Estimated VRAM = (weight memory + KV cache) × (1 + reserve% ÷ 100).
Method
The weights term counts packed parameter bits. The cache term stores one key and one value per layer, KV head, head-dimension element, context token, and active sequence. The reserve is applied to the combined estimate for framework and runtime overhead.
Worked example
For 7 billion parameters at 4 bits, 32 layers, 8 KV heads, head dimension 128, 4,096 cached tokens, one sequence, and a 16-bit cache, the weights use about 3.260 GiB and the cache 0.500 GiB. With a 20% reserve, the estimate is about 4.512 GiB.
Assumptions and limits
This is a planning estimate, not a guarantee that a model will fit. It excludes tokenizer and graph allocations, temporary activations, allocator fragmentation, quantization scales and padding, tensor-parallel sharding, offloaded cache, and model-specific runtime buffers. Use the actual KV-head count and cache precision for the selected model and runtime.
Frequently asked questions
Why does context length change VRAM?
The KV cache grows with the number of cached tokens and active sequences, so longer contexts and larger concurrent batches increase this memory term.
Should I enter attention heads or KV heads?
Enter the number of key-value heads used by the model. Grouped-query and multi-query attention can have fewer KV heads than attention heads.
Does four-bit weight precision mean the model needs exactly four bits per parameter?
No. Quantization metadata, alignment, embeddings, and runtime allocations add memory beyond the packed-weight calculation.
Does this tell me whether a model fits on one GPU?
Compare the estimate with memory available to the process, but check the actual model, runtime, sharding, and cache behavior before deployment.
How do I use the LLM Inference VRAM Requirement Estimator?
Enter Model parameters (billions), Weight precision (bits per parameter), Transformer layers, Key-value heads per layer, then complete the remaining labeled fields. Match the units shown beside each field and review the result together with the assumptions below.
Reference: Hugging Face Transformers documentation on KV-cache memory behavior and cache strategies. See our calculation methodology.