Skip to content

Commit 6034901

Browse files
fix: handle amdsmi load failures when libamd_smi is missing
When the amdsmi Python package is installed without ROCm (e.g. on macOS), import can raise KeyError while resolving libamd_smi.so. Treat AttributeError, OSError, and KeyError like a broken install: disable AMD metrics and warn instead of crashing the CodeCarbon CLI on import.
1 parent 7000cd4 commit 6034901

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

codecarbon/core/gpu_amd.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ def is_rocm_system():
2828
"Please install amdsmi to get GPU metrics."
2929
)
3030
AMDSMI_AVAILABLE = False
31-
except AttributeError as e:
31+
except (AttributeError, OSError, KeyError) as error:
3232
amdsmi = None
33-
# In some environments, amdsmi may be present but not properly configured, leading to AttributeError when importing
3433
logger.warning(
35-
"AMD GPU detected but amdsmi is not properly configured. "
36-
"Please ensure amdsmi is correctly installed to get GPU metrics."
37-
"Tips : check consistency between Python amdsmi package and ROCm versions, and ensure AMD drivers are up to date."
38-
f" Error: {e}"
34+
"amdsmi is installed but could not load libamd_smi (ROCm drivers missing "
35+
"or incompatible). AMD GPU metrics will be unavailable. Error: %s",
36+
error,
3937
)
4038
AMDSMI_AVAILABLE = False
4139

0 commit comments

Comments
 (0)