RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Eruo Fredoline
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /How-to
  5. /How to monitor CPU and GPU memory during inference
HOW-TO · INF

How to monitor CPU and GPU memory during inference

intermediate·10 min·By Eruo Fredoline
PREREQUISITES

nvidia-smi (NVIDIA) or rocm-smi (AMD) available

What this does

Monitoring memory usage during inference helps diagnose out-of-memory errors, identify memory leaks, and tune offloading settings for optimal performance.

Steps

  1. Monitor GPU memory in real-time.

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

    Expected: Live-updating table showing VRAM usage and GPU utilization.

  2. Log memory to a file during a benchmark run.

    # Start logging in background
    nvidia-smi --query-gpu=memory.used --format=csv,noheader -lms 500 > gpu_mem_log.csv &
    LOG_PID=$!
    # Run inference
    ./llama-cli -m model.gguf -p "Long prompt here" -n 512
    # Stop logging
    kill $LOG_PID
    
  3. Monitor CPU memory on Windows.

    Get-Process -Name ollama | Select-Object WorkingSet64, PrivateMemorySize64
    # Or watch total system memory
    while ($true) { Get-Counter "\Memory\Available MBytes"; Start-Sleep 1 }
    
  4. Plot memory usage over time.

    import pandas as pd, matplotlib.pyplot as plt
    df = pd.read_csv("gpu_mem_log.csv", header=None, names=["memory_mb"])
    df.plot()
    plt.ylabel("GPU Memory (MB)")
    plt.savefig("memory_profile.png")
    

Verification

# Check the log has timestamps increasing during inference
Get-Content gpu_mem_log.csv | Select-Object -First 5
# Expected: rising memory values as model loads, plateau during generation

Common failures

  • nvidia-smi shows zero GPU activity: The model may be running entirely on CPU. Check --n-gpu-layers setting.
  • Sampling interval too fast: -lms 100 (100ms) can miss events. Use 500ms for accurate captures.
  • Permission denied: On Linux, nvidia-smi may need sudo for certain metrics. On Windows, run PowerShell as Administrator.

Operator checkpoint

Before treating this as solved, write down the local runtime, model or package version, hardware/backend if relevant, and the verification output. This keeps the guide useful as a Will-It-Run style decision instead of a one-off command transcript.

Operator checkpoint

Before treating this as solved, write down the local runtime, model or package version, hardware/backend if relevant, and the verification output. This keeps the guide useful as a Will-It-Run style decision instead of a one-off command transcript.

Related guides

  • How to enable full GPU acceleration for maximum performance
  • How to set GPU layers to optimize memory usage
RELATED GUIDES
INF
How to enable full GPU acceleration for maximum performance
INF
How to set GPU layers to optimize memory usage
← All how-to guidesCourses →