Coder Social home page Coder Social logo

sb-ai-lab / eco2ai Goto Github PK

View Code? Open in Web Editor NEW
217.0 5.0 17.0 2.61 MB

eco2AI is a python library which accumulates statistics about power consumption and CO2 emission during running code.

License: Apache License 2.0

Python 100.00%
carbon-emissions carbon-footprint esg sustainability ai environment co2-emissions co2-monitoring energy-consumption power-consumption-measurement

eco2ai's Introduction

PyPI Downloads PyPI all Downloads

PyPI - Downloads PyPI - Downloads DOI telegram support

Eco2AI

About Eco2AI πŸ“‹

The Eco2AI is a python library for CO2 emission tracking. It monitors energy consumption of CPU & GPU devices and estimates equivalent carbon emissions taking into account the regional emission coefficient. The Eco2AI is applicable to all python scripts and all you need is to add the couple of strings to your code. All emissions data and information about your devices are recorded in a local file.

Every single run of Tracker() accompanies by a session description added to the log file, including the following elements:

  • project_name
  • experiment_description
  • start_time
  • duration(s)
  • power_consumption(kWTh)
  • CO2_emissions(kg)
  • CPU_name
  • GPU_name
  • OS
  • country

Installation

To install the eco2AI library, run the following command:

pip install eco2ai

Use examples

Example usage eco2AI Open In Collab You can also find eco2AI tutorial on youtube utube

The eco2AI interface is quite simple. Here is the simplest usage example:

import eco2ai

tracker = eco2ai.Tracker(project_name="YourProjectName", experiment_description="training the <your model> model")

tracker.start()

<your gpu &(or) cpu calculations>

tracker.stop()

The eco2AI also supports decorators. As soon as the decorated function is executed, the information about the emissions will be written to the emission.csv file:

from eco2ai import track

@track
def train_func(model, dataset, optimizer, epochs):
    ...

train_func(your_model, your_dataset, your_optimizer, your_epochs)

For your convenience, every time you instantiate the Tracker object with your custom parameters, these settings will be saved until the library is deleted. Each new tracker will be created with your custom settings (if you create a tracker with new parameters, they will be saved instead of the old ones). For example:

import eco2ai

tracker = eco2ai.Tracker(
    project_name="YourProjectName", 
    experiment_description="training <your model> model",
    file_name="emission.csv"
    )

tracker.start()
<your gpu &(or) cpu calculations>
tracker.stop()

...

# now, we want to create a new tracker for new calculations
tracker = eco2ai.Tracker()
# now, it's equivalent to:
# tracker = eco2ai.Tracker(
#     project_name="YourProjectName", 
#     experiment_description="training the <your model> model",
#     file_name="emission.csv"
# )
tracker.start()
<your gpu &(or) cpu calculations>
tracker.stop()

You can also set parameters using the set_params() function, as in the example below:

from eco2ai import set_params, Tracker

set_params(
    project_name="My_default_project_name",
    experiment_description="We trained...",
    file_name="my_emission_file.csv"
)

tracker = Tracker()
# now, it's equivelent to:
# tracker = Tracker(
#     project_name="My_default_project_name",
#     experiment_description="We trained...",
#     file_name="my_emission_file.csv"
# )
tracker.start()
<your code>
tracker.stop()

Important note

If for some reasons it is not possible to define country, then emission coefficient is set to 436.529kg/MWh, which is global average. Global Electricity Review

For proper calculation of gpu and cpu power consumption, you should create a "Tracker" before any gpu or CPU usage.

Create a new β€œTracker” for every new calculation.

Usage of Eco2AI

An example of using the library is given in the publication. It the paper we presented experiments of tracking equivalent CO2 emissions using eco2AI while training ruDALL-E models with with 1.3 billion (Malevich, ruDALL-E XL 1.3B) and 12 billion parameters (Kandinsky, ruDALL-E XL 12B). These are multimodal pre-trained transformers that learn the conditional distribution of images with by some string of text capable of generating arbitrary images from a russian text prompt that describes the desired result. Properly accounted carbon emissions and power consumption Malevich and Kandinsky fine-tuning Malevich and Kandinsky on the Emojis dataset is given in the table below.

Model Train time Power, kWh CO2, kg GPU CPU Batch Size
Malevich 4h 19m 1.37 0.33 A100 Graphics, 1 AMD EPYC 7742 64-Core 4
Kandinsky 9h 45m 24.50 5.89 A100 Graphics, 8 AMD EPYC 7742 64-Core 12

Also we presented results for training of Malevich with optimized variation of GELU activation function. Training of the Malevich with the 8-bit version of GELU allows us to spent about 10% less energy and, consequently, produce less equivalent CO2 emissions.

Citing Eco2AI

DOI

The Eco2AI is licensed under a Apache licence 2.0.

Please consider citing the following paper in any research manuscript using the Eco2AI library:

@inproceedings{budennyy2023eco2ai,
  title={Eco2ai: carbon emissions tracking of machine learning models as the first step towards sustainable ai},
  author={Budennyy, SA and Lazarev, VD and Zakharenko, NN and Korovin, AN and Plosskaya, OA and Dimitrov, DV and Akhripkin, VS and Pavlov, IV and Oseledets, IV and Barsola, IS and others},
  booktitle={Doklady Mathematics},
  pages={1--11},
  year={2023},
  organization={Springer}
}

In collaboration with

eco2ai's People

Contributors

alexnkorovin avatar nikitanikolaevich avatar parohod avatar vladimir-laz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

eco2ai's Issues

Compatibility with pandas>2.0

Thank you for the helpful package!

A problem I've been having is when I update my environment to use a newer version of pandas, it doesn't allow for higher pandas versions.

Is there any plans to update the package to be compatible with pandas > 2.0?

How does eco2AI handle using single GPUs on a multi GPU rack?

Hey there!

First of all, thank you for the great effort to make AI emissions more transparent, and for drawing more attention to this important topic! I have been using your tool to track the emissions for (small) language models and have a couple of questions regarding the usage of your tool.

Setup:
I have a cluster system with 4 GPUs (Tesla V100) available. I run my models with the CUDA_VISIBLE_DEVICES=gpu_id prefix in the command line to only use 1 specific GPU for my training.

Problem:
In the output csv, it says that 4 GPUs have been tracked, although I enforce only 1 GPU to be used

Questions:

  • Does eco2AI count the emissions of the whole rack while runtime (also runs by other people), or just the resources used by the code it is wrapped around? If the second is the case, why does it say 4 GPUs in the output file?
  • How would I specify using only 1 GPU in your code, if this is not done automatically?

Thank you very much in advance for your help

Cast error when converting string to float in get_cpu_percent_linux.

Hi, i got this error when running the tool (version 0.3.5):

image

when running top command, it shows me the values with commas:

image

Desktop

image

To fix it, i changed line 533 of eco2ai/tools/tools_cpu.py:

from: sum_cpu += float(words[8])
to: sum_cpu += float(words[8].replace(",","."))

Can you add this to the repo? thanks!
LucΓ­a

Usage with containers and application-level metrics

Hello,
I have a couple of questions:

  • Can Eco2AI be used in a private cloud in containerized applications orchestrated by K8s?
  • Does it track only the code's execution (just the application) or the total energy consumption of the system? and if it can track only the application's, how is it done?
    Thank you :)

Permisson problem with /eco2ai/data/config.txt

Hi, we are enjoying using your lib, but we have some problem, that isn't critical.

We have this lib on our linux servers and when user without root trying use this lib, he always has this problem.
image

The problem is solved by changing the write permissions in the /eco2ai/data/config.txt file to 777
But it would be nice if you changed this in your code, it might be better to create this file in the user's home directory every time.
It's minor problem, but after solving this problem, your lib would be better)

With respect, Mikhail R.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.