Codegreen is a Python package and CLI tool for energy profiling of Python code. It allows measuring the energy consumption of Deep learning framework APIs like TensorFlow.
Codegreen requires the following hardware:
- Intel processor
- NVIDIA GPU
The Intel processor is needed for accessing the RAPL power sensors. An NVIDIA GPU is required for profiling GPU usage via nvidia-smi
.
Make sure to add your respective local paths to the following files after installation:
codegreen/fecom/patching/patching_config.py
codegreen/fecom/measurement/measurement_config.py
pip install codegreen
Or install from source:
git clone https://github.com/user/codegreen
cd codegreen
pip install .
Run codegreen --help
to see the CLI options:
Usage: codegreen [OPTIONS] COMMAND [ARGS]...
๐ CodeGreen: Your Passport to a Greener Code! ๐
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --install-completion [bash|zsh|fish|power Install completion โ
โ shell|pwsh] for the specified โ
โ shell. โ
โ --show-completion [bash|zsh|fish|power Show completion for โ
โ shell|pwsh] the specified shell, โ
โ to copy it or โ
โ customize the โ
โ installation. โ
โ --help Show this message andโ
โ exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โญโ Commands โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ project-patcher Patch scripts for measurement โ
โ run-energy-profiler Start measurement server โ
โ start-energy-measurement Run patched scripts and collect data โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Basic usage:
codegreen project-patcher --project myscripts/
Patch all Python scripts in myscripts/
for instrumentation. Patched projects are saved with a _patched
suffix.
codegreen run-energy-profiler
This will start the energy measurement server.
codegreen start-energy-measurement --project repo_dir --scripts script_to_run --iterations "5"
This will run the patched scripts for project repo_dir
, scripts script_to_run
and number of run iterations n
and collect power usage data. Save the energy profiles and execution logs under experiments/
.
import codegreen
codegreen.profile(my_function)
See the API documentation for more details.
codegreen/
: Source codemain.py
: Main CLI entry pointfecom/
: Core measurement functionalitypatching/
: Code instrumentationmeasurement/
: Measurement and outputexperiment/
: Experimental configurations
utils/
: utility functions
codegreen is licensed under the Apache 2.0. See LICENSE for more details.