Carbon Aware ML
Carbon-aware training for PyTorch that pauses or schedules training based on real-time grid carbon intensity (and optionally electricity prices). Works in any region supported by Electricity Maps or WattTime. Each user supplies their own API credentials and region.
Installation
pip install 'carbonaware-ml[all]' # includes scheduler + tensorboard extras
# or minimal
pip install carbonaware-ml
# zsh users: extras must be quoted
Configure environment
export CARBONAWARE_REGION="CA-ON" # your authorized zone (e.g., US-CAL-CISO, DE)
export ELECTRICITYMAPS_API_TOKEN="<your_token>" # required for Electricity Maps
# Optional if your plan requires Basic Auth
export ELECTRICITYMAPS_EMAIL="you@example.com"
# Optional WattTime instead of Electricity Maps
# export WATTTIME_USERNAME="<user>"
# export WATTTIME_PASSWORD="<pass>"
Quickstart (Python)
import os
from carbonaware_ml import CarbonAwareTrainer, providers
# model/optimizer/dataloader are your own objects
trainer = CarbonAwareTrainer(
model=my_model,
optimizer=my_optimizer,
dataloader=my_dataloader,
region=os.environ.get("CARBONAWARE_REGION"),
carbon_provider=providers.ElectricityMapsProvider(),
)
# Start only when favorable
trainer.train_until_green(threshold=200, num_epochs=3)
# Or train now, pausing when conditions exceed thresholds
trainer.train(num_epochs=3, threshold=200, check_interval_s=300)
Providers:
- Electricity Maps (real-time/forecast carbon intensity)
- Env:
ELECTRICITYMAPS_API_TOKEN(required),ELECTRICITYMAPS_EMAIL(optional for Basic Auth)
- Env:
- WattTime (alternative intensity source via
WATTTIME_USERNAME/WATTTIME_PASSWORD)
If no external provider is configured, the trainer defaults to an "always-allow" mode.
CLI
# Use env region or pass explicitly
carbonaware intensity --region "$CARBONAWARE_REGION"
carbonaware price --region "$CARBONAWARE_REGION"
TensorBoard (optional)
trainer = CarbonAwareTrainer(..., tb_log_dir="runs/demo")
Scheduler (optional)
from carbonaware_ml.scheduler import run_when_favorable
sched = run_when_favorable(trainer, num_epochs=1, threshold=150, price_threshold_cents=12.0, check_interval_s=300)
Author
- Tom Almog (https://github.com/tomalmog)
License
MIT
Metadata
Release files for carbonaware-ml 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| carbonaware_ml-0.1.1.tar.gz | 8.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| carbonaware_ml-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.0 kB
Release files / carbonaware_ml-0.1.1.tar.gz
| Download URL | carbonaware_ml-0.1.1.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1832e3a9d451fa8ce5dad39e945f88cb81d9625add9d37cb56955366e1eb6b01
|
|
BLAKE2b-256 checksum How to use checksums |
f1828e5d4e5de0de1b21920e10b3e5fd9c0053106c83530ee4dd1ee69a2e4677
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.13.7 Darwin/22.6.0
|
Release files / carbonaware_ml-0.1.1-py3-none-any.whl
| Download URL | carbonaware_ml-0.1.1-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
481f87d18e2251a9e45b117e20aa14c66150019c436a703a4d501f80dcef5873
|
|
BLAKE2b-256 checksum How to use checksums |
8f580cb5aaf2c50e9850a929608ecb97e8be6f23d6f356bcc4dcde65f0dd033a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.13.7 Darwin/22.6.0
|
Security for carbonaware-ml 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.