mlco2 / codecarbon

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

Clarification on Power vs. Energy in CodeCarbon Calculations #654

Open RafiullahOmar opened 3 weeks ago

RafiullahOmar commented 3 weeks ago

Description

How does CodeCarbon differentiate between 'power' and 'energy' in its calculations? Could someone clarify how CodeCarbon handles these two concepts?

What I Did

After a quick search, I got the feeling that these terms are used interchangeably in some contexts.

benoit-cty commented 3 weeks ago

Thanks for reporting this.

We try to consistently use Energy = Power * Time and Power = Energy / Time , can you tell where there still have mistake ?

RafiullahOmar commented 3 weeks ago

Actually, after a quick review, I couldn't find out if they are dealt with differently and what the tracker returns: power or energy. I assumed power, but for confirmation, I had a quick review and couldn't find it

benoit-cty commented 2 weeks ago

We return the sum of energy, we also return power but it will be the last power, not the mean of all measured power : https://github.com/mlco2/codecarbon/blob/e6d1ca5e93028f03368a5c54ba9f8765ee1ac55a/codecarbon/emissions_tracker.py#L711

RafiullahOmar commented 1 week ago

Is there any possibility to get the mean of all power for a specific task same like we get the energy?

benoit-cty commented 1 week ago

You could divide the energy by the duration to get the mean power. So I don't know if implementing a mean by adding a sum and a counter make sense.

headscott commented 1 week ago

According to the question about mean power: isn't cpu_power, gpu_power and ram_power the average use of Watt per second? So if I add these 3 values, I am getting the average power for gpu, cpu and ram per second?

benoit-cty commented 4 hours ago

Looking at the code, I think it's only the last measured power that is stored.