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
Only generate model uuid when logging model #5167
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -85,6 +85,16 @@ def model_path(tmpdir): | |||||||
return os.path.join(str(tmpdir), "model") | ||||||||
|
||||||||
|
||||||||
def _is_valid_uuid(val): | ||||||||
import uuid | ||||||||
|
||||||||
try: | ||||||||
uuid.UUID(str(val)) | ||||||||
return True | ||||||||
except ValueError: | ||||||||
return False | ||||||||
|
||||||||
|
||||||||
@pytest.mark.large | ||||||||
def test_model_save_load(sklearn_knn_model, iris_data, tmpdir, model_path): | ||||||||
sk_model_path = os.path.join(str(tmpdir), "knn.pkl") | ||||||||
|
@@ -102,13 +112,17 @@ def test_model_save_load(sklearn_knn_model, iris_data, tmpdir, model_path): | |||||||
|
||||||||
reloaded_model_config = Model.load(os.path.join(model_path, "MLmodel")) | ||||||||
assert model_config.__dict__ == reloaded_model_config.__dict__ | ||||||||
assert model_config.model_uuid is not None and _is_valid_uuid(model_config) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
assert mlflow.pyfunc.FLAVOR_NAME in reloaded_model_config.flavors | ||||||||
assert mlflow.pyfunc.PY_VERSION in reloaded_model_config.flavors[mlflow.pyfunc.FLAVOR_NAME] | ||||||||
reloaded_model = mlflow.pyfunc.load_pyfunc(model_path) | ||||||||
np.testing.assert_array_equal( | ||||||||
sklearn_knn_model.predict(iris_data[0]), reloaded_model.predict(iris_data[0]) | ||||||||
) | ||||||||
|
||||||||
reloaded_model_config2 = Model.load(os.path.join(model_path, "MLmodel")) | ||||||||
assert reloaded_model_config.model_uuid == reloaded_model_config2.model_uuid | ||||||||
|
||||||||
|
||||||||
@pytest.mark.large | ||||||||
def test_signature_and_examples_are_saved_correctly(sklearn_knn_model, iris_data): | ||||||||
|
@@ -556,26 +570,6 @@ def test_column_schema_enforcement_no_col_names(): | |||||||
assert pyfunc_model.predict(d).equals(pd.DataFrame(d)) | ||||||||
|
||||||||
|
||||||||
def _is_valid_uuid(val): | ||||||||
import uuid | ||||||||
|
||||||||
try: | ||||||||
uuid.UUID(str(val)) | ||||||||
return True | ||||||||
except ValueError: | ||||||||
return False | ||||||||
|
||||||||
|
||||||||
def test_model_uuid(): | ||||||||
m = Model() | ||||||||
assert m.model_uuid is not None | ||||||||
assert _is_valid_uuid(m.model_uuid) | ||||||||
m_dict = m.to_dict() | ||||||||
assert m_dict["model_uuid"] == m.model_uuid | ||||||||
m2 = Model.from_dict(m_dict) | ||||||||
assert m2.model_uuid == m.model_uuid | ||||||||
|
||||||||
|
||||||||
def test_tensor_schema_enforcement_no_col_names(): | ||||||||
m = Model() | ||||||||
input_schema = Schema([TensorSpec(np.dtype(np.float32), (-1, 3))]) | ||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not set uuid here. Otherwise there're many other place we need also set uuid.
e.g.
mlflow/mlflow/pyfunc/__init__.py
Line 1072 in f9b5745
mlflow/mlflow/catboost.py
Line 122 in f9b5745
etc.
I move the set uuid code into Model constructor again.