Skip to content

Commit 9fc8975

Browse files
committed
Added mlflow system metrics.
1 parent d4a91bd commit 9fc8975

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@ bikes = 'bikes.scripts:main'
2323
[tool.poetry.dependencies]
2424
python = "^3.12"
2525
cloudpathlib = "^0.17.0"
26+
codecarbon = "^2.3.4"
2627
loguru = "^0.7.2"
28+
mlflow-skinny = "^2.10.2"
2729
omegaconf = "^2.3.0"
2830
pandas = "^2.2.0"
2931
pandera = "^0.18.0"
3032
plotly = "^5.18.0"
33+
psutil = "^5.9.8"
3134
pyarrow = "^15.0.0"
3235
pydantic = "^2.5.3"
3336
pydantic-settings = "^2.1.0"
37+
pynvml = "^11.5.0"
3438
scikit-learn = "^1.4.0"
35-
mlflow-skinny = "^2.10.2"
36-
codecarbon = "^2.3.4"
3739

3840
[tool.poetry.group.dev.dependencies]
3941
invoke = "^2.2.0"

src/bikes/services.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class MLflowService(Service):
132132
autolog_log_models (bool): If True, enables logging of models during autologging.
133133
autolog_log_datasets (bool): If True, logs datasets used during autologging.
134134
autolog_silent (bool): If True, suppresses all MLflow warnings during autologging.
135+
enable_system_metrics (bool): enable system metrics logging.
135136
tracking_uri (str): The URI for the MLflow tracking server.
136137
experiment_name (str): The name of the experiment to log runs under.
137138
registry_uri (str): The URI for the MLflow model registry.
@@ -147,6 +148,8 @@ class MLflowService(Service):
147148
autolog_log_models: bool = False
148149
autolog_log_datasets: bool = True
149150
autolog_silent: bool = False
151+
# system
152+
enable_system_metrics: bool = True
150153
# tracking
151154
tracking_uri: str = "http://localhost:5000"
152155
experiment_name: str = "bikes"
@@ -171,6 +174,9 @@ def start(self):
171174
log_models=self.autolog_log_models,
172175
silent=self.autolog_silent,
173176
)
177+
# system metrics
178+
if self.enable_system_metrics:
179+
mlflow.enable_system_metrics_logging()
174180

175181
def client(self) -> MlflowClient:
176182
"""Get an instance of MLflow client."""

tests/test_services.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44

55
import mlflow
6+
import pytest
67
from bikes import services
78
from loguru import logger
89

@@ -37,9 +38,11 @@ def test_carbon_service(tmp_carbon_path: str):
3738
assert os.stat(output_path).st_size > 0, "Output path should not be empty!"
3839

3940

40-
def test_mlflow_service(mlflow_service: services.MLflowService):
41+
@pytest.mark.parametrize("enable_system_metrics", [True, False])
42+
def test_mlflow_service(enable_system_metrics: bool, mlflow_service: services.MLflowService):
4143
# given
4244
service = mlflow_service
45+
service.enable_system_metrics = enable_system_metrics
4346
# when
4447
service.start()
4548
client = service.client()

0 commit comments

Comments
 (0)