Skip to content

Commit e168655

Browse files
authored
Merge pull request #1072 from mlco2/feat/rocm
AMD ROCm support
2 parents c2b8df8 + a429a4b commit e168655

36 files changed

Lines changed: 3252 additions & 748 deletions

CONTRIBUTING.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ flake8...................................................................Passed
258258

259259
If any of the linters/formatters fail, check the difference with `git diff`, add the differences if there is no behavior changes (isort and black might have change some coding style or import order, this is expected it is their job) with `git add` and finally try to commit again `git commit ...`.
260260

261-
You can also run `pre-commit` with `uv run pre-commit run -v` if you have some changes staged but you are not ready yet to commit.
261+
You can also run `pre-commit` with `uv run pre-commit run --all-file` to check all file.
262262

263263

264264
<!-- TOC --><a name="dependencies-management"></a>
@@ -363,6 +363,18 @@ cp /data/tests/test_package_integrity.py .
363363
pytest test_package_integrity.py
364364
```
365365

366+
### Contribute to a fork branch
367+
368+
When a user open a PR from a fork, we are allowed to push to the fork branch.
369+
370+
If you want to do so, do the following:
371+
372+
```bash
373+
git remote add <user_name> https://github.com/<user_name>/codecarbon.git
374+
git fetch <user_name> <git_branch>
375+
git checkout -b <git_branch> <user_name>/<git_branch>
376+
```
377+
366378
<!-- TOC --><a name="api-and-dashboard"></a>
367379
## API and Dashboard
368380

codecarbon/cli/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ def monitor(
345345
if offline:
346346
if not country_iso_code:
347347
print(
348-
"ERROR: country_iso_code is required for offline mode", file=sys.stderr
348+
"ERROR: Country ISO code is required for offline mode. Add it to your configuration or provide it via the command line: `--country-iso-code FRA`",
349+
file=sys.stderr,
349350
)
350351
raise typer.Exit(1)
351352

@@ -358,7 +359,7 @@ def monitor(
358359
experiment_id = get_existing_local_exp_id()
359360
if api and experiment_id is None:
360361
print(
361-
"ERROR: No experiment id, call 'codecarbon config' first.",
362+
"ERROR: No experiment id, call 'codecarbon config' first. Or run in offline mode with `--offline --country-iso-code FRA` flag if you don't want to connect to the API.",
362363
file=sys.stderr,
363364
)
364365
raise typer.Exit(1)

codecarbon/core/config.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import configparser
22
import os
33
from pathlib import Path
4-
from typing import List, Union
4+
from typing import List, Optional, Union
55

66
from codecarbon.external.logger import logger
77

@@ -73,6 +73,43 @@ def parse_gpu_ids(gpu_ids: Union[str, List[int]]) -> List[str]:
7373
)
7474

7575

76+
def normalize_gpu_ids(
77+
gpu_ids: Optional[Union[str, List[Union[int, str]]]],
78+
) -> Optional[List[Union[int, str]]]:
79+
"""
80+
Normalize GPU IDs from config/user input into a list of ids consumable by hardware
81+
resolution code.
82+
83+
Supports:
84+
- comma-separated string values (sanitized via parse_gpu_ids)
85+
- lists containing ints and/or strings
86+
"""
87+
if gpu_ids is None:
88+
return None
89+
90+
if isinstance(gpu_ids, str):
91+
return parse_gpu_ids(gpu_ids)
92+
93+
if isinstance(gpu_ids, list):
94+
normalized_gpu_ids: List[Union[int, str]] = []
95+
for gpu_id in gpu_ids:
96+
if isinstance(gpu_id, int):
97+
normalized_gpu_ids.append(gpu_id)
98+
elif isinstance(gpu_id, str):
99+
normalized_gpu_ids.extend(parse_gpu_ids(gpu_id))
100+
else:
101+
logger.warning(
102+
"Ignoring invalid gpu_id entry of type %s; expected int or str.",
103+
type(gpu_id).__name__,
104+
)
105+
return normalized_gpu_ids
106+
107+
logger.warning(
108+
"Invalid gpu_ids format. Expected a string or a list of ints/strings."
109+
)
110+
return None
111+
112+
76113
def get_hierarchical_config():
77114
"""
78115
Get the user-defined codecarbon configuration ConfigParser dictionnary

codecarbon/core/cpu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from codecarbon.core.rapl import RAPLFile
1919
from codecarbon.core.units import Time
20-
from codecarbon.core.util import detect_cpu_model
20+
from codecarbon.core.util import count_cpus, detect_cpu_model
2121
from codecarbon.external.logger import logger
2222
from codecarbon.input import DataSource
2323

@@ -1001,7 +1001,7 @@ def _main(self) -> Tuple[str, int]:
10011001
)
10021002
if is_psutil_available():
10031003
# Count thread of the CPU
1004-
threads = psutil.cpu_count(logical=True)
1004+
threads = count_cpus()
10051005
estimated_tdp = threads * DEFAULT_POWER_PER_CORE
10061006
logger.warning(
10071007
f"We will use the default power consumption of {DEFAULT_POWER_PER_CORE} W per thread for your {threads} CPU, so {estimated_tdp}W."

0 commit comments

Comments
 (0)