Skip to main content

gpuest

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 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 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.1

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.1
File Size Uploaded Provenance Actions
gpuest-0.1.1.tar.gz 10.5 kB Without provenance Details for gpuest-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 21.5 kB

Release files / gpuest-0.1.1.tar.gz

Download URL gpuest-0.1.1.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fde4cd13638e8997055ad53ceea6a87f961d0ab7396d0d7a6a8e42945fb69e10
BLAKE2b-256 checksum
How to use checksums
1202f30cea85208da30bb2eec612749ebb7e672668df7a5c9a6e147a959ee94d
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.1-py3-none-any.whl

Download URL gpuest-0.1.1-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
285f4f14e871591a0eafd6c41483bb2076820cfdd1e076a60026a416c6581f36
BLAKE2b-256 checksum
How to use checksums
1e4409416961aaaa275e93daff344c70bc905091a029b01ad6f6d300e5208258
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.1

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.1 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