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.5.tar.gz (10.7 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.5-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: matcha_gpu-0.2.5.tar.gz
  • Upload date:
  • Size: 10.7 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.5.tar.gz
Algorithm Hash digest
SHA256 681d6e9db38fa14004d3771ff41d6404a5d8d6b8e0c3a2d8f9acf82faa468a63
MD5 4d4ed4a256d74c2c454e414b5c419010
BLAKE2b-256 342ead36a8704806c1327b22da3550010815b1cf9eb241e39ab3848fa46acb6d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: matcha_gpu-0.2.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 80af30c3ddccf3d159718e8bfdacca2d26e05c7e542c839e6bdc035d4df24fe3
MD5 af8cc4193a44b9b5fc6f755054e8d50c
BLAKE2b-256 3d2d12714f55e9470c805c2ff7dfa06a31a7350ebe2abbf869b273f05a95f302

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