There is no single correct number for VRAM usage while a local model is running. The value you get depends on which layer you measure: the whole GPU, a single process, the framework’s memory allocator, or the model’s internal components. Measuring those layers in order is what turns a vague “my GPU is full” into a diagnosis you can act on.
This guide is written for practitioners running local inference on NVIDIA hardware, because the most accessible tooling — nvidia-smi, NVML, and the nvidia-ml-py Python bindings — is NVIDIA-specific. The same layering applies on other vendors’ GPUs, but the commands differ and you will need that vendor’s tooling. By the end you should be able to say not just how many gigabytes your model uses, but which part of the model is using them.
Four layers of VRAM measurement
Each layer answers a different question, and each has a blind spot. Use them together rather than picking one.
| Layer | Typical tool | Answers | Does not answer |
|---|---|---|---|
| Device | nvidia-smi | Total VRAM used and free on the card | Which process, or which component, is responsible |
| Process | NVML via nvidia-ml-py | How much memory each compute process holds | Weights versus KV cache versus workspace |
| Allocator | Framework APIs such as PyTorch’s torch.cuda | Allocated versus reserved memory, and peak usage inside your code | Memory held by other libraries or the CUDA context |
| Component | Breakdown tools such as LLM Inspector | Weights, KV cache, workspace, activations, other | Anything the tool cannot attach to or infer |
Why the headline number misleads
The project LLM Inspector states the problem plainly: existing tools tell you that your GPU is using 18 GB, while the useful question is why. Its README illustrates the difference with a sample breakdown — weights 7 GB, KV cache 8 GB, workspace 1 GB, other 2 GB — and then an optimization projection: FP8 would save roughly 3 GB of weights, AWQ would save roughly 5 GB of weights, but weight quantization will not fix an 8 GB KV cache bottleneck.
That last point is the reason measurement matters. Weight quantization shrinks the weights; it does nothing for the KV cache, which grows with context length and concurrency. If you only ever read the total from nvidia-smi, you cannot tell which of those two you are actually fighting.
Note that the numbers above are the project’s illustrative example, not a measured result from a specific machine. Treat any projected saving as an estimate until you confirm it on your own workload.
Prerequisites
- An NVIDIA GPU with a working driver, so that
nvidia-smireturns output. - Python 3 with
pipif you want programmatic measurement. - For per-process tracking, install the NVML binding with
pip install nvidia-ml-py. A practical guide to VRAM profiling notes thatnvidia-ml-pyis still maintained by NVIDIA, unlikenvidia-ml-py3, which is no longer maintained. - Optional: LLM Inspector itself, described as the
htopfor LLM inference. It is a Python project under the MIT license, created in July 2026, withdevas its default branch. It is a young, single-maintainer project, so treat it as an early-stage tool rather than settled infrastructure.
Step 1: Establish a device baseline
Before loading anything, record what the GPU is already doing. Desktop compositors, other inference servers, and leftover processes all consume memory and will otherwise be attributed to your model.
nvidia-smi --query-gpu=memory.used,memory.total --format=csv
nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv -l 1
The first command gives an instant snapshot. The second lists compute processes and refreshes every second, which is useful while a model loads. The difference between your idle baseline and the loaded state is your model’s real footprint — not the size of the weight file.
Step 2: Attribute memory to a process with NVML
Shell polling is convenient but imprecise. NVML lets you query the same information from inside the process you are measuring, which makes the numbers reproducible.
from pynvml import (
nvmlInit, nvmlShutdown,
nvmlDeviceGetHandleByIndex,
nvmlDeviceGetComputeRunningProcesses,
nvmlDeviceGetMemoryInfo,
)
nvmlInit()
handle = nvmlDeviceGetHandleByIndex(0)
info = nvmlDeviceGetMemoryInfo(handle)
print(f"device used: {info.used / 1024**2:.0f} MiB of {info.total / 1024**2:.0f} MiB")
for proc in nvmlDeviceGetComputeRunningProcesses(handle):
used = (proc.usedGpuMemory or 0) / 1024**2
print(f"pid {proc.pid}: {used:.0f} MiB")
nvmlShutdown()
Two caveats are worth knowing. First, usedGpuMemory can be unavailable on some driver and platform combinations, which is why the example falls back to zero. Second, this still reports a per-process total; it cannot tell you that 8 GB of it is KV cache.
Step 3: Read the framework allocator’s own numbers
If you run inference through PyTorch, the caching allocator exposes far more detail than the driver does. The distinction that matters most is allocated versus reserved memory.
import torch
torch.cuda.reset_peak_memory_stats()
# ... load the model and run your workload here ...
print("allocated:", torch.cuda.memory_allocated() / 1024**2, "MiB")
print("reserved: ", torch.cuda.memory_reserved() / 1024**2, "MiB")
print("peak: ", torch.cuda.max_memory_allocated() / 1024**2, "MiB")
Allocated memory is what tensors currently hold. Reserved memory is what the allocator has claimed from the driver, including cached blocks it is holding for reuse. Reserved memory is normally larger, and the gap is why nvidia-smi can still show gigabytes in use after you have deleted every tensor. That gap is caching, not a leak — until it grows without bound across identical iterations.
reset_peak_memory_stats() plus max_memory_allocated() is the most reliable way to capture a peak rather than a snapshot, because a fast polling loop can miss short spikes entirely.
Step 4: Attribute memory to model components
Device, process, and allocator numbers tell you how much. To learn what, you need a breakdown tool. LLM Inspector describes itself as going one level deeper, from a process total into a tree of weights, KV cache, workspace, and activations, plus a projected optimization analysis. Its README states that deep metrics come from an optional embedded attach() call, while the repository’s topic tags cover GPU monitoring, memory profiling, PyTorch, quantization, Ollama, and vLLM.
This is the layer that changes decisions. If the breakdown shows the KV cache dominating, you reduce context length or concurrency rather than reaching for a smaller quantization format. If weights dominate, quantization is the right lever. Keep in mind that the optimization projections are modeled estimates derived from the running configuration — they are not measured post-change results.
A reproducible measurement protocol
Memory numbers are only comparable if the conditions match. A short protocol that produces defensible figures:
- Fix the configuration: model and revision, quantization format, context length, batch size, and concurrency. Write them down.
- Record the idle baseline with
nvidia-smibefore loading. - Load the model and let it finish initializing, including any warm-up inference.
- Call
reset_peak_memory_stats()immediately before the measured run, not before loading. - Run a representative workload — the prompt lengths and output lengths you actually use.
- Record peak allocator memory, reserved memory, and the NVML per-process total together.
- Repeat at least three times and report the range, not a single value.
- Log driver, CUDA, framework, and runtime versions alongside the numbers.
Step 1 is the one people skip. Changing context length between two runs invalidates the comparison entirely, because the KV cache scales with it.
Common measurement errors
- Sampling too slowly. A one-second poll can miss the peak during model loading or a long prefill. Use allocator peak tracking where possible.
- Reading
nvidia-smiafter unloading. Cached allocator blocks keep the number high. Compare against your idle baseline, and check whether reserved memory actually falls. - Ignoring other processes. A second inference server or a desktop session inflates the device total. The per-process query separates them.
- Equating weight file size with VRAM. Runtime overhead, the CUDA context, activations, and the KV cache all sit on top of the weights.
- Assuming quantization fixes everything. It reduces weights, not the KV cache. If the cache is the bottleneck, the saving will disappoint.
- Comparing across environments. Different drivers, container visibility settings, or multi-instance GPU partitions change what the process can see and allocate.
Limits and tradeoffs
None of these layers is complete on its own. NVML gives authoritative per-process totals but no internal attribution. Framework allocator stats are precise for the framework’s own allocations but blind to memory held elsewhere. LLM Inspector is the only layer in this set that offers component-level attribution, and it is early-stage software on a dev default branch with a small contributor base — verify its output against NVML totals before relying on it for capacity planning.
There is also a scope limit worth stating: NVML and nvidia-smi are NVIDIA tooling. On other vendors’ accelerators you need that vendor’s monitoring stack, and the exact commands in this guide will not apply.
What to do next
Start with the baseline and the per-process query, because they take under a minute and immediately tell you whether you have a real problem or a misattributed one. Add allocator peak tracking when you need numbers you can compare across runs. Reach for a component breakdown when the question shifts from “how much” to “which part” — that is the point at which quantization, context length, and concurrency stop being guesses.
If you run this protocol and get a result that contradicts your expectations, share your GPU model, runtime, quantization format, context length, and the three numbers you recorded. Concrete configurations are what make memory discussions useful to the next person reading them.
FAQ
Why does nvidia-smi show more VRAM in use than the model file size?
The weight file is only one component. The CUDA context, runtime overhead, activations, workspace buffers, and the KV cache all consume additional memory, and the framework's caching allocator may also hold reserved blocks that are not currently in use.
Does quantizing weights always reduce total VRAM usage?
No. Quantization reduces the weights portion only. LLM Inspector's own example notes that weight quantization will not fix a KV cache bottleneck, so a workload dominated by long contexts or high concurrency may see little total benefit.
How do I measure peak VRAM instead of a snapshot?
In PyTorch, call torch.cuda.reset_peak_memory_stats() right before the measured workload and read torch.cuda.max_memory_allocated() afterward. This captures short spikes that a polling loop on nvidia-smi can miss.
Can I use nvidia-smi and pynvml on a non-NVIDIA GPU?
No. Both are NVIDIA-specific tools. Other accelerator vendors require their own monitoring utilities, though the same measurement layering — device, process, allocator, component — still applies.