WattOps Start free
← Blog

How to measure GPU energy in Python

Guide · Last updated 20 October 2026 · 2 min read

On this pageThe short answerSeveral steps in one programWhy not read nvidia-smi or the power reading?Make the number mean somethingMeasure a whole script insteadNext

You can read a GPU's real energy use from Python in a few lines, without estimating it from utilisation or a spec sheet. This guide shows how, and what to watch out for so the number means something.

The short answer

pip install landauer-gap
import joules

with joules.measure("train") as p:
    train_one_epoch()

print(p.energy_j, "J in", p.duration_s, "s")

joules.measure reads the hardware's own energy counter when the block starts and when it ends. The energy of the block is the difference. On NVIDIA GPUs from Volta onwards that counter comes from the driver (NVML); on Intel and AMD CPUs, from RAPL; on AMD and Intel GPUs, from the kernel's hwmon files.

Several steps in one program

To compare the steps of a longer program, give each one a name. A Session keeps a median and a spread for every name:

import joules

with joules.Session() as s:
    for batch in loader:
        with s.phase("forward"):
            out = model(batch)
        with s.phase("backward"):
            out.loss.backward()
    print(s.summary())   # per phase: count, median energy and time, quartiles

Why not read nvidia-smi or the power reading?

Make the number mean something

Measure a whole script instead

No code changes at all:

joules -- python train.py

It prints the energy of each GPU, the CPU and DRAM, the time, the cost and the carbon.

Next