Learn
Hardware & deployment

How much VRAM do you need to run a 7B model?

The short answer

A 7B model needs about 14 GB for BF16 weights or roughly 4 to 5 GB at four bits. Add the KV cache, activations and framework overhead on top: a 24 GB GPU is comfortable for quantised single-user work at moderate context, while 32K-token contexts and concurrent users push you toward 48 or 80 GB.

On this page

Three numbers, not one

The honest answer to how much VRAM a 7B model needs is a range that spans roughly 6 GB to 60 GB, because the weights are only the first of three costs. The second is the KV cache, which stores attention keys and values for every token currently in context and therefore grows with conversation length and with the number of users served at once. The third is everything else: activations during the forward pass, CUDA context, the memory allocator's fragmentation, compiled CUDA graphs, and whatever else shares the card. A single-user chat session and a twenty-user API share the same weights but not the same cache.

It also matters what you mean by 7B. Models in that class range from about 6.7B to 8.1B parameters, and a 20 percent difference in parameters is a 20 percent difference in weight memory. Architecture matters even more for the cache: two 7B models with identical weight sizes can differ by a factor of four in KV cache per token depending on how many key and value heads they use and how many layers they have. Any capacity plan that starts from the label on the model card rather than the config file is an estimate at best.

Weights: the part you can calculate exactly

Weight memory is parameters times bytes per parameter. A 7.6B model in BF16 is about 15.2 GB; a 7B at four bits is about 3.5 GB of raw values plus roughly 0.5 to 0.9 GB of scales, zero points and tensors held at higher precision, so plan on 4.1 to 4.5 GB for an AWQ or Q4_K_M checkpoint. Eight-bit checkpoints land near 7.5 to 8.5 GB for the same reason. Llama-3-8B, with 8.03B parameters, is 16.1 GB in BF16, 8.6 GB at eight bits and roughly 4.9 GB at four bits. Round up rather than down: the file size on disk is a good proxy, and the runtime will add its own buffers.

This is the number people quote when they say a 7B model runs on an 8 GB card, and at four bits that is true if the context is short. It stops being true the moment you want 32K tokens of history, a batch of eight concurrent requests, or BF16 precision for a quality-sensitive task. The weights set the floor; the cache and overhead decide whether the deployment actually fits.

The KV cache, calculated rather than guessed

The formula is two (for keys and values) times layers times KV heads times head dimension times sequence length times batch times bytes per element. Llama-2-7B has 32 layers, 32 attention heads and a head dimension of 128, with no grouped-query attention, so each token costs 2 x 32 x 32 x 128 x 2 bytes, which is 524,288 bytes, or half a megabyte per token in FP16. Eight thousand tokens of context is 4 GB, 32K is 16 GB, and a four-request batch at 32K is 64 GB. That single number explains why the original 7B models were painful to serve and why grouped-query attention was adopted so quickly.

Llama-3-8B keeps eight KV heads instead of 32, so the same formula gives 128 KB per token: 1 GB for 8K, 4 GB for 32K, 16 GB for 128K. Qwen2.5-7B goes further with four KV heads across 28 layers, about 56 KB per token, so 32K costs only 1.8 GB. Gemma-2-9B goes the other way: 42 layers with a head dimension of 256, about 336 KB per token, but it interleaves local sliding-window attention with global attention, which caps the effective cache for most layers. Reading the config file before renting a GPU is worth more than any rule of thumb.

Two multipliers are easy to forget. Batch size multiplies the cache linearly, and so does the number of concurrent conversations if the server keeps each one resident. Cache precision also matters: FP8 halves every figure above, and is a single flag in vLLM, but it should be validated on long-context retrieval before production. Prefix caching helps when many requests share a long system prompt, because the shared blocks are stored once, but it does not shrink the cache for genuinely distinct conversations.

Activations, fragmentation and framework overhead

A CUDA context costs 300 to 600 MB before your model loads anything useful, and PyTorch's caching allocator holds freed blocks rather than returning them to the driver, so resident memory is usually higher than the sum of live tensors. Compiled CUDA graphs, which vLLM and TensorRT-LLM use to cut launch overhead, can add several hundred megabytes to a gigabyte and a half depending on batch sizes. Tokenizer buffers, host-pinned staging memory for transfers and logging are small individually and add up to a gigabyte or so on a busy server.

Activations are modest during decode, when the batch is one token per sequence, but they spike during prefill of a long prompt. A 32K-token prefill through a 7B model can transiently allocate several gigabytes for intermediate tensors unless the runtime chunks the prefill or uses FlashAttention's tiling. vLLM addresses this with chunked prefill, which splits a long prompt into pieces and interleaves them with decode steps. If you size memory against steady-state decode and then send one 30K-token document, you will see the out-of-memory error that your average-case math said was impossible.

Worked budgets for cards people actually buy

An 8 GB card such as the RTX 4060 Ti holds a four-bit 7B at 4.3 GB. After roughly 1.2 GB of runtime overhead there is about 2.5 GB left for cache, which is 4K to 5K tokens on an older multi-head model at 0.5 MB per token, or 16K to 20K on a grouped-query model at 128 KB per token. It runs, but a long chat history will evict or fail. A 12 GB card like the RTX 3060 doubles that headroom: four-bit weights plus 16K of GQA context plus overhead lands near 8 GB, leaving room for a small batch.

At 16 GB, the 4060 Ti 16 GB and 4070 Ti Super can hold an eight-bit 7B at 8.5 GB with 8K of context, or a four-bit model with 32K to 64K of context and a couple of concurrent requests. At 24 GB, the RTX 3090 and 4090 become genuinely comfortable: BF16 weights at 15 GB plus 8K of GQA cache plus 2 GB of overhead is about 18 GB, and a four-bit model with 128K of context is roughly 20 GB if you accept a single user and FP16 cache. This is the sweet spot for local development and small internal tools.

A 48 GB card such as the A6000 or L40S supports a BF16 7B with 32K context and a batch of four, or a four-bit model with long context and a batch of sixteen. An 80 GB A100 or H100 is where a 7B model stops being the interesting question: it holds the BF16 weights, a large cache and a batch of 32 at 8K, or a four-bit 70B with a modest context. Rental prices track that capability: a 24 GB 4090 is roughly $0.35 to $0.60 per hour, a 48 GB L40S about $1.00 to $1.40, an 80 GB A100 $1.50 to $2.50 and an H100 $2.50 to $4.00, so 24/7 operation ranges from about $300 to $2,900 a month before you serve a single token.

What pushes memory up, in order of impact

  • Context length, linearly and without mercy: doubling tokens doubles the cache, and a 128K context can cost four times the four-bit weights.
  • Concurrent sequences, also linearly: ten users at 8K each is the same cache as one user at 80K.
  • Cache precision: FP16 to FP8 halves the cache; FP32 doubles it, which some fine-tuning stacks still do by default.
  • Model architecture: multi-head attention costs four times what eight-head grouped-query attention costs for the same parameter count.
  • Vision or audio encoders in multimodal models, which add their own weights and image-token caches that can be large for high-resolution inputs.
  • CUDA graphs, fragmentation and a 0.9 memory-utilisation setting that reserves almost the whole card by design.
  • A second model on the same GPU, such as an embedding model and a reranker in a RAG stack, each with its own context and overhead.

Levers to pull when you are two gigabytes short

Reduce context before you reduce quality. Most chat products do not need 128K of history; summarizing older turns or retrieving only relevant chunks often improves answers as well as saving memory. Cut batch size or concurrency next, then quantise the cache to FP8, then choose an architecture with fewer KV heads. If the workload shares a long system prompt across requests, enable prefix caching, which can remove most of the duplicated cache in agent and RAG traffic. Chunked prefill prevents a single long document from spiking memory past the limit.

Tensor parallelism splits weights and cache across GPUs, but it costs a network hop per layer and works best on NVLink; two consumer cards over PCIe will fit more but generate slower than one card that fits the model. CPU offload through llama.cpp's layer split keeps a model running when it does not fit, at a five to twenty times throughput penalty once layers spill to system RAM. Apple silicon and unified-memory machines sidestep the ceiling entirely, with 64 to 128 GB addressable, but memory bandwidth of 100 to 550 GB/s means token rates well below a discrete GPU. Choose the trade you can measure rather than the one that sounds cheapest.

Measure it, do not model it

Load the exact checkpoint and runtime you plan to deploy, send prompts that match production length and concurrency, and watch memory under load rather than at idle. nvidia-smi dmon gives a per-second view, torch.cuda.max_memory_allocated gives the allocator's high-water mark inside a Python process, and vLLM exposes cache utilisation and preemption counts in its Prometheus metrics. In llama.cpp, the startup log prints per-layer offload and the context size actually allocated, which is often the fastest way to find a misconfigured context.

Leave 10 to 15 percent headroom for fragmentation and spikes. Size against p95 prompt length and peak concurrency, not the average, and then run a soak test with realistic traffic for an hour. Memory leaks in serving stacks are rare but real, and a slow climb over days is easier to catch before customers do. Write the numbers down: model, quantisation, context limit, maximum concurrent sequences and measured peak. The next person to change the context limit will thank you.

Sizing a RAG service end to end

A retrieval-augmented service rarely runs one model. Suppose you pair a four-bit 7B generator at 4.5 GB with a 0.6B embedding model in BF16 at 1.2 GB and a 0.6B cross-encoder reranker at 1.2 GB. That is 6.9 GB of weights before any context. Add 16K of generator cache at 128 KB per token, about 2 GB, plus 1.5 GB of overhead across three runtimes, and you are near 10.5 GB. A 16 GB card fits this comfortably at low concurrency; a 12 GB card does not, and teams that budgeted only for the generator discover it after the reranker is deployed.

The same logic applies to guard models, speech-to-text sidecars, and a small classifier for routing. Each has its own weights, its own context and often its own framework with its own CUDA context. List every process that will touch the GPU, add them up, then add the headroom. If the total exceeds the card, the cheapest fix is usually to move embeddings and reranking to a separate small GPU or to a CPU runtime, because those models are latency-tolerant relative to the generator and their throughput per gigabyte is high.

A repeatable sizing procedure

  • Read the config: parameter count, layer count, KV head count, head dimension and maximum context.
  • Compute weight memory from parameters and the exact checkpoint format, then add 10 percent for scales and unquantised tensors.
  • Compute cache per token from the formula, multiply by the p95 context length you will actually allow, then by peak concurrency.
  • Add 1.5 to 2 GB for runtime overhead, CUDA graphs and fragmentation on a single-GPU server.
  • Compare the total with usable VRAM, which is total minus display and other processes, and require 10 to 15 percent slack.
  • Load-test at peak concurrency with realistic prompt lengths, then adjust context or batch rather than trusting the spreadsheet.

Common mistakes

  • Forgetting that the desktop compositor and a browser on the same card can consume 0.5 to 1.5 GB before the model starts.
  • Setting vLLM's memory utilisation to 0.95 and then wondering why a prefill spike kills the process.
  • Leaving max-model-len at the model's architectural maximum, which makes the server reserve cache for a context no user will send.
  • Comparing a four-bit model at 32K with a BF16 model at 4K and concluding that quantization caused a quality drop.
  • Buying a 16 GB card for 32K-context work on a multi-head model, where the cache alone exceeds the card.
  • Sizing for one user, then deploying behind an API with default concurrency of 256.
  • Ignoring the embedding and reranker models in a RAG stack, which together can add several gigabytes.
  • Assuming a 7B model is 7B parameters when the checkpoint is 8.1B and the tokenizer adds another hundred megabytes.
Page feedback

Was this helpful?

A quick signal helps improve these notes.

Report a mistake Straight to the lab inbox

Put it to work

See the models, datasets and gateway this lab runs.