Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding s3 bucket parsing for model paths #81

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mlflow_export_import/bulk/import_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _import_experiments(client, input_dir, use_src_user_id):
for exp in exps:
exp_input_dir = os.path.join(input_dir, "experiments", exp["id"])
try:
_run_info_map = importer.import_experiment( exp["name"], exp_input_dir)
_run_info_map = importer.import_experiment(f'/Shared/{exp["name"]}', exp_input_dir) # MATCHING DBX PATH
run_info_map[exp["id"]] = _run_info_map
except Exception as e:
exceptions.append(str(e))
Expand Down
12 changes: 10 additions & 2 deletions mlflow_export_import/model/import_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
import click
from urllib.parse import urlparse

import mlflow
from mlflow.exceptions import RestException
Expand Down Expand Up @@ -54,7 +55,6 @@ def _import_version(self, model_name, src_vr, dst_run_id, dst_source, sleep_time
tags = src_vr["tags"]
if self.import_source_tags:
_set_source_tags_for_field(src_vr, tags)

dst_vr = self.mlflow_client.create_model_version(
model_name,
dst_source, dst_run_id, \
Expand Down Expand Up @@ -190,7 +190,7 @@ def import_model(self, model_name, input_dir, delete_model=False, verbose=False,
for vr in model_dct["versions"]:
src_run_id = vr["run_id"]
dst_run_id = self.run_info_map[src_run_id].run_id
mlflow.set_experiment(vr["_experiment_name"])
mlflow.set_experiment(f'/Shared/{vr["_experiment_name"]}') # MATCHING DBX PATH
self.import_version(model_name, vr, dst_run_id, sleep_time)
if verbose:
model_utils.dump_model_versions(self.mlflow_client, model_name)
Expand All @@ -211,6 +211,14 @@ def _extract_model_path(source, run_id):
:param run_id: Run ID in the 'source field
:return: relative path to the model artifact
"""
if source[:5] == "s3://": # check if source is s3 bucket
# bucket name may contain 'artifacts', this bypasses the bucket name
pattern = "artifacts"
parsed_s3 = urlparse(source)
s3_path = parsed_s3.path
idx = s3_path.find(pattern)
model_path = s3_path[1+idx+len(pattern):]
return model_path
idx = source.find(run_id)
if idx == -1:
raise MlflowExportImportException(f"Cannot find run ID '{run_id}' in registered model version source field '{source}'", http_status_code=404)
Expand Down