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

Resolve model metadata for saved models that do not define an artifact_path #11166

Merged
merged 3 commits into from Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Comment on lines +288 to +289
Copy link
Member Author

@harupy harupy Feb 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine to always set these attributes.

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