mlco2 / codecarbon

Track emissions from Compute and recommend ways to reduce their impact on the environment.
https://mlco2.github.io/codecarbon
MIT License
1.12k stars 173 forks source link

Documentation is unclear about co2_signal_api_token functionality #403

Open epistoteles opened 1 year ago

epistoteles commented 1 year ago

Description

In the CodeCarbon documentation, you can see that you can add a co2_signal_api_token to your .codecarbon.config (on the "Parameters" page). However, I have found no indication of what effect this has and why I would want to do this in the entire documentation.

My assumption is the following: If I don't add an API key, CodeCarbon will use estimates for the carbon intensity of a particular country. If I do add an API key, CodeCarbon will query the current (more accurate) carbon intensity via the API.

Question 1: Is this assumption correct? Question 2: If it is correct, how often is the API queried? For example, if I start tracking in a Jupyter Notebook with tracker.start(), then train a model for 12 hours, then stop tracking with tracker.stop(), will CodeCarbon query the carbon intensity once at the init, or will it query the intensity once per hour and then average the values over the entire run? Sometimes models are trained for multiple days or even weeks, and if the carbon intensity is only queried once not using the API may actually be more accurate.

benoit-cty commented 1 year ago

Yes, your assumption is correct, we use CO2 Signal for real time carbon intensity, otherwise we use an annual mean.

The call to CO2 Signal is made in def _prepare_emissions_data( so it is at the end, before CodeCarbon write the result in a PDF. It is only if you use the CodeCarbon API that it will compute emissions before every API call so it will be more accurate. You could configure the interval between API calls.

benoit-cty commented 2 weeks ago

We need also to change the name of "CO2 Signal" to "Electricity Maps API" https://api-portal.electricitymaps.com/catalog/prd_8e3ood60rcv8f51h

And update the doc to say that it is now free.