LM Studio Guide
Isometric graphics card on a dark blue background, with cyan memory blocks highlighting VRAM used to run a quantized 7B model.
inference

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.

By LM Studio Guide Editorial · · 4 min read

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 format1 input token6,144 input tokens30,720 input tokens
BF1614.38 GB15.38 GB19.97 GB
GPTQ-Int88.42 GB9.43 GB14.01 GB
GPTQ-Int45.52 GB6.52 GB11.11 GB
AWQ5.39 GB6.39 GB10.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

  1. Qwen2.5 Speed Benchmark
  2. Hugging Face: Optimizing LLMs for Speed and Memory
  3. Hugging Face: Unlocking Longer Generation with Key-Value Cache Quantization
  4. Hugging Face: Cache Strategies
  5. LM Studio: lms load
  6. vLLM: Production Metrics
  7. vLLM: Optimization and Tuning
  8. Prometheus: Getting Started
  9. Prometheus: Instrumentation
  10. QLoRA: Efficient Finetuning of Quantized LLMs
  11. LM Studio: System Requirements
#vram#local-llms#quantization #lm-studio #inference

Related