1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-11 06:46:56 +08:00

Add file lock for MLflowExpManager (#619)

This commit is contained in:
you-n-g
2021-09-26 16:21:15 +08:00
committed by GitHub
parent 17d472cf01
commit 45ea4bae4e
2 changed files with 10 additions and 0 deletions

View File

@@ -1,7 +1,9 @@
# Copyright (c) Microsoft Corporation. # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License. # Licensed under the MIT License.
from urllib.parse import urlparse
import mlflow import mlflow
from filelock import FileLock
from mlflow.exceptions import MlflowException from mlflow.exceptions import MlflowException
from mlflow.entities import ViewType from mlflow.entities import ViewType
import os, logging import os, logging
@@ -191,6 +193,13 @@ class ExpManager:
if experiment_name is None: if experiment_name is None:
experiment_name = self._default_exp_name experiment_name = self._default_exp_name
logger.warning(f"No valid experiment found. Create a new experiment with name {experiment_name}.") logger.warning(f"No valid experiment found. Create a new experiment with name {experiment_name}.")
# NOTE: mlflow doesn't consider the lock for recording multiple runs
# So we supported it in the interface wrapper
pr = urlparse(self.uri)
if pr.scheme == "file":
with FileLock(os.path.join(pr.netloc, pr.path, "filelock")) as f:
return self.create_exp(experiment_name), True
return self.create_exp(experiment_name), True return self.create_exp(experiment_name), True
def _get_exp(self, experiment_id=None, experiment_name=None) -> Experiment: def _get_exp(self, experiment_id=None, experiment_name=None) -> Experiment:

View File

@@ -58,6 +58,7 @@ REQUIRED = [
"pymongo==3.7.2", # For task management "pymongo==3.7.2", # For task management
"scikit-learn>=0.22", "scikit-learn>=0.22",
"dill", "dill",
"filelock",
] ]
# Numpy include # Numpy include