Skip to content

Commit

Permalink
Resolve model metadata for saved models that do not define an artifac…
Browse files Browse the repository at this point in the history
…t_path (mlflow#11166)

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
  • Loading branch information
harupy authored and sateeshmannar committed Feb 20, 2024
1 parent df2727b commit 872b105
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 2 additions & 4 deletions mlflow/models/model.py
Expand Up @@ -285,10 +285,8 @@ def __init__(
**kwargs,
):
# store model id instead of run_id and path to avoid confusion when model gets exported
if run_id:
self.run_id = run_id
self.artifact_path = artifact_path

self.run_id = run_id
self.artifact_path = artifact_path
self.utc_time_created = str(utc_time_created or datetime.utcnow())
self.flavors = flavors if flavors is not None else {}
self.signature = signature
Expand Down
7 changes: 7 additions & 0 deletions tests/models/test_model.py
Expand Up @@ -479,3 +479,10 @@ def predict(self, context, model_input, params=None):
assert loaded_model.saved_input_example_info["type"] == "json_object"
loaded_example = loaded_model.load_input_example(local_path)
assert loaded_example == input_example


def test_model_saved_by_save_model_can_be_loaded(tmp_path, sklearn_knn_model):
mlflow.sklearn.save_model(sklearn_knn_model, tmp_path)
info = Model.load(tmp_path).get_model_info()
assert info.run_id is None
assert info.artifact_path is None

0 comments on commit 872b105

Please sign in to comment.