How Much VRAM for a 7B Model? Quantization and Context
Size a 7B model using documented memory figures for BF16, INT8 and INT4. Account for KV cache, context length and LM Studio GPU offload.
A 7B model can load successfully and still exhaust GPU memory during generation. The answer to how much vram for a 7b model depends on weight precision, context length, and simultaneous requests. The growing KV cache is why a successful load does not prove the workload fits. Hugging Face’s cache documentation explains that distinction.
Related: GGUF Quantization Levels: Q4_K_M vs Q8_0 Explained.
How much VRAM does a 7B model need?
For a concrete starting point, Qwen’s vendor benchmark reports these GPU memory footprints for Qwen2.5-7B-Instruct using Hugging Face Transformers. It used an NVIDIA A100, batch size 1, and generated 2,048 tokens per request. Values retain the source’s GB labeling. Qwen methodology and results.
| Weight format | 1 input token | 6,144 input tokens | 30,720 input tokens |
|---|---|---|---|
| BF16 | 14.38 GB | 15.38 GB | 19.97 GB |
| GPTQ-Int8 | 8.42 GB | 9.43 GB | 14.01 GB |
| GPTQ-Int4 | 5.52 GB | 6.52 GB | 11.11 GB |
| AWQ | 5.39 GB | 6.39 GB | 10.98 GB |
Is 8 GB enough? It is a candidate for short-context, quantized inference. Is 16 GB enough? It is a candidate for short-context BF16. These are sizing inferences from the vendor benchmark, subject to available memory and runtime overhead. The long-context results show why neither capacity guarantees a fit. Qwen vendor benchmark.
These figures are workload footprints, not hardware minimums or LM Studio measurements. Validate the exact model artifact and backend before buying hardware.
Why context and batch size change the answer
Start with this accounting identity:
required VRAM = resident weights + KV cache + peak temporary allocations + runtime overhead
For weights alone, use parameter count × bytes per stored parameter. FP16 and BF16 use the same storage width. Quantization reduces weight storage, but the runtime still needs working memory. Hugging Face’s inference guide separates these costs.
For a conventional transformer with full attention, estimate the unquantized cache as:
KV bytes ≈ 2 × layers × KV heads × head dimension × cached tokens × bytes per cache element
The factor of 2 represents keys and values. Use KV heads, which can differ from query heads under grouped-query attention. Sum cached tokens across active sequences; count prompt tokens and generated tokens. This extends Hugging Face’s per-token cache formula to the active workload.
A longer RAG prompt therefore spends memory before the answer starts. Concurrent conversations add their own cache demand. Sliding-window layers, shared prefixes, and preallocated caches change the accounting; static allocation can reserve capacity ahead of actual token use. Cache strategies.
The metric that matters
For a vLLM service, watch KV cache occupancy at the intended concurrency, defined as occupied cache capacity divided by total allocated cache capacity. vLLM exposes vllm:kv_cache_usage_perc; a value of 1 means full occupancy. Pair it with waiting requests and time-to-first-token (TTFT). vLLM metric definitions.
This is more informative than the GPU memory bar alone: vLLM preallocates cache memory, so device usage can remain high while request pressure changes. Insufficient cache can trigger preemption and recomputation, increasing latency without an immediate OOM. vLLM tuning documentation.
Choose a memory budget that keeps the target workload within its latency objective. Treat throughput in tokens/sec as a companion metric; waiting users still notice a p99 TTFT spike.
Wiring it up
In LM Studio, run lms ls to find the downloaded model’s key. Substitute it below; the context length is an example configuration, not a capacity guarantee:
lms load MODEL_KEY --estimate-only --context-length 4096 --gpu max
The estimator honors context length and GPU offload. Repeat it with the intended context, then load and exercise that workload. To reduce GPU residency, lower the offload setting; account for system RAM too. LM Studio’s load command.
For a vLLM deployment, save this as prometheus.yml. It assumes Prometheus and the running vLLM server share a network namespace, with vLLM listening on port 8000. vLLM provides the /metrics endpoint; the scrape structure follows Prometheus’s configuration example.
global:
scrape_interval: 15s
scrape_configs:
- job_name: vllm
metrics_path: /metrics
static_configs:
- targets: ["127.0.0.1:8000"]
Start Prometheus with prometheus --config.file=prometheus.yml. Graph cache occupancy alongside vllm:num_requests_waiting and the TTFT histogram. Confirm metric names against the installed vLLM release.
What you’ll see
A healthy run completes the intended prompt lengths and concurrency without OOMs or persistent queues. Cache occupancy has room for the workload’s bursts, and p95/p99 latency stays within the service objective.
The concerning pattern is sustained cache pressure accompanied by preemption, growing queues, and latency deterioration. In vLLM, reducing max_num_seqs or max_num_batched_tokens can reduce concurrent memory demand. vLLM’s preemption guidance documents those controls.
Save model, quantization, context, and concurrency settings with the result. For ongoing alert design, the sister publication SentryML covers production model monitoring.
Caveats
- Quantization changes the tradeoff. Weight quantization can affect outputs and speed; run a regression test against a fixed golden set before accepting the smaller artifact. Hugging Face’s inference guide.
- Cache compression has a cost. Quantized caches can hurt latency at short context; cache offloading trades GPU memory for transfers. Neither is a free capacity upgrade. Cache strategies.
- Monitoring can mislead. A scrape can miss a brief memory peak. Shorter intervals increase collection work, and request IDs or prompt text create expensive label cardinality and potential data leakage. Keep labels bounded. Prometheus instrumentation guidance.
- Inference is not training. QLoRA freezes a quantized base and trains LoRA adapters, but training still has additional state and activations. Do not reuse an inference footprint as a fine-tuning requirement. QLoRA paper.
- System RAM is a separate budget. LM Studio recommends at least 16 GB RAM on Windows and 16 GB or more on macOS. Those platform recommendations do not certify a particular model and context. LM Studio requirements.
Sources
- Qwen2.5 Speed Benchmark
- Hugging Face: Optimizing LLMs for Speed and Memory
- Hugging Face: Unlocking Longer Generation with Key-Value Cache Quantization
- Hugging Face: Cache Strategies
- LM Studio: lms load
- vLLM: Production Metrics
- vLLM: Optimization and Tuning
- Prometheus: Getting Started
- Prometheus: Instrumentation
- QLoRA: Efficient Finetuning of Quantized LLMs
- LM Studio: System Requirements
Related
LM Studio System Requirements: RAM, VRAM, GPU
What LM Studio actually requires: 16 GB RAM, AVX2, 4 GB VRAM, macOS 14 on Apple Silicon, and how to size a machine for the model you want to run.
GGUF Quantization Levels: Q4_K_M vs Q8_0 Explained
How GGUF quantization trades model quality for memory, what Q4_K_M costs you against Q8_0, and how to match a quant level to the memory you have.
LM Studio vs Ollama for Local LLMs: How to Actually Choose
A practical comparison of LM Studio and Ollama for local LLMs: licensing limits, OpenAI API coverage, and the memory and context defaults.