Skip to main content

GPU energy estimator

Creates a local database of GPU energy consumption tracking. Supports nvidia and amd vendors only, but may be extended to more. There are three steps to energy estimation:

  1. Record an idle energy profile (needed only if you need to subtract idle times from the next step)
  2. Record a workflow profile that outputs the task magnitude (e.g., number of tokens)
  3. Create an estimation of energy spent for new tasks

Results verify setup compatibility, and provide both mean estimation and confidence margins.

⚡ Quickstart

Install this as a library per pip install gpuest.

Then, create an initial energy profile for the machine's idle state. Energy profiles are stored in a file energy_profiles.toml that can be shared between the exact same setups. This is done with the idiom below, where the idle function needs to return its own sleep duration.

We will be using a helper function recording the idle profile, as that can be tricky to do robustly from the get go; the helper polls the GPU avery fixed number of seconds, and gets the minimum spent energy across ten such intervals. This avoids being influenced by energy spikes. The process is repeated to get a sense of idle estimation standard deviation. Make sure that the GPU is not utilized too much.

# 1_profile_idle.py
import time
from gpuest import Energy

energy = Energy("energy_profiles.toml")
energy.record_idle(intervals=5.0, batches=10, repetitions_per_batch=10)

Create an energy profile for your GPU compute, such as an LLM. Here we query an ollama model. The function passed to the profile should output some notion of near-linearly increasing magnitude for a task using the GPU, like the number of tokens.

You can make multiple recordings, for example corresponding to different prompts, and they aggregate (pass argument reset=True to overwrite previous values).

# 2_profile.py
import requests  # pip install requests
from gpuest.energy import Energy

model_name = "llama3.2:latest"


def ollama(prompt: str):
    response = requests.post(
        "http://localhost:11434/api/generate",
        json={"model": model_name, "prompt": prompt, "stream": False})
    if response.status_code != 200: return 0  # skip this measurement
    result = response.json()
    return result["prompt_eval_count"] + result["eval_count"]


energy = Energy()
for prompt in [
    "Who am I?",
    "To be or not to be?"
]: energy.record(model_name, lambda: ollama(prompt), batches=5, repetitions_per_batch=5)

Now, to estimate the energy consumption for the gathered energy profile, just run the following:

# 3_estimate.py
import requests  # pip install requests
from gpuest.energy import Energy

model_name = "llama3.2:latest"


def get_response(prompt):
    response = requests.post(
        "http://localhost:11434/api/generate",
        json={"model": model_name, "prompt": prompt, "stream": False})
    assert response.status_code == 200
    return response.json()


get_response("Hi.")  # hot start

energy = Energy()
prev_accumulated_energy = energy.vendor.get_gpu_accumulation()
result = get_response("What is CERTH? Explain in one sentence.")
energy_spent = energy.vendor.get_gpu_accumulation() - prev_accumulated_energy

magnitude = result["prompt_eval_count"] + result["eval_count"]
profile_vendor, estimation_mean, estimation_margin = energy.estimate("llama3.2:latest", magnitude)

print("Response: " + result["response"])
print(
    f"Energy cost for {profile_vendor} estimated {estimation_mean - estimation_margin:.3f} to {estimation_mean + estimation_margin:.3f} Joule consumption")
print(
    f"Total real energy cost: {energy_spent:.3f} (THIS INCLUDES THE IDLE AND OTHER WORKLOAD COST THAT THE ABOVE ESTIMATION EXCLUDES)")

Metadata

Release files for gpuest 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gpuest 0.1.0
File Size Uploaded Provenance Actions
gpuest-0.1.0.tar.gz 7.4 kB Without provenance Details for gpuest-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gpuest 0.1.0
File Interpreter ABI Platform Actions
gpuest-0.1.0-py3-none-any.whl Python 3 none any Details for gpuest-0.1.0-py3-none-any.whl

Total release size: 14.5 kB

Release files / gpuest-0.1.0.tar.gz

Download URL gpuest-0.1.0.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a12b3ce1cc4fc3fe13e838cece252b11e285f364ca30e457c0d65a36e603075f
BLAKE2b-256 checksum
How to use checksums
e56c95299809fd0dcd307d6910b72d005f657ff92e24f5deac730ef8540bab4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / gpuest-0.1.0-py3-none-any.whl

Download URL gpuest-0.1.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2eff6ba448a6b455929e8d705c85b80680c2f6ce71d3328a555663d044ef69c2
BLAKE2b-256 checksum
How to use checksums
ce4a187e8130132d38cde2a58dbfd8ef2b75ab4371a4f917a58a218e6388b54d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for gpuest 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page