AIForum.

How to Monitor GPU and VRAM Usage for Local AI

On this page

THE SHORT ANSWER

Monitoring local AI workloads starts with nvidia-smi: a snapshot for a quick check, a CSV query loop for a trace, and dmon for a compact usage view. Interactive tools such as nvtop and gpustat cover day-to-day work, while DCGM and pynvml provide structured telemetry for benchmarking and serving.
Quick facts

If you run models locally, two numbers decide whether your setup works: how busy the GPU is, and how much VRAM is left. The default tool for both is nvidia-smi, which ships with the NVIDIA driver and reports memory, utilization, temperature, and the processes attached to each GPU. For continuous work, nvidia-smi‘s query and dmon modes, plus interactive monitors such as nvtop and gpustat, cover most day-to-day needs. For benchmarking or serving, DCGM and pynvml provide structured, programmatic telemetry.

This guide is for anyone running local inference or training on a single machine — a workstation, a home server, or a rented GPU box — who needs to answer a practical question: is my model fitting in VRAM, and is the GPU actually doing work? It follows the NVIDIA tooling documented by the fastai GPU guide and the NVIDIA AIPerf telemetry documentation, with a note on the AMD path.

Separate the questions you are really asking

GPU monitoring gets easier once you split it into distinct measurements, because they fail in different ways:

  • VRAM footprint — memory.used against memory.total. This tells you whether the model fits and how much headroom remains for longer contexts or a second process.
  • GPU utilization — utilization.gpu, the percentage of time the GPU was busy. High VRAM with low utilization usually means the bottleneck is somewhere else.
  • Memory utilization — utilization.memory, the share of memory bandwidth in use. Useful when a workload is moving data rather than computing.
  • Temperature and power state — temperature.gpu and pstate, which explain throttling and unexpected slowdowns.
  • Owning process — which PID holds the memory, so you can tell your model apart from a stray process or another user’s job.

These are exactly the fields the fastai GPU guide recommends querying in a loop, so they make a good default set to standardize on.

The baseline: a single nvidia-smi snapshot

Running nvidia-smi with no arguments prints the current state: per-GPU memory, utilization, temperature, power, and a process table. It is the fastest way to confirm that a driver is present and that the GPU sees your workload. Its limitation is that it is a snapshot — it shows the current state rather than the trace of changes, which is why the fastai documentation recommends a query loop for anything that varies over time.

Continuous monitoring with nvidia-smi query mode

Query mode emits machine-readable CSV and is the most useful single command for local AI work:

nvidia-smi --query-gpu=timestamp,pstate,temperature.gpu,utilization.gpu,utilization.memory,memory.total,memory.free,memory.used --format=csv -l 1

The -l 1 flag loops the query every second, which gives you a trace rather than a single reading; increase the number to poll less frequently. Run nvidia-smi --help-query-gpu to list the other fields you can request. If you only care about memory, the fastai guide notes that this shorter form is usually sufficient:

nvidia-smi --query-gpu=timestamp,memory.used,memory.total --format=csv -l 1

For a compact percentage view of the essentials — usage and memory — use the device monitor:

nvidia-smi dmon -s u

Run nvidia-smi dmon without arguments for the full set of stats, and nvidia-smi dmon -h to see the available options.

Watching, logging, and time-boxing a session

Three small habits make nvidia-smi much more useful in practice.

  1. Refresh a plain snapshot in place: watch -n 1 nvidia-smi redraws the standard output every second.
  2. Log and watch at the same time: the fastai guide points out that -f filename writes to a file but hides the output. Piping through tee instead shows the output and records it, for example nvidia-smi ... | tee filename.
  3. Stop automatically: the same guide suggests wrapping the command so it exits after a fixed period, for example timeout -t 3600 nvidia-smi ... for a one-hour capture.

Logged CSV is what makes a problem reproducible: you can compare an idle baseline against a loaded run and see whether VRAM grew steadily, which points to a leak or a growing KV cache, or spiked once, which points to model load.

Interactive monitors: nvtop and gpustat

When you want a live dashboard rather than a scrolling log, two tools come up in the fastai guide. nvtop stands for NVidia TOP and is described as an htop-like task monitor for NVIDIA GPUs: it handles multiple GPUs, shows processes, and visually displays memory and GPU statistics. It is not shipped as a ready binary — the guide notes it must be built from source and requires tools such as gcc and make, though the build instructions are short. gpustat is listed alongside it as an nvidia-smi-like monitor, useful when you want a compact per-GPU summary you can read at a glance or embed in a script.

Production and programmatic telemetry: DCGM, pynvml, and amdsmi

Once you move from watching to measuring — for example, benchmarking an inference server — you want metrics collected by the runtime rather than by a terminal you are staring at. NVIDIA’s AIPerf documentation describes several paths for collecting GPU telemetry during benchmarking, covering power, utilization, memory, and temperature:

  • Dynamo with built-in DCGM. If you are using Dynamo, DCGM is pre-configured on port 9401 and no additional setup is needed; enabling the --gpu-telemetry flag turns on console display, and additional DCGM URL endpoints can be added. Endpoints may be written with or without the http:// prefix, for example localhost:9400.
  • Other inference servers with custom DCGM. If you use a different backend, DCGM must be set up separately.
  • pynvml for local monitoring. The documentation positions pynvml as the simple local option when you do not want to run DCGM at all.
  • amdsmi for AMD ROCm GPUs. This is the AMD equivalent path in the same guide.

AIPerf can display these metrics live and export them as CSV or JSON, including a custom metrics CSV format. The guide also includes a direct comparison of DCGM, pynvml, and amdsmi, which is the right place to check before committing to one collector for a benchmark harness.

Why the model file size is not your VRAM number

A common source of confusion is expecting memory.used to match the size of the model file. It will not. VRAM consumption is the sum of the model weights, plus the key/value cache that grows with context length and concurrency, plus the runtime’s own allocations for kernels, workspaces, and framework overhead. When you monitor, watch how memory.used behaves as you increase context length or batch size — that growth is the KV cache and overhead, not the weights. This is why a model that fits at a short context can fail at a longer one, and why monitoring during a realistic request is more informative than checking once after load.

Troubleshooting common monitoring problems

  • nvidia-smi: command not found — the NVIDIA driver utilities are not installed or not on PATH. Fix the driver installation before debugging anything else; none of the tools above will work without it.
  • Memory is used but no process is listed — the process may belong to another user, or be running inside a container with a different process namespace. Check with appropriate privileges and from inside the container context.
  • Utilization stays near zero while the job is slow — the GPU may be waiting on data loading, tokenization, or CPU work, or the model may have been placed on CPU. Compare utilization.gpu against host CPU usage.
  • Readings look noisy — polling every second is usually enough. Very frequent polling adds overhead and produces jitter rather than insight; the one-second loop used in the fastai guide is a reasonable floor.
  • Wrong GPU reported — on multi-GPU machines, select the device explicitly with nvidia-smi -i <index> so you are not reading a neighbour’s card.

A practical monitoring routine

  1. Capture an idle baseline with nvidia-smi --query-gpu=timestamp,memory.used,memory.total --format=csv -l 1 before loading anything.
  2. Start the model and note the jump in memory.used — that is your weight footprint plus fixed overhead.
  3. Send a realistic request at your intended context length and watch how much further memory climbs.
  4. Log the whole session with tee so you have a trace to compare against.
  5. If something fails or slows down, re-run with the same command and compare the two logs rather than guessing.

The next step depends on your goal. If you are tuning a single local model, keep the query loop open in a second terminal while you experiment with context length and quantization. If you are benchmarking a server, move to DCGM or pynvml so metrics are collected automatically. Readers who hit a specific error or a surprising VRAM number are welcome to share their GPU, runtime, model, and the exact command they ran in the community so others can compare.

FAQ

Does nvidia-smi work on AMD GPUs?

No. The NVIDIA AIPerf telemetry documentation lists amdsmi as the path for local AMD ROCm GPU monitoring, alongside the NVIDIA options.

How do I log GPU statistics to a file while still seeing them?

Use a pipe through tee rather than the -f filename option. The fastai guide notes that -f writes to a file but hides the output, while tee shows the output and logs it at the same time.

Why is VRAM usage higher than the model file size?

Because memory.used includes the weights plus the KV cache, which grows with context length and concurrency, plus the runtime's allocations for kernels, workspaces, and framework overhead.

How often should I poll GPU statistics?

One second is the common default, expressed as -l 1 in nvidia-smi query mode. Polling much more frequently adds overhead and produces noisy readings rather than better insight.

References

  1. https://docs.fast.ai/dev/gpu.html
  2. https://docs.nvidia.com/aiperf/tutorials/metrics-analysis/gpu-telemetry-with-ai-perf

Related terms

VRAM
The dedicated memory on a GPU. Local models must fit their weights, KV cache, and runtime overhead into it.
nvidia-smi
The NVIDIA System Management Interface, a command-line utility that reports GPU memory, utilization, temperature, power, and running processes.
DCGM
NVIDIA Data Center GPU Manager, a telemetry collector used for structured GPU metrics; Dynamo ships with it pre-configured on port 9401.
pynvml
A Python binding for NVIDIA management APIs, positioned in NVIDIA AIPerf documentation as the simple local GPU monitoring option without DCGM.
KV cache
Key/value tensors stored during inference that grow with context length and concurrency, adding to VRAM beyond the model weights.

Leave a Reply

Your email address will not be published. Required fields are marked *