mlco2 / codecarbon

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

more tracker instances #681

Open enricocapuano opened 1 month ago

enricocapuano commented 1 month ago

Goodmorning! I'm trying to use the last version of CodeCarbon and I'm facing this problem: when I create more than one instance of tracker in my file, I receive this error. [codecarbon ERROR @ 13:41:42] Error: Another instance of codecarbon is already running. Turn off the other instance to be able to run this one. Exiting. [codecarbon WARNING @ 13:41:42] Another instance of codecarbon is already running. Exiting.

Is it possible to create more than one instance of tracker or not? How can I do it?

inimaz commented 1 month ago

Hello @enricocapuano ! Thanks for using codecarbon. We added this as a lock so that only one instance is running at the same time in the machine, otherwise you will be measuring twice the same CPU/GPU/RAM energy, power...

That said, to understand your use case better, why do you need more than one instance of the tracker running at the same time?

enricocapuano commented 1 month ago

Hello @inimaz, thanks for answering! I need to do a comparison about consumptions between two different processes that do the same thing in different ways. Do you have any suggestions?

inimaz commented 1 month ago

Can you provide an example of your code? Normally as long as they are not run in parallel, there should be no problem with your use case.

benoit-cty commented 1 month ago

Running them is parallel is not supported by CodeCarbon as, for now, we monitor the whole machine and not only the process. There is a 'process' mode but it only support RAM usage, not CPU nor GPU yet.

enricocapuano commented 1 month ago

Ok, thanks for answering. I have another question: once I received that error, how can I fix it? Should I necessarily create another project? Thanks in advance

inimaz commented 1 month ago

If you still have the error running only one instance then it is a bug, could you provide an example of how you are running it in your code? A workaround until the fix is ready is to remove manually the lock file. It is a file .codecarbon.lock that will be in your temp dir (in linux: /tmp, in windows: C:\Users\username\AppData\Local\Temp).

Example in Linux

rm /tmp/.codecarbon.lock

enricocapuano commented 1 month ago

Thanks again. I already tried to remove the lock file and it did not work. Anyway, it seems that I solved my issue setting the parameter allow_multiple_runs as True when creating tracker instance. Thank you for the support!

inimaz commented 1 month ago

Nice! Then it means you were running things in parallel. Could you provide an example of your code? Otherwise it is hard to guess