-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
64 lines (49 loc) · 2.06 KB
/
cli.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
'''
copy runs across mlflow experiments
usage:
pirama [options]
options:
-m --metric=<name> name of the performance metric used to identify the best run in an experiment. ignored if a run id is provided.
-r --run=<id> run from which to read data.
-s --source=<name> name of the experiment from which to copy data. cannot be used together with -r. if used, -m is required as well.
-t --target=<name> name of the target experiment in which a new run will be created and data logged.
-h --help show this message.
'''
import logging
import sys
import docopt
import mlflow
logger = logging.getLogger('pirama')
logging.basicConfig(level=logging.INFO)
client = mlflow.tracking.MlflowClient(tracking_uri='https://mlflow.ouva.dev')
def create_run(src=None, exname:str = None):
if not exname:
raise ValueError('cannot create run without an experiment name')
logger.debug(f'creating new run in experiment {exname} starting from run {src}')
# Create a new run in the destination experiment
experiment = client.get_experiment_by_name(name=exname)
dest_run = client.create_run(experiment.experiment_id)
# Log parameters, metrics, and tags
for key, value in src.data.params.items():
client.log_param(dest_run.info.run_id, key, value)
for key, value in src.data.metrics.items():
client.log_metric(dest_run.info.run_id, key, value)
for key, value in src.data.tags.items():
client.set_tag(dest_run.info.run_id, key, value)
logger.info(f'created new run as {dest_run}')
def read_run(runid: str):
if not runid:
logger.error('run id (-r) is required to copy data from one run into another experiment. see -h for more help.')
sys.exit(1)
logger.debug(f'reading run {runid}')
run = client.get_run(runid)
logger.info(f'fetched data from run {run.info}')
return run
def main():
args = docopt.docopt(__doc__)
runid = args['--run']
run = read_run(runid)
exname = args['--target']
create_run(src=run, exname=exname)
if __name__ == '__main__':
main()