Skip to main content

GPU energy metering for AI training workloads

Project description

matcha

GPU energy metering for AI training workloads

PyPI version PyPI Downloads Python License

Measure GPU energy consumption of any training run. One command. Zero overhead. Zero code changes.


Install

pip install matcha-gpu

Requires an NVIDIA GPU with drivers installed.

Quick Start

Prefix your training command with matcha run:

matcha run torchrun --standalone --nproc_per_node=1 train_gpt.py

Your training runs at full speed. Matcha appends one line at the end:

matcha_energy total:364722J (101.31Wh) duration:746.0s avg_power:489W peak_power:700W samples:7449

That's it. No code changes. No config files. Works with any training script.

How It Works

Matcha runs a lightweight background thread that polls GPU power via NVML at 100ms intervals. Your training process runs natively — no stdout interception, no wrapper overhead. When training finishes, Matcha computes total energy using trapezoidal integration of instantaneous power readings.

Commands

matcha run — Zero overhead energy measurement

# Measure total energy for any training command
matcha run python train.py
matcha run torchrun --standalone --nproc_per_node=1 train_gpt.py
matcha run deepspeed --num_gpus=4 train.py --deepspeed ds_config.json

matcha wrap — Per-step energy breakdown

# See energy for each training step (some overhead)
matcha wrap -p python train.py

Parses stdout for step markers (step 10, iter 10, [10/1000], etc.) and reports energy between each step. Useful for diagnosing energy spikes and inefficient training phases.

matcha monitor — Live GPU power monitoring

# Watch GPU power draw in real time
matcha monitor
matcha monitor --gpu 0 --window 2.0

Python SDK

import matcha

m = matcha.init()

for step in range(num_steps):
    m.step_start()
    # ... your training code, unchanged ...
    energy = m.step_end(step)

summary = m.finish()
# summary.total_energy_j, summary.energy_kwh, summary.j_per_step

Example Output

step:1/20000 train_loss:6.9357 train_time:356ms step_avg:356.10ms
step:2/20000 train_loss:16.7414 train_time:725ms step_avg:362.47ms
...
step:1709/20000 val_loss:2.2111 val_bpb:1.3095 train_time:600097ms step_avg:351.14ms
final_int8_zlib_roundtrip_exact val_loss:2.21311047 val_bpb:1.31072868
matcha_energy total:364722J (101.31Wh) duration:746.0s avg_power:489W peak_power:700W samples:7449

Tested On

  • NVIDIA H100 80GB HBM3 — training nanoGPT variants at 500-700W
  • Works with torchrun, deepspeed, accelerate, or plain python
  • Compatible with PyTorch, JAX, and any framework that runs on NVIDIA GPUs

Why

GPU rental is expensive. Electricity is cheap. But knowing your energy profile tells you whether your GPU is actually working hard or sitting idle — and that directly maps to training efficiency and cost.

10-minute H100 training run:
  Energy cost:   $0.01 (101 Wh @ $0.12/kWh)
  Compute cost:  $0.48 (RunPod @ $2.90/hr)

  → Compute is 48x the energy cost
  → Optimizing energy/step = faster training = less rental time

Roadmap

  • Multi-GPU support (aggregate across 8xH100)
  • Log file tailing for zero-overhead per-step attribution
  • JSONL output for downstream analysis
  • Go sidecar binary for production deployments
  • Carbon footprint estimation by region

Built by

Keeya Labs · usematcha.dev

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matcha_gpu-0.2.4.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matcha_gpu-0.2.4-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file matcha_gpu-0.2.4.tar.gz.

File metadata

  • Download URL: matcha_gpu-0.2.4.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for matcha_gpu-0.2.4.tar.gz
Algorithm Hash digest
SHA256 4e8d43d7e23e534015169893c2dd58e9aa8ac9a92b8a72d82db05c54aeb58696
MD5 47f3f59bab7624921568f3eea6c85ca7
BLAKE2b-256 4bbe4f2458cbf470c03d0d858051a2ea1205aacc34a912b55cb31b7ee8ff8b90

See more details on using hashes here.

File details

Details for the file matcha_gpu-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: matcha_gpu-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for matcha_gpu-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 73ff0ad664e70833492cb845141983752fe5460460b9413da30f67a70ce69573
MD5 e174808dcd8cbed10006ce8ac2f1f243
BLAKE2b-256 6f1331796a387f28b85170ef4395dc21d2b4cbad1c32c152282c4984c8815b64

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page