-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_artifacts_uri.py
executable file
·72 lines (56 loc) · 2.83 KB
/
update_artifacts_uri.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
"""
Script to update Artifacts Tracking URI for MLFlow.
This script intended purpose is to take a local run (logged in a directory via
MLFlow) and update the URIs of the Artifact locations. This is useful when, for
example, the training/evaluation scripts were run on a remote server, but the
only way to access the MLFlow UI is moving that results to a local environment.
Argumentation Mining Transformers Module Training Script
Copyright (C) 2024 Cristian Cardellino
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import argparse
import logging
import yaml
from mlflow import MlflowClient
from pathlib import Path
from tqdm.auto import tqdm
logger = logging.getLogger(__name__)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--mlflow-uri",
required=True,
type=Path,
help="Path to the directory where the MLFlow experiments are.",
)
args = parser.parse_args()
mlflow_uri = args.mlflow_uri # type: Path
logger.info("Loading MLFlow client.")
client = MlflowClient(mlflow_uri.absolute().as_uri())
logger.info("Updating experiments artifacts locations and URIs.")
for experiment in tqdm(client.search_experiments()):
experiment_meta_file = mlflow_uri / experiment.experiment_id / "meta.yaml"
with open(experiment_meta_file, "rt") as fh:
meta = yaml.load(fh, Loader=yaml.SafeLoader)
new_artifact_location = mlflow_uri / experiment.experiment_id
meta["artifact_location"] = new_artifact_location.absolute().as_uri()
with open(experiment_meta_file, "wt") as fh:
yaml.dump(meta, fh, Dumper=yaml.SafeDumper)
for run in client.search_runs(experiment.experiment_id):
run_meta_file = mlflow_uri / experiment.experiment_id / run.info.run_id / "meta.yaml"
with open(run_meta_file, "rt") as fh:
meta = yaml.load(fh, Loader=yaml.SafeLoader)
new_artifact_uri = mlflow_uri / experiment.experiment_id / run.info.run_id / "artifacts"
meta["artifact_uri"] = new_artifact_uri.absolute().as_uri()
with open(run_meta_file, "wt") as fh:
yaml.dump(meta, fh, Dumper=yaml.SafeDumper)