Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Monitor GPU Utilization, Latency & Failures in AI Inference

· 4 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Monitoring GPU metrics during AI inference is essential for maintaining low latency, ensuring high throughput, and preventing hardware failures. By tracking utilization, response times, and error rates, you can optimize model serving efficiency and identify bottlenecks before they impact users.

What You'll Need

  • A Linux-based host with NVIDIA GPUs (or compatible accelerators)
  • nvidia-smi installed and accessible via the command line
  • Python 3.8+ with libraries like psutil, requests, and a logging framework
  • Access to your inference server logs (e.g., Triton, vLLM, or custom Flask/FastAPI endpoints)
  • A cron job or systemd service for periodic metric collection

Step-by-Step

  1. Verify Driver and Tooling: Ensure the NVIDIA driver is installed correctly by running nvidia-smi. Confirm that all expected GPUs are visible and in an idle state. If using containerized inference, verify that the Docker runtime has access to the GPU devices via --gpus all.
  2. Configure Continuous Monitoring: Create a Python script that queries nvidia-smi every 5–10 seconds. Use subprocess calls to parse JSON output (nvidia-smi --query-gpu=timestamp,utilization.gpu,memory.used,memory.total,freq,temperature.gpu,pstate --format=json). This provides raw data on compute usage, memory pressure, clock speeds, and thermal states.
  3. Instrument Your Inference Endpoint: Add middleware to your API server to capture request-level metrics. Record the timestamp when a request arrives, when it enters the GPU queue, when inference starts, and when the response is sent. Calculate latency as the difference between arrival and completion timestamps.
  4. Log Metrics to a Central Store: Write both system-level GPU metrics and application-level latency data to a time-series database like Prometheus or InfluxDB. Use structured logging (JSON format) so you can correlate spikes in GPU temperature with increases in p99 latency.
  5. Set Up Alerting Rules: Define thresholds for critical failures. For example, alert if GPU utilization drops below 10% while requests are pending (indicating a bottleneck elsewhere), or if memory usage exceeds 95% (risk of OOM kills). Trigger alerts for latency exceeding acceptable Service Level Objectives (SLOs).
  6. Implement Failure Detection: Monitor for CUDA errors such as illegal memory access or out-of-memory exceptions. These often appear in application logs but may not trigger immediate system alerts. Parse logs for keywords like "CUDA_ERROR" or "OOM" and escalate them immediately.
  7. Visualize and Review: Build dashboards showing GPU utilization trends, average/median/p99 latency over time, and error rates. Correlate these views to identify patterns, such as increased latency during peak traffic hours or gradual performance degradation due to thermal throttling.

Common Mistakes

One frequent error is relying solely on average latency, which masks tail-latency issues affecting a small percentage of users. Another mistake is ignoring GPU memory fragmentation; even if total memory usage appears low, insufficient contiguous blocks can cause inference failures. Additionally, failing to account for CPU-GPU synchronization delays can lead to inaccurate latency measurements if only GPU-side timestamps are used.

Tips

Use batched inference whenever possible to maximize GPU utilization and reduce per-request overhead. Enable asynchronous execution in your inference framework to overlap data preprocessing with GPU computation. Regularly update drivers and CUDA versions to benefit from performance optimizations and bug fixes. Finally, implement graceful shutdown procedures to ensure ongoing requests complete before terminating the process, avoiding partial outputs.

Troubleshooting

If GPU utilization remains low despite high request volume, check for CPU bottlenecks in data loading or preprocessing. High latency with normal utilization may indicate network congestion or inefficient model architecture. If you observe frequent OOM errors, reduce batch size or enable dynamic batching. For sudden drops in performance, inspect thermal throttling by checking GPU temperatures; if above 85°C, improve cooling or reduce load. Always restart the inference service if persistent CUDA errors occur, as they may leave the GPU in an inconsistent state.

Frequently Asked Questions

How do I measure end-to-end latency accurately?

Record timestamps at the client send, server receive, GPU start, GPU finish, and client receive points. Subtract the client send time from the client receive time for true end-to-end latency, or use server-side timestamps for internal pipeline analysis.

What is a healthy GPU utilization level for inference?

Utilization should ideally be between 70% and 95%. Below 70% suggests underutilization or bottlenecks in data preparation, while above 95% may indicate resource contention or inability to handle burst traffic.

Can I monitor GPU metrics without root access?

Yes, if your user account has permission to read /proc/driver/nvidia/gpus/* or if nvidia-smi is configured for non-root access. Containerized environments often grant this access via device permissions.

Why does my GPU memory usage stay high after requests finish?

This is often due to cached activations or fragmented memory pools. Restarting the inference service clears this, but enabling memory-efficient kernels or reducing cache sizes can mitigate the issue.

How do I detect silent GPU failures?

Silent failures, like incorrect outputs due to bit-flips, are hard to detect. Monitor ECC errors via nvidia-smi and implement output validation checks in your application logic to catch anomalies.

Is it safe to undervolt GPUs for inference?

Undervolting can reduce power consumption and heat, potentially improving sustained performance. However, it may cause instability under heavy loads. Test thoroughly in staging environments and understand that it may affect warranty terms.