Skip to content

Commit

Permalink
Fallback to module available check for mlflow (#17467)
Browse files Browse the repository at this point in the history
(cherry picked from commit b0af0ee)
  • Loading branch information
carmocca authored and Borda committed Jun 1, 2023
1 parent 88be8cb commit da3a102
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/lightning/pytorch/loggers/mlflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from typing import Any, Dict, List, Literal, Mapping, Optional, Union

import yaml
from lightning_utilities.core.imports import RequirementCache
from lightning_utilities.core.imports import module_available, RequirementCache
from torch import Tensor

from lightning.fabric.utilities.logger import _add_prefix, _convert_params, _flatten_dict
Expand All @@ -36,9 +36,8 @@

log = logging.getLogger(__name__)
LOCAL_FILE_URI_PREFIX = "file:"
_MLFLOW_FULL_AVAILABLE = RequirementCache("mlflow>=1.0.0")
_MLFLOW_SKINNY_AVAILABLE = RequirementCache("mlflow-skinny>=1.0.0")
_MLFLOW_AVAILABLE = _MLFLOW_FULL_AVAILABLE or _MLFLOW_SKINNY_AVAILABLE
_MLFLOW_AVAILABLE = RequirementCache("mlflow>=1.0.0") or module_available("mlflow")

if _MLFLOW_AVAILABLE:
from mlflow.entities import Metric, Param
from mlflow.tracking import context, MlflowClient
Expand Down Expand Up @@ -149,9 +148,7 @@ def __init__(
run_id: Optional[str] = None,
):
if not _MLFLOW_AVAILABLE:
raise ModuleNotFoundError(
f"{_MLFLOW_FULL_AVAILABLE!s}. You can also try {_MLFLOW_SKINNY_AVAILABLE.requirement!r}"
)
raise ModuleNotFoundError(str(_MLFLOW_AVAILABLE))
super().__init__()
if not tracking_uri:
tracking_uri = f"{LOCAL_FILE_URI_PREFIX}{save_dir}"
Expand Down

0 comments on commit da3a102

Please sign in to comment.