Skip to content

Codecarbon version 3.0.0 #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 90 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
d8409ae
build on codecarbon_v3_rc
Dec 11, 2024
a31f4bd
bump
Dec 11, 2024
b3bf622
hatch run dev:bumpver update --set-version 3.0.0-rc0 --tag-num
Dec 11, 2024
b8e1a9a
Add CPU load tracking
benoit-cty Jun 13, 2022
455cb6b
Add new CPU
benoit-cty Jun 14, 2022
b9ce886
Add mandatory country
benoit-cty Jun 14, 2022
0fb7805
Fix RAPL fallback
benoit-cty Jun 14, 2022
747637f
debug RAPL
Nov 26, 2024
7118d1e
Release Drafter
Dec 11, 2024
dca73f3
refacto ResourceTracker
Dec 11, 2024
59b3a15
example
Dec 12, 2024
e30ba69
Add CPU load
Jan 7, 2025
cc1e661
Add division to Power
Jan 7, 2025
9f73cbf
Handle Pandas warning
Jan 7, 2025
6a9509d
CPU Load task support
Jan 7, 2025
8172f73
CPU load and RAPL comparison
Jan 7, 2025
69384f3
Better cpu load estimation
Jan 8, 2025
e3740a2
change version
Jan 10, 2025
185fa1a
Fix test test_carbon_tracker_offline_region_error
Jan 10, 2025
e8089f4
RAPL path
Jan 10, 2025
af293f4
Handle no Tapo
Jan 10, 2025
c9b4e59
Debug config
Jan 10, 2025
7762896
wip: test on Scaleway
Jan 10, 2025
6316c13
Add load per core
Jan 10, 2025
9b92614
Add E5-2620 v3
Jan 11, 2025
0d21378
Add a TDP test
Jan 11, 2025
ce725f9
Fix match for Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz
Jan 11, 2025
8c87972
Fix psutil detection
Jan 11, 2025
95757d3
Fix cpu 0
Jan 11, 2025
c20b05d
Scaleway test results
Jan 12, 2025
8958709
Notes on E5-2620
Jan 12, 2025
05bb94e
Add count_physical_cpus
Jan 14, 2025
95a0e72
Multiply TDP per physical CPU
Jan 14, 2025
21dc0aa
Custom CPU load
Jan 14, 2025
edb5645
Find RAM domain
Jan 14, 2025
2fbe2a9
Handle RAPL RAM
Jan 14, 2025
5711478
Improve RAPL
Jan 14, 2025
07fec48
Do not read core
Jan 14, 2025
692c128
Docs
Jan 14, 2025
25f1074
CPU Fallback doc
Jan 17, 2025
5ef4897
AMD CPU
Feb 3, 2025
12357e3
Add W per core for default
benoit-cty Feb 4, 2025
e3e1410
Data on CPU loads
Feb 14, 2025
239af2c
fix circular import
Feb 15, 2025
19a46a8
Default to 1 CPU
Feb 15, 2025
ec42aa9
Fix case TDP is None
Feb 15, 2025
ad9f744
bump
Feb 15, 2025
cfd8c1f
docs
Feb 15, 2025
682f960
fix: remove percpu argument for psutil.cpu_percent & process.cpu_perc…
SaboniAmine Feb 17, 2025
a82ac13
remove percpu
Feb 18, 2025
3d050b0
Set minimal version for psutil
Feb 18, 2025
850a6b1
bump deps
Feb 18, 2025
176d4fa
bump to rc2
Feb 18, 2025
89e19f2
Fix _get_power_from_cpu_load in process mode
Feb 18, 2025
08d6caf
Fix pandas warning
Feb 18, 2025
b428426
Add AMD EPYC 7R13
benoit-cty Feb 20, 2025
511e3f3
Fix percentage
Feb 20, 2025
9b803bc
bump
Feb 20, 2025
d5c2e24
fix: redirect user to dashboard after cli account creation (#763)
SaboniAmine Jan 19, 2025
2432703
chore: bump version (#765)
SaboniAmine Jan 19, 2025
50c77b4
feat: allow_multiple_runs is true by default
inimaz Feb 6, 2025
7a032ef
deps bump
benoit-cty Jan 28, 2025
e9286af
Bump deps
Jan 29, 2025
6389e8a
fix line feed
Apr 13, 2025
404ac46
rebuild docs
Apr 13, 2025
1310f0a
bump deps
Apr 13, 2025
6502d40
New heuristic for RAM
Mar 15, 2025
39e52db
Fix test and RAM slot power
Mar 15, 2025
5958346
force ram and cpu power
Mar 28, 2025
09a045a
tests
Mar 28, 2025
449f8c3
force_ram_power
Apr 2, 2025
903526d
seems to work
Apr 2, 2025
c28bdc0
Fix test
Apr 6, 2025
cde578c
bump and docs
Apr 6, 2025
d007d33
doc
Apr 6, 2025
3aaddb0
fix bug with psutil detection
Apr 11, 2025
ad94a4e
bump
Apr 11, 2025
8732fc8
Add a minimum of 10% TDP
Apr 11, 2025
24ebb41
Log modes to INFO
Apr 11, 2025
c968ccc
bump
Apr 11, 2025
74261fd
fix max
Apr 11, 2025
c609e26
Typo
Apr 12, 2025
a9a7183
typo
Apr 12, 2025
ecbe924
bump deps
Apr 13, 2025
66cd832
doc
Apr 13, 2025
545983d
bump to 3.0.0
Apr 15, 2025
67e821e
build doc
Apr 15, 2025
0792bc8
bump deps
Apr 15, 2025
0040777
lint
Apr 17, 2025
a5e001e
cleaning
Apr 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
APP_NAME: cc_dashboard_prod
run: |
./clever-tools-latest_linux/clever link $CLEVER_APP_ID
./clever-tools-latest_linux/clever deploy -f -a $APP_NAME --quiet
./clever-tools-latest_linux/clever deploy -f -a $APP_NAME --quiet
2 changes: 1 addition & 1 deletion .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ jobs:
run: mamba install --channel file:///tmp/conda-bld --channel codecarbon codecarbon
- name: Test conda package
shell: bash -l {0}
run: codecarbon --help
run: codecarbon --help
5 changes: 2 additions & 3 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ name: Release Drafter
on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master
branches: [master]

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5.7.0
- uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 changes: 11 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ Here is the launch.json to be able to debug examples and tests:
{
"version": "0.2.0",
"configurations": [

{
"name": "Python: Current File",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
Expand All @@ -261,13 +262,17 @@ Here is the launch.json to be able to debug examples and tests:
},
{
"name": "PyTest: Current File",
"type": "python",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": ["${file}"],
"args": [
"-s",
"${file}"
],
"console": "integratedTerminal",
"justMyCode": true,
"env": { "PYTHONPATH": "${workspaceRoot}" }
"env": { "PYTHONPATH": "${workspaceRoot}",
"CODECARBON_ALLOW_MULTIPLE_RUNS": "True" }
},
{
"name": "PyTest: codecarbon monitor",
Expand All @@ -279,7 +284,7 @@ Here is the launch.json to be able to debug examples and tests:
],
"console": "integratedTerminal",
"justMyCode": true,
"env": { "PYTHONPATH": "${workspaceRoot}" }
"env": { "PYTHONPATH": "${workspaceRoot}"}
}
]
}
Expand Down Expand Up @@ -350,7 +355,7 @@ to regenerate the html files.
### Release process

- Merge all PRs.
- Create a PR bumping the version with `hatch run dev:bumpver update --patch`.
- Create a PR bumping the version with `hatch run dev:bumpver update --patch`. For a release candidate, use `hatch run dev:bumpver update --set-version 3.0.0_rc1`.
- Run `hatch run python3 .github/check_version.py` to check version consistancy.
- Update the dependencies with `hatch-pip-compile --upgrade --all`.
- [Build Documentation](#documentation) if needed with `hatch run docs:build`.
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,9 @@ Here is a sample for BibTeX:
# Contact 📝

Maintainers are [@vict0rsch](https://github.com/vict0rsch) [@benoit-cty](https://github.com/benoit-cty) and [@SaboniAmine](https://github.com/saboniamine). Codecarbon is developed by volunteers from [**Mila**](http://mila.quebec) and the [**DataForGoodFR**](https://twitter.com/dataforgood_fr) community alongside donated professional time of engineers at [**Comet.ml**](https://comet.ml) and [**BCG GAMMA**](https://www.bcg.com/en-nl/beyond-consulting/bcg-gamma/default).

## Star History

Comparison of the number of stars accumulated by the different Python CO2 emissions projects:
[![Star History Chart](https://api.star-history.com/svg?repos=mlco2/codecarbon,lfwa/carbontracker,sb-ai-lab/Eco2AI,fvaleye/tracarbon,Breakend/experiment-impact-tracker&type=Date)](https://star-history.com/#mlco2/codecarbon&lfwa/carbontracker&sb-ai-lab/Eco2AI&fvaleye/tracarbon&Breakend/experiment-impact-tracker&Date)

2 changes: 1 addition & 1 deletion codecarbon/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.8.4"
__version__ = "3.0.0"
4 changes: 2 additions & 2 deletions codecarbon/core/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ def _create_run(self, experiment_id: str):
gpu_count=self.conf.get("gpu_count"),
gpu_model=self.conf.get("gpu_model"),
# Reduce precision for Privacy
longitude=round(self.conf.get("longitude"), 1),
latitude=round(self.conf.get("latitude"), 1),
longitude=round(self.conf.get("longitude", 0), 1),
latitude=round(self.conf.get("latitude", 0), 1),
region=self.conf.get("region"),
provider=self.conf.get("provider"),
ram_total_size=self.conf.get("ram_total_size"),
Expand Down
53 changes: 48 additions & 5 deletions codecarbon/core/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"""

import os
import re
import shutil
import subprocess
import sys
from typing import Dict, Optional, Tuple

import pandas as pd
import psutil
from rapidfuzz import fuzz, process, utils

from codecarbon.core.rapl import RAPLFile
Expand All @@ -19,6 +21,9 @@
from codecarbon.external.logger import logger
from codecarbon.input import DataSource

# default W value per core for a CPU if no model is found in the ref csv
DEFAULT_POWER_PER_CORE = 4


def is_powergadget_available() -> bool:
"""
Expand Down Expand Up @@ -58,6 +63,24 @@ def is_rapl_available() -> bool:
return False


def is_psutil_available():
try:
nice = psutil.cpu_times().nice
if nice > 0.0001:
return True
else:
logger.debug(
f"is_psutil_available() : psutil.cpu_times().nice is too small : {nice} !"
)
return False
except Exception as e:
logger.debug(
"Not using the psutil interface, an exception occurred while instantiating "
+ f"psutil.cpu_times : {e}",
)
return False


class IntelPowerGadget:
"""
A class to interface with Intel Power Gadget for monitoring CPU power consumption on Windows and (non-Apple Silicon) macOS.
Expand Down Expand Up @@ -237,7 +260,7 @@ class IntelRAPL:

"""

def __init__(self, rapl_dir="/sys/class/powercap/intel-rapl"):
def __init__(self, rapl_dir="/sys/class/powercap/intel-rapl/subsystem"):
self._lin_rapl_dir = rapl_dir
self._system = sys.platform.lower()
self._rapl_files = []
Expand Down Expand Up @@ -275,6 +298,8 @@ def _fetch_rapl_files(self) -> None:
with open(path) as f:
name = f.read().strip()
# Fake the name used by Power Gadget
# We ignore "core" in name as it seems to be included in "package" for Intel CPU.
# TODO: Use "dram" for memory power
if "package" in name:
name = f"Processor Energy Delta_{i}(kWh)"
i += 1
Expand All @@ -294,7 +319,7 @@ def _fetch_rapl_files(self) -> None:
logger.debug("We will read Intel RAPL files at %s", rapl_file)
except PermissionError as e:
raise PermissionError(
"Unable to read Intel RAPL files for CPU power, we will use a constant for your CPU power."
"PermissionError : Unable to read Intel RAPL files for CPU power, we will use a constant for your CPU power."
+ " Please view https://github.com/mlco2/codecarbon/issues/244"
+ " for workarounds : %s",
e,
Expand Down Expand Up @@ -332,8 +357,6 @@ def get_static_cpu_details(self) -> Dict:
"""
Return CPU details without computing them.
"""
logger.debug("get_static_cpu_details %s", self._cpu_details)

return self._cpu_details

def start(self) -> None:
Expand Down Expand Up @@ -426,6 +449,18 @@ def _get_matching_cpu(
start_cpu = model_raw.find(" CPU @ ")
if start_cpu > 0:
model_raw = model_raw[0:start_cpu]
model_raw = model_raw.replace(" CPU", "")
model_raw = re.sub(r" @\s*\d+\.\d+GHz", "", model_raw)
direct_match = process.extractOne(
model_raw,
cpu_df["Name"],
processor=lambda s: s.lower(),
scorer=fuzz.ratio,
score_cutoff=THRESHOLD_DIRECT,
)

if direct_match:
return direct_match[0]
indirect_matches = process.extract(
model_raw,
cpu_df["Name"],
Expand Down Expand Up @@ -467,10 +502,18 @@ def _main(self) -> Tuple[str, int]:
+ " Please contact us.",
cpu_model_detected,
)
if is_psutil_available():
# Count thread of the CPU
threads = psutil.cpu_count(logical=True)
estimated_tdp = threads * DEFAULT_POWER_PER_CORE
logger.warning(
f"We will use the default power consumption of {DEFAULT_POWER_PER_CORE} W per thread for your {threads} CPU, so {estimated_tdp}W."
)
return cpu_model_detected, estimated_tdp
return cpu_model_detected, None
logger.warning(
"We were unable to detect your CPU using the `cpuinfo` package."
+ " Resorting to a default power consumption of 85W."
+ " Resorting to a default power consumption."
)
return "Unknown", None

Expand Down
4 changes: 2 additions & 2 deletions codecarbon/core/emissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_cloud_country_iso_code(self, cloud: CloudMetadata) -> str:
selected = df.loc[flags]
if not len(selected):
raise ValueError(
"Unable to find country name for "
"Unable to find country ISO Code for "
f"cloud_provider={cloud.provider}, "
f"cloud_region={cloud.region}"
)
Expand All @@ -105,7 +105,7 @@ def get_cloud_geo_region(self, cloud: CloudMetadata) -> str:
selected = df.loc[flags]
if not len(selected):
raise ValueError(
"Unable to find country name for "
"Unable to find State/City name for "
f"cloud_provider={cloud.provider}, "
f"cloud_region={cloud.region}"
)
Expand Down
Loading
Loading