From d4754ad881a15795400778841df924f0fd84a3cf Mon Sep 17 00:00:00 2001 From: Kavyansh Tyagi <142140238+KAVYANSHTYAGI@users.noreply.github.com> Date: Mon, 2 Jun 2025 18:54:57 +0530 Subject: [PATCH 1/3] Update test_mlflow.py --- tests/tests_pytorch/loggers/test_mlflow.py | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/tests_pytorch/loggers/test_mlflow.py b/tests/tests_pytorch/loggers/test_mlflow.py index c7f9dbe1fe2c6..d99449eb9f893 100644 --- a/tests/tests_pytorch/loggers/test_mlflow.py +++ b/tests/tests_pytorch/loggers/test_mlflow.py @@ -427,3 +427,35 @@ def test_set_tracking_uri(mlflow_mock): mlflow_mock.set_tracking_uri.assert_not_called() _ = logger.experiment mlflow_mock.set_tracking_uri.assert_called_with("the_tracking_uri") + +def test_mlflowlogger_metric_deduplication(monkeypatch): + import types + from lightning.pytorch.loggers.mlflow import MLFlowLogger + + # Dummy MLflow client to record log_batch calls + logged_metrics = [] + class DummyMlflowClient: + def log_batch(self, run_id, metrics, **kwargs): + logged_metrics.extend(metrics) + def set_tracking_uri(self, uri): pass + def create_run(self, experiment_id, tags): + class Run: info = types.SimpleNamespace(run_id="dummy_run_id") + return Run() + def get_run(self, run_id): + class Run: info = types.SimpleNamespace(experiment_id="dummy_experiment_id") + return Run() + def get_experiment_by_name(self, name): return None + def create_experiment(self, name, artifact_location=None): return "dummy_experiment_id" + + # Patch the MLFlowLogger to use DummyMlflowClient + monkeypatch.setattr("mlflow.tracking.MlflowClient", lambda *a, **k: DummyMlflowClient()) + + logger = MLFlowLogger(experiment_name="test_exp") + logger.log_metrics({'foo': 1.0}, step=5) + logger.log_metrics({'foo': 1.0}, step=5) # duplicate + + # Only the first metric should be logged + assert len(logged_metrics) == 1 + assert logged_metrics[0].key == "foo" + assert logged_metrics[0].value == 1.0 + assert logged_metrics[0].step == 5 From 0773eb455b13812674547dc81833d78fa09a2faa Mon Sep 17 00:00:00 2001 From: Kavyansh Tyagi <142140238+KAVYANSHTYAGI@users.noreply.github.com> Date: Mon, 2 Jun 2025 19:02:50 +0530 Subject: [PATCH 2/3] test_mlflow.py --- tests/tests_pytorch/loggers/test_mlflow.py | 32 ---------------------- 1 file changed, 32 deletions(-) diff --git a/tests/tests_pytorch/loggers/test_mlflow.py b/tests/tests_pytorch/loggers/test_mlflow.py index d99449eb9f893..c7f9dbe1fe2c6 100644 --- a/tests/tests_pytorch/loggers/test_mlflow.py +++ b/tests/tests_pytorch/loggers/test_mlflow.py @@ -427,35 +427,3 @@ def test_set_tracking_uri(mlflow_mock): mlflow_mock.set_tracking_uri.assert_not_called() _ = logger.experiment mlflow_mock.set_tracking_uri.assert_called_with("the_tracking_uri") - -def test_mlflowlogger_metric_deduplication(monkeypatch): - import types - from lightning.pytorch.loggers.mlflow import MLFlowLogger - - # Dummy MLflow client to record log_batch calls - logged_metrics = [] - class DummyMlflowClient: - def log_batch(self, run_id, metrics, **kwargs): - logged_metrics.extend(metrics) - def set_tracking_uri(self, uri): pass - def create_run(self, experiment_id, tags): - class Run: info = types.SimpleNamespace(run_id="dummy_run_id") - return Run() - def get_run(self, run_id): - class Run: info = types.SimpleNamespace(experiment_id="dummy_experiment_id") - return Run() - def get_experiment_by_name(self, name): return None - def create_experiment(self, name, artifact_location=None): return "dummy_experiment_id" - - # Patch the MLFlowLogger to use DummyMlflowClient - monkeypatch.setattr("mlflow.tracking.MlflowClient", lambda *a, **k: DummyMlflowClient()) - - logger = MLFlowLogger(experiment_name="test_exp") - logger.log_metrics({'foo': 1.0}, step=5) - logger.log_metrics({'foo': 1.0}, step=5) # duplicate - - # Only the first metric should be logged - assert len(logged_metrics) == 1 - assert logged_metrics[0].key == "foo" - assert logged_metrics[0].value == 1.0 - assert logged_metrics[0].step == 5 From c592d3b42dec98b7b9555121ac65b08b02d04f16 Mon Sep 17 00:00:00 2001 From: Kavyansh Tyagi <142140238+KAVYANSHTYAGI@users.noreply.github.com> Date: Sat, 7 Jun 2025 13:59:07 +0530 Subject: [PATCH 3/3] Fix logging message formatting in setup --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 92f0265eafb9f..b432033a0d8c4 100755 --- a/setup.py +++ b/setup.py @@ -110,7 +110,8 @@ def _set_manifest_path(manifest_dir: str, aggregate: bool = False, mapping: Mapp assert os.path.exists(manifest_path) # avoid error: setup script specifies an absolute path manifest_path = os.path.relpath(manifest_path, _PATH_ROOT) - logging.info("Set manifest path to", manifest_path) + # Use lazy logging formatting + logging.info("Set manifest path to %s", manifest_path) setuptools.command.egg_info.manifest_maker.template = manifest_path yield # cleanup