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

[HWORKS-1535] Infer model schema from feature view #241

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
29 changes: 28 additions & 1 deletion python/hsml/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from typing import Any, Dict, Optional, Union

import humps
from hsml import client, util
from hsml import ModelSchema, client, util
from hsml.constants import ARTIFACT_VERSION
from hsml.constants import INFERENCE_ENDPOINTS as IE
from hsml.core import explicit_provenance
Expand Down Expand Up @@ -109,6 +109,20 @@ def __init__(
util.ProvenanceWarning,
stacklevel=1,
)
if self._model_schema is None:
if self._feature_view is None or self._training_dataset_version is None:
warnings.warn(
"Model schema can only be inferred if both a feature view and training dataset version are known",
util.ProvenanceWarning,
stacklevel=1,
)
Comment on lines +114 to +118
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if this warning is useful for users. Do you think the following is clearer?
Model schema could not be inferred without feature view and training dataset version.

The method executes in any case. We just inform whether the model schema could not be inferred given the parameters.

else:
features, labels = self._feature_view.get_training_data(
training_dataset_version=self._training_dataset_version
)
self._model_schema = ModelSchema(
input_schema=features, output_schema=labels
)

def save(
self,
Expand All @@ -133,6 +147,19 @@ def save(
# Returns
`Model`: The model metadata object.
"""

if self._model_schema is None:
if (
self._feature_view is not None
and self._training_dataset_version is not None
):
features, labels = self._feature_view.get_training_data(
training_dataset_version=self._training_dataset_version
)
self._model_schema = ModelSchema(
input_schema=features, output_schema=labels
)
Comment on lines +151 to +161
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that having this in the constructor is enough, no need to retry it here.


return self._model_engine.save(
model_instance=self,
model_path=model_path,
Expand Down
Loading