Skip to content

Commit 46ce9ec

Browse files
author
amesar
committed
Issue #43: implemented export/import of 'new' Run.inputs
1 parent 4768758 commit 46ce9ec

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

mlflow_export_import/run/export_run.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def export_run(
6767
"info": info,
6868
"params": run.data.params,
6969
"metrics": _get_metrics_with_steps(mlflow_client, run),
70-
"tags": tags
70+
"tags": tags,
71+
"inputs": _inputs_to_dict(run.inputs)
7172
}
7273
io_utils.write_export_file(output_dir, "run.json", __file__, mlflow_attr)
7374
fs = _filesystem.get_filesystem(".")
@@ -130,6 +131,15 @@ def _export_notebook(dbx_client, output_dir, notebook, notebook_formats, run, fs
130131
download_notebook(notebook_dir, notebook, revision_id, notebook_formats, dbx_client)
131132

132133

134+
def _inputs_to_dict(inputs):
135+
def to_dict(ds):
136+
return {
137+
"dataset": utils.strip_underscores(ds.dataset),
138+
"tags": [ utils.strip_underscores(tag) for tag in ds.tags ]
139+
}
140+
return [ to_dict(x) for x in inputs.dataset_inputs ]
141+
142+
133143
@click.command()
134144
@opt_run_id
135145
@opt_output_dir

mlflow_export_import/run/import_run.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from mlflow_export_import.common.filesystem import mk_local_path
2323
from mlflow_export_import.common import filesystem as _filesystem
2424
from mlflow_export_import.common import MlflowExportImportException
25-
from mlflow_export_import.client.http_client import create_dbx_client
25+
from mlflow_export_import.client.http_client import create_dbx_client, create_http_client
2626
from . import run_data_importer
2727
from . import run_utils
2828

@@ -61,6 +61,7 @@ def _mk_ex(src_run_dct, dst_run_id, exp_name):
6161
}
6262

6363
mlflow_client = mlflow_client or mlflow.MlflowClient()
64+
http_client = create_http_client(mlflow_client)
6465
dbx_client = create_dbx_client(mlflow_client)
6566

6667
_logger.info(f"Importing run from '{input_dir}'")
@@ -69,7 +70,6 @@ def _mk_ex(src_run_dct, dst_run_id, exp_name):
6970
src_run_path = os.path.join(input_dir, "run.json")
7071
src_run_dct = io_utils.read_file_mlflow(src_run_path)
7172
in_databricks = "DATABRICKS_RUNTIME_VERSION" in os.environ
72-
#_logger.debug(f"in_databricks: {in_databricks}")
7373

7474
run = mlflow_client.create_run(exp.experiment_id)
7575
run_id = run.info.run_id
@@ -83,6 +83,8 @@ def _mk_ex(src_run_dct, dst_run_id, exp_name):
8383
use_src_user_id,
8484
in_databricks
8585
)
86+
_import_inputs(http_client, src_run_dct, run_id)
87+
8688
path = os.path.join(input_dir, "artifacts")
8789
if os.path.exists(_filesystem.mk_local_path(path)):
8890
mlflow_client.log_artifacts(run_id, mk_local_path(path))
@@ -141,6 +143,12 @@ def _upload_databricks_notebook(dbx_client, input_dir, src_run_dct, dst_notebook
141143
_logger.warning(f"Cannot save notebook '{dst_notebook_path}'. {e}")
142144

143145

146+
def _import_inputs(http_client, src_run_dct, run_id):
147+
inputs = src_run_dct.get("inputs")
148+
dct = { "run_id": run_id, "datasets": inputs }
149+
http_client.post("runs/log-inputs", dct)
150+
151+
144152
@click.command()
145153
@opt_input_dir
146154
@opt_experiment_name

0 commit comments

Comments
 (0)