Skip to main content

Carbon-aware PyTorch training plugin (multi-region via Electricity Maps/WattTime).

Project description

Carbon Aware ML (multi-region)

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. Users supply their own API credentials and desired region.

Installation

pip install -e .
# Optional extras
pip install -e '.[scheduler]'
pip install -e '.[tensorboard]'
pip install -e '.[all]'

Quickstart

from carbonaware_ml import CarbonAwareTrainer, providers

trainer = CarbonAwareTrainer(
    model=my_model,
    optimizer=my_optimizer,
    dataloader=my_dataloader,
    region=os.environ.get("CARBONAWARE_REGION", "CA-ON"),
    carbon_provider=providers.ElectricityMapsProvider(),
)

# Block until grid intensity is green enough, then train
trainer.train_until_green(threshold=200, num_epochs=3)

# Or always-on training but pausing when above threshold
trainer.train(num_epochs=3, threshold=200, check_interval_s=300)

You can also import via carbonaware_ml:

from carbonaware_ml import CarbonAwareTrainer

Providers:

  • Electricity Maps (real-time/forecast carbon intensity)
    • Set credentials via environment:
      • ELECTRICITYMAPS_API_TOKEN (required)
      • ELECTRICITYMAPS_EMAIL (optional; enables Basic Auth fallback if your plan requires it)
  • WattTime (alternative intensity source)
  • Ontario TOU price provider (demo, no API key)

If no external provider is configured, the trainer defaults to an "always-allow" mode.

Environment

  • CARBONAWARE_REGION: your region/zone (e.g., CA-ON, US-CAL-CISO, DE)
  • ELECTRICITYMAPS_API_TOKEN: Electricity Maps API token
  • ELECTRICITYMAPS_EMAIL: your Electricity Maps account email (if Basic Auth is needed)

License

MIT

CLI

carbonaware intensity --region CA-ON          # or set CARBONAWARE_REGION
carbonaware price --region CA-ON

TensorBoard

trainer = CarbonAwareTrainer(..., tb_log_dir="runs/demo")

Scheduler (optional)

from carbonaware_ontario.scheduler import run_when_favorable
sched = run_when_favorable(trainer, num_epochs=1, threshold=150, price_threshold_cents=12.0, check_interval_s=300)

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

carbonaware_ml-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

carbonaware_ml-0.1.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file carbonaware_ml-0.1.0.tar.gz.

File metadata

  • Download URL: carbonaware_ml-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.13.7 Darwin/22.6.0

File hashes

Hashes for carbonaware_ml-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ea8d2065ebe7c7dc48b2493f3667c368928504b69de3ef1499073863cc023e15
MD5 f8898edbe596b64691a6e03148bf0986
BLAKE2b-256 b29d4139524fb90df2c7759a1cdb46f1b0ff28ab0e7333638e1046faf7d7b1b3

See more details on using hashes here.

File details

Details for the file carbonaware_ml-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: carbonaware_ml-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.13.7 Darwin/22.6.0

File hashes

Hashes for carbonaware_ml-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 11fee6154bf07df00ae1129757910ff08d9be419f98e44720feceeed22cca630
MD5 09224b2d604406c363b9ff288c0a899c
BLAKE2b-256 f19bf1b93587a1e636319ba9272f66faa1402f9271455a7af60a49fc98885d8a

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