Skip to content

Commit

Permalink
Fix "finished" status code in MLFlowLogger (#16340)
Browse files Browse the repository at this point in the history

Co-authored-by: awaelchli <[email protected]>
  • Loading branch information
Forbu and awaelchli authored Jan 12, 2023
1 parent e7eddbd commit 898a236
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/pytorch_lightning/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed bug where the ``interval`` key of the scheduler would be ignored during manual optimization, making the LearningRateMonitor callback fail to log the learning rate ([#16308](https://github.com/Lightning-AI/lightning/pull/16308))


- Fixed an issue with `MLFlowLogger` not finalizing correctly when status code 'finished' was passed ([#16340](https://github.com/Lightning-AI/lightning/pull/16340))


## [1.8.6] - 2022-12-21

- minor cleaning
Expand Down
2 changes: 2 additions & 0 deletions src/pytorch_lightning/loggers/mlflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ def finalize(self, status: str = "success") -> None:
status = "FINISHED"
elif status == "failed":
status = "FAILED"
elif status == "finished":
status = "FINISHED"

# log checkpoints as artifacts
if self._checkpoint_callback:
Expand Down
21 changes: 21 additions & 0 deletions tests/tests_pytorch/loggers/test_mlflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,27 @@ def test_mlflow_logger_experiment_calls(client, _, time, param, metric, tmpdir):
)


@pytest.mark.parametrize(
"status,expected",
[
("success", "FINISHED"),
("failed", "FAILED"),
("finished", "FINISHED"),
],
)
@mock.patch("pytorch_lightning.loggers.mlflow._MLFLOW_AVAILABLE", return_value=True)
@mock.patch("pytorch_lightning.loggers.mlflow.MlflowClient")
def test_mlflow_logger_finalize(_, __, status, expected):
logger = MLFlowLogger("test")

# Pretend we are in a worker process and finalizing
_ = logger.experiment
assert logger._initialized

logger.finalize(status)
logger.experiment.set_terminated.assert_called_once_with(logger.run_id, expected)


@mock.patch("pytorch_lightning.loggers.mlflow._MLFLOW_AVAILABLE", return_value=True)
@mock.patch("pytorch_lightning.loggers.mlflow.MlflowClient")
def test_mlflow_logger_finalize_when_exception(*_):
Expand Down

0 comments on commit 898a236

Please sign in to comment.