forked from mlflow/mlflow-export-import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Import_Run.py
77 lines (51 loc) · 1.94 KB
/
Import_Run.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
73
74
75
76
77
# Databricks notebook source
# MAGIC %md ## Import Run
# MAGIC
# MAGIC Import run from the folder that was created by the [Export_Run]($Export_Run) notebook.
# MAGIC
# MAGIC #### Widgets
# MAGIC * `1. Destination experiment name` - Import run into this experiment. Will create if it doesn't exist.
# MAGIC * `2. Input directory` - Input directory containing an exported run.
# MAGIC * `3. Import source tags`
# COMMAND ----------
# MAGIC %md ### Include setup
# COMMAND ----------
# MAGIC %run ./Common
# COMMAND ----------
# MAGIC %md ### Widget setup
# COMMAND ----------
dbutils.widgets.text("1. Destination experiment name", "")
experiment_name = dbutils.widgets.get("1. Destination experiment name")
dbutils.widgets.text("2. Input directory", "")
input_dir = dbutils.widgets.get("2. Input directory")
dbutils.widgets.dropdown("3. Import source tags","no",["yes","no"])
import_source_tags = dbutils.widgets.get("3. Import source tags") == "yes"
print("input_dir:", input_dir)
print("experiment_name:", experiment_name)
print("import_source_tags:", import_source_tags)
# COMMAND ----------
assert_widget(experiment_name, "1. Destination experiment name")
assert_widget(input_dir, "2. Input base directory")
# COMMAND ----------
# MAGIC %md ### Import Run
# COMMAND ----------
from mlflow_export_import.run.import_run import import_run
run, _ = import_run(
experiment_name = experiment_name,
input_dir = input_dir,
import_source_tags = import_source_tags
)
print("Run ID:", run.info.run_id)
# COMMAND ----------
# MAGIC %md ### Display run UI link
# COMMAND ----------
display_run_uri(run.info.run_id)
# COMMAND ----------
# MAGIC %md ### Check imported source tags
# COMMAND ----------
if import_source_tags:
import pandas as pd
run = mlflow_client.get_run(run.info.run_id)
data = [ (k, v) for k,v in run.data.tags.items() if k.startswith("mlflow_exim") ]
df = pd.DataFrame(data, columns = ["Key","Value"])
display(df)