Energy-efficient middleware for PyTorch ML workloads — tracks carbon, optimizes GPU, reports savings.
Project description
GreenTensor
Energy-efficient middleware for PyTorch ML workloads.
GreenTensor wraps your training loop with one line of code and gives you:
- Real carbon emissions and energy tracking (via CodeCarbon)
- Automatic GPU optimizations (cuDNN benchmark, mixed precision)
- Idle GPU detection to reduce wasted energy
- A detailed savings report comparing against your baseline
Install
pip install greentensor
Quickstart
from greentensor import GreenTensor
with GreenTensor() as gt:
with gt.mixed_precision():
train() # your existing training code, unchanged
Output:
+======================================+
| GreenTensor Report |
+======================================+
Runtime : 12.34 s
Energy Used : 0.000412 kWh
CO2 Emissions : 0.000096 kg
======================================
Compare against a baseline
import pickle
from greentensor import GreenTensor
from greentensor.core.tracker import Tracker
from greentensor.report.metrics import RunMetrics
import time
# 1. Run baseline (no optimizations)
tracker = Tracker()
tracker.start()
t0 = time.perf_counter()
train()
duration = time.perf_counter() - t0
emissions_kg, energy_kwh = tracker.stop()
baseline = RunMetrics(duration_s=duration, energy_kwh=energy_kwh, emissions_kg=emissions_kg)
# 2. Run optimized — report shows real savings
with GreenTensor(baseline=baseline) as gt:
with gt.mixed_precision():
train()
Batch size optimizer
from greentensor import optimize_batch_size
batch_size = optimize_batch_size(32) # auto-scales based on available GPU memory
Dashboard
streamlit run dashboard/app.py
Enter baseline and optimized metrics manually, or upload .pkl files saved from your runs.
Configuration
from greentensor import GreenTensor, Config
config = Config(
enable_cudnn_benchmark=True,
enable_mixed_precision=True,
idle_threshold_pct=10.0, # GPU util % below which idle is detected
max_batch_size=512,
)
with GreenTensor(config=config) as gt:
train()
Run tests
pip install pytest
pytest tests/ -v
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file greentensor-0.1.0.tar.gz.
File metadata
- Download URL: greentensor-0.1.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf8ea6860fcb45b09b5f75402b824ac8056a75026757d7bafc96eb1ab0d02022
|
|
| MD5 |
f7a0cad62b90b78a21b6dc39cc073258
|
|
| BLAKE2b-256 |
ff6c61fa5b9ced402b0285b726f18029f6d01ff1afe2c49824117708d5c9801c
|
File details
Details for the file greentensor-0.1.0-py3-none-any.whl.
File metadata
- Download URL: greentensor-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5002976c39738a33d9ee8622779dafeda2cb204a5f78df9647235980d10d72ab
|
|
| MD5 |
ad3ed6fb34d7f8072fc46b0bcbc9273c
|
|
| BLAKE2b-256 |
0a007cb354b079954cd5ae09c9e423b337b0982fa1389863936b950c5b10a71b
|