← All practical guides
Inference & deployment10 min readPublished Oct 10, 2026

LLM GPU Memory Requirements: Weights, KV Cache and OOM

LLM GPU memory requirements: Budget for weights, KV cache, concurrency and runtime headroom. Choose context limits or quantization for your workload.

Guide

Who this is for: Developers sizing GPU memory for model weights, context length and concurrent sequences.

The answer in 3 lines

  • Budget for weights, KV cache, concurrency and runtime headroom.
  • Choose context limits or quantization around the workload you will admit.
  • Evidence: linked documentation; no independent test results are claimed.

Evidence: Analysis of the linked documentation and source-reported behavior; examples and decision tables are explanatory, not executed tests.

The direct answer

Budget for resident weights, allocated KV cache and the runtime's peak working memory, with headroom for the workload you will admit. Context length and simultaneous sequences drive cache demand; reducing weight precision addresses a different component, so a model loading successfully does not establish that your requests will fit.

Try your GPU memory budget

Change the guide’s hypothetical workload to see how context and concurrency affect memory demand. Inputs describe one GPU; enter weights actually resident on that device.

Assumes identical full-attention cache dimensions across layers, equal token limits per sequence, and no shared prefixes. For a static cache, use its allocated token capacity. Sliding-window, hybrid, compressed and other cache layouts require different accounting.

Weight budget
14.9 GiB
KV payload per sequence
2 GiB
Total KV payload
8 GiB
Runtime + headroom
3 GiB
Total planned memory
25.9 GiB

1.9 GiB over the entered capacity

This workload exceeds the entered capacity even before uncounted allocations. Reduce token limits or concurrency and recalculate.

KV bytes = 2 × 32 layers × 8 KV heads × 128 elements × 2 bytes × 16,384 tokens × 4 sequences.

1 GiB = 1,073,741,824 bytes. Cache payload excludes block padding and cache metadata. Include those in your allowances; runtime and headroom defaults are hypothetical inputs, not measured recommendations. This estimates inference memory, not training memory or performance.

Formula basis: Transformers 4.57.1 cache tensor layout ↗ · Read the worked example

01

Budget the workload that must fit

A model that loads and answers a short prompt has passed one capacity check. It has not demonstrated that several long requests can finish together. For autoregressive inference, stored keys and values let later tokens reuse earlier attention work; their storage is separate from the model's weights. Transformers caching explanation

Start with a budget for each GPU, not the sum of memory across a machine:

W + K_allocated + R_peak + H ≤ C

  • W — resident weights: the tensors actually placed on this device, including any quantization metadata.
  • K_allocated — cache allocation: physical storage committed to the cache, including unused capacity within reserved buffers or blocks.
  • R_peak — other runtime memory: budget for activations, temporary workspaces, graph pools and other allocations outside W and K. Establish it for the configurations and request shapes you allow.
  • H — headroom: an explicit planning allowance for observed variation and operational requirements, not an assumed universal percentage.
  • C — capacity available to this process: after accounting for other device users. Do not substitute a product's advertised capacity without checking its units and actual availability.

This is a planning decomposition, not an engine's accounting API. Avoid counting the same storage twice when reconciling it with allocator metrics. PyTorch documents memory retained by its allocator and private pools used by CUDA graphs; vLLM also documents graph capture as an additional memory cost. PyTorch 2.9 CUDA semantics, vLLM 0.11.0 memory guidance

Scope: text-generation inference with a conventional decoder attention cache. Training, multimodal encoders, speculative draft models and unusual state representations need additional accounting. Evidence was checked on 10 October 2026. Implementation examples below are pinned to Transformers 4.57.1, vLLM 0.11.0, PyTorch 2.9 and Accelerate 1.10.1; these are reference versions, not claims about the latest release.

Conceptual GPU budget: concurrency enlarges the cache requirement

Loading diagram…
Conceptual accounting diagram, not measured proportions or a memory layout. Weights, physically allocated cache and other runtime memory must fit within the process's available capacity while leaving chosen headroom. Both sequence length and concurrency affect cache demand; concurrency is not a second copy of the weights.
02

Estimate KV bytes from the architecture

For a full-attention decoder with the same cache dimensions in every layer, start with the live-token payload implied by the stored tensors:

KV_payload_bytes = 2 × L × H_kv × D × b_kv × Σ T_i

InputWhat to obtain
2Both the key and value tensors
LNumber of layers that store these tensors
H_kvStored key/value heads per layer
DElements per stored head
b_kvBytes per cache element; 2 for the assumed BF16 or FP16 cache
Σ T_iSum of cached token counts across simultaneously resident sequences, when the cache layout stores per-sequence histories without dense batch padding

The tensor dimensions are documented in Transformers caching. Use KV heads, not automatically the number of query heads: the pinned Llama attention implementation projects keys and values using num_key_value_heads and updates the cache before the attention operation. Grouped-query attention can therefore store fewer heads than it uses for queries.

Count the rendered prompt, including templates and retrieved text, plus the generation allowance. For admission planning, prompt length plus the maximum permitted output is a useful conservative token bound; the precise current cache length depends on the generation step. Count resident sequences, not registered users or requests still waiting outside the engine. Multiple completions or beams need an implementation-specific expansion of that count.

This formula is a payload estimate, not total allocated memory. If an implementation materializes a dense batch cache, replace Σ T_i with that tensor's batch and allocated sequence dimensions. The vLLM paged-attention layout stores tokens in blocks, so partially used blocks still occupy storage. Padding, metadata and separately retained reusable prefixes can add capacity requirements. Assume no prefix sharing in a conservative first estimate.

Change the formula when its premises change. Sliding-window or chunked layers have bounded retained history in the documented Transformers caches; mixed layer types need a layer-by-layer sum. Static caches reserve capacity ahead of use. Other state representations need their own documented layout. Transformers cache strategies

03

Work through a hypothetical 24 GiB budget

Hypothetical arithmetic, not a GPU test or a claim about a named model. Assume one device, all weights resident, exactly 8,000,000,000 parameters at 2 bytes each, 32 full-attention layers, 8 KV heads per layer, 128 elements per head, and a 2-byte KV cache. Assume four independent sequences, no prefix sharing, and no additional draft model.

Each sequence is allowed 12,288 prompt tokens and 4,096 output tokens: a planning bound of 16,384 cached tokens. Here, 1 KiB = 1,024 bytes and 1 GiB = 1,073,741,824 bytes; decimal GB is a different unit.

CalculationResult
Weight payload: 8,000,000,000 × 2 bytes16,000,000,000 bytes ≈ 14.90 GiB
KV per token: 2 × 32 × 8 × 128 × 2 bytes131,072 bytes = 128 KiB
KV per sequence: 131,072 × 16,384 bytes2,147,483,648 bytes = 2 GiB
Four sequences: 4 × 2 GiB8 GiB KV payload
Weights plus KV payload22.90 GiB
Hypothetical 24 GiB process capacity minus that subtotalOnly 1.10 GiB remains

That remainder must accommodate cache-allocation overhead, the rest of the runtime and headroom. No evidence here establishes that 1.10 GiB is enough. A successful weight load therefore cannot approve this four-request configuration.

Now change one premise at a time:

Hypothetical changeKV payloadWeights + KV payloadDesign consequence
Baseline: four × 16,384 tokens8 GiB22.90 GiBRuntime fit unresolved
Reduce the combined token bound to 8,192 per sequence4 GiB18.90 GiBRebudget prompt and output allowances; all four cannot keep their old limits
Admit two sequences at 16,384 tokens each4 GiB18.90 GiBPreserve per-request length; queue or reject excess arrivals
Use an idealized 1-byte cache, four × 16,384 tokens4 GiB before cache metadata18.90 GiB before cache metadataRequires supported cache conversion and quality validation
Admit eight sequences at 16,384 tokens each16 GiB30.90 GiBExceeds 24 GiB even before other memory

These are changes to estimated demand. An engine with a preallocated pool may retain the same physical allocation after demand falls. Reconcile the estimate with its configured pool and available cache blocks.

Once you have a defensible runtime allowance and headroom, an initial full-attention admission bound is:

total resident token budget ≤ floor((C − W − R_peak − H) / KV_bytes_per_token)

Use bytes throughout. This bound assumes ideal packing; subtract allocation overhead and other retained cache state, then respect the engine's actual cache capacity. It is a candidate to validate, not a safe concurrency promise.

04

Choose the lever that changes the exhausted component

Use the budget to select a change, then check its application cost. These controls can be combined; they are not competing product categories.

ChangeComponent it targetsCost or limitationWhat to validate
Shorten the permitted prompt or outputRetained KV tokens; input work may also fallLess evidence, conversation history or answer length; static allocations may need reconfigurationToken counts after templating and task success at the new limits
Lower simultaneously admitted sequencesAggregate KV demand and batch working memoryMore queueing or rejected requests during burstsLong-request overlap, wait time and rejection behavior
Quantize weightsWSupported formats and kernels vary; lower precision can affect output quality; does not establish a smaller KV dtypeActual resident weight allocation and representative answer quality
Lower or quantize KV precisionCache payload per tokenScaling metadata, conversion work and model/backend compatibility matterCache allocation, long-context quality and latency
Offload KV state to CPUGPU-resident cacheHost RAM and repeated device transfers are requiredCPU capacity, transfer cost and service latency
Offload weights to CPU or diskGPU-resident weightsWeights must be made available for execution; storage and transfer can become limitingHost/storage budget and end-to-end behavior
Reduce graph capture or use eager executionGraph-related runtime allocationChanges execution performance, not the mathematical KV payloadPeak allocation and latency under the same workload

The weight/cache distinction is explicit in the documentation: TGI quantization describes weight formats and loading, while vLLM's FP8 cache documentation describes a separate KV representation and its scaling factors. Do not infer a four-bit cache from four-bit weights.

For the pinned Transformers version, offloaded caches move layer state between host and device, and quantized caches can add latency. Cache strategies Accelerate separately documents weight offload and warns about host-memory and disk-transfer constraints. Accelerate 1.10.1 The graph option is documented in vLLM 0.11.0.

More GPUs can change placement too, but recompute the budget per device from the chosen parallelism layout. A total that fits across several cards does not establish that each card's weights, cache and working memory fit. vLLM parallelism guidance

05

Use the failure phase to choose the next measurement

The following is a diagnostic procedure derived from the budget, not a guarantee that a symptom has one cause. Keep model revision, precision and request shape fixed while investigating one change.

ObservationFirst evidence to collectDecision it can support
Failure during weight loadingFailing allocation, destination device, dtype and placement; host versus device OOMReconsider weight representation, placement or capacity before tuning request limits
Weights load, but warm-up or graph capture failsAllocation peak before and during initialization; graph configurationCheck runtime reserve and graph settings
Long prompts fail during prefillPrompt-token count, scheduled input batch and peak working allocationReduce admitted prefill work and investigate runtime workspace needs
Failure appears late in generation or only when long requests overlapResident token counts, KV blocks, sequence count and output boundsRevisit the combined length/concurrency cache budget
Requests slow down with cache-preemption warningsEngine cache occupancy and preemption/recomputation countsCheck cache pressure even if the process has not crashed
GPU memory looks full while traffic is idleEngine cache-pool allocation, live tensors and allocator reservationsDistinguish allocated capacity from current request demand

In vLLM 0.11.0 V1, cache pressure can cause preemption and later recomputation. Its tuning guide describes a preallocated cache controlled through a GPU-memory fraction. Raising that fraction reallocates a finite budget; it does not create memory. The same guide distinguishes the scheduler's token-per-iteration budget from per-sequence length and sequence-count controls. Do not substitute max_num_batched_tokens for a bound on all tokens retained across requests. vLLM tuning

For PyTorch 2.9, inspect both allocated tensor memory and allocator-reserved memory; they overlap and must not be added together. Device-wide usage can include allocations outside those tensor counters. empty_cache() releases unused allocator-held memory, not live weights or KV tensors. A persistent excess of live demand therefore needs a budget change. CUDA memory management

If the suspect component remains unresolved, record that gap. An OOM message alone is not evidence for a universal overhead percentage or a recommended GPU size.

06

Turn the estimate into a deployment decision

Before selecting hardware, fill in the facts that determine the budget:

  1. Pin the model and runtime. Record model revision, attention/state architecture, layer count, stored KV heads and dimensions, weight representation, cache dtype, engine version and device placement. Verify supported combinations against that version's documentation.
  2. Define admitted work. Record maximum rendered input and output tokens, simultaneous resident sequences, any beams or multiple completions, and the queue/rejection policy. Keep maximum context support separate from the workload you intend to serve.
  3. Build a per-device worksheet. Separate W, cache payload, allocated cache capacity, other runtime memory and headroom. Use bytes consistently. Record where each number comes from: configuration, arithmetic or measurement.
  4. Plan representative validation. Include startup, warm-up, longest admitted prompts, long generation and overlapping requests at the intended concurrency. Exercise the boundary case together; separate single-request and short-prompt checks do not cover their combination.
  5. Capture the limiting evidence. Measure allocation peaks and engine cache capacity/occupancy; retain errors, preemptions and queue behavior. Include host RAM and transfer behavior if offloading. Use these observations to set runtime allowance and headroom.
  6. Approve an operating envelope. Record the model/runtime configuration, request limits and device arrangement that passed your checks. Check answer quality and latency after precision, context or offload changes. Revalidate when any budget premise changes.

No hardware validation was performed for this guide. Its worked numbers identify what to measure and which changes affect the estimate. The deployment decision comes from checking the complete admitted workload on the intended stack.

Sources & further reading

Documentation informs the product behavior described here. The worked scenarios and conceptual diagrams explain how those behaviors fit together.

  1. Transformers 4.57.1: Caching ↗Hugging Face · Accessed 2026-10-10
  2. Transformers v4.57.1: Llama attention source ↗Hugging Face · Accessed 2026-10-10
  3. Transformers 4.57.1: KV cache strategies ↗Hugging Face · Accessed 2026-10-10
  4. vLLM 0.11.0: Conserving Memory ↗vLLM · Accessed 2026-10-10
  5. vLLM 0.11.0: Optimization and Tuning ↗vLLM · Accessed 2026-10-10
  6. vLLM 0.11.0: Quantized KV Cache ↗vLLM · Accessed 2026-10-10
  7. vLLM 0.11.0: Paged Attention design ↗vLLM · Accessed 2026-10-10
  8. PyTorch 2.9: CUDA semantics ↗PyTorch · Accessed 2026-10-10
  9. Accelerate 1.10.1: Loading big models into memory ↗Hugging Face · Accessed 2026-10-10
  10. Text Generation Inference: Quantization (accessed 2026-10-10) ↗Hugging Face · Accessed 2026-10-10

Explore the individual tools

Suggest a correction · More practical guides

LLM GPU Memory Requirements: Weights, KV Cache and OOM — Runeval