Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow log to an existing run ID in MLflow with MLFlowLogger #12290

Merged
merged 22 commits into from Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6719acb
specify mlflow exception type for mlflow get_run call
Kr4is Mar 9, 2022
7a6cf0f
Merge branch 'PyTorchLightning:master' into master
Kr4is Mar 10, 2022
0a52a8a
update changelog
Kr4is Mar 10, 2022
9d75176
place run_id parameter at constructor end
Kr4is Mar 11, 2022
e98c390
move changelog description from changed to added
Kr4is Mar 11, 2022
c050e86
Update CHANGELOG.md
Kr4is Mar 12, 2022
28d606d
set existing run experiment_id if run_if already exists
Kr4is Mar 12, 2022
bd11951
add mlflow logger tests
Kr4is Mar 12, 2022
c6aa700
Merge branch 'PyTorchLightning:master' into master
Kr4is Mar 12, 2022
e43e6c3
Merge branch 'PyTorchLightning:master' into master
Kr4is Mar 18, 2022
df7e23e
solve logger initialization and tests
Kr4is Mar 18, 2022
e73d60e
Merge branch 'PyTorchLightning:master' into master
Kr4is Mar 18, 2022
c22e564
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 18, 2022
2500173
remove comment
Kr4is Mar 18, 2022
075099d
Merge branch 'PyTorchLightning:master' into master
Kr4is Mar 19, 2022
319db6f
Merge branch 'PyTorchLightning:master' into master
Kr4is Mar 21, 2022
83c5304
move run_id to the end documentation args
Kr4is Mar 23, 2022
606f8a9
Merge branch 'PyTorchLightning:master' into master
Kr4is Mar 23, 2022
2b517a3
Merge branch 'PyTorchLightning:master' into master
Kr4is Mar 24, 2022
be67516
Merge branch 'PyTorchLightning:master' into master
Kr4is Mar 25, 2022
9c76ad3
Merge branch 'PyTorchLightning:master' into master
Kr4is Mar 26, 2022
260d735
Merge branch 'PyTorchLightning:master' into master
Kr4is Mar 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -151,6 +151,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Changed

- Allow log to an existing run ID in MLflow with `MLFlowLogger` ([#12290](https://github.com/PyTorchLightning/pytorch-lightning/pull/12290))
ananthsub marked this conversation as resolved.
Show resolved Hide resolved

- Drop PyTorch 1.7 support ([#12191](https://github.com/PyTorchLightning/pytorch-lightning/pull/12191))


Expand Down
15 changes: 13 additions & 2 deletions pytorch_lightning/loggers/mlflow.py
Expand Up @@ -87,7 +87,8 @@ def any_lightning_module_function_or_hook(self):
self.logger.experiment.whatever_ml_flow_supports(...)

Args:
experiment_name: The name of the experiment
run_id: The run identifier of the experiment. If not provided, a new run is started.
rohitgr7 marked this conversation as resolved.
Show resolved Hide resolved
experiment_name: The name of the experiment.
run_name: Name of the new run. The `run_name` is internally stored as a ``mlflow.runName`` tag.
If the ``mlflow.runName`` tag has already been set in `tags`, the value is overridden by the `run_name`.
tracking_uri: Address of local or remote tracking server.
Expand All @@ -110,6 +111,7 @@ def any_lightning_module_function_or_hook(self):

def __init__(
self,
run_id: Optional[str] = None,
ananthsub marked this conversation as resolved.
Show resolved Hide resolved
experiment_name: str = "lightning_logs",
run_name: Optional[str] = None,
tracking_uri: Optional[str] = os.getenv("MLFLOW_TRACKING_URI"),
Expand All @@ -130,7 +132,7 @@ def __init__(
self._experiment_id = None
self._tracking_uri = tracking_uri
self._run_name = run_name
self._run_id = None
self._run_id = run_id
self.tags = tags
self._prefix = prefix
self._artifact_location = artifact_location
Expand All @@ -149,6 +151,15 @@ def experiment(self) -> MlflowClient:
self.logger.experiment.some_mlflow_function()

"""

if self._run_id:
try:
self._mlflow_client.get_run(self._run_id)
return self._mlflow_client
except mlflow.exceptions.MlflowException:
awaelchli marked this conversation as resolved.
Show resolved Hide resolved
log.warning(f"Run id with name {self._run_id} not found. Creating a new one.")
self._run_id = None

if self._experiment_id is None:
expt = self._mlflow_client.get_experiment_by_name(self._experiment_name)
if expt is not None:
Expand Down