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

added snippets for Connection, Model Registry #160

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rktraz
Copy link

@rktraz rktraz commented Nov 14, 2022

No description provided.

Copy link

@jimdowling jimdowling left a comment

Choose a reason for hiding this comment

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

I think Javier should review this.

docs/index.md Outdated

HSML is the library to interact with the Hopsworks Model Registry and Model Serving. The library makes it easy to export, manage and deploy models.

The library automatically configures itself based on the environment it is run.

Choose a reason for hiding this comment

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

This sentence doesn't mean anything.
configures itself how?
Technically, it should be
"The library automatically configures itself based on the environment it is run in."
Do you mean?
The library automatically configures itself based on the environment it is run in, either Python or Spark.
If you mean - it configures itself based on whether it is run inside Hopsworks or outside Hopsworks - in this case, just remove the sentence. Users will expect it should work inside/outside Hopsworks. We shouldn't need to tell them.

docs/index.md Outdated
HSML is the library to interact with the Hopsworks Model Registry and Model Serving. The library makes it easy to export, manage and deploy models.

The library automatically configures itself based on the environment it is run.
However, to connect from an external Python environment additional connection information, such as host and port, is required. For more information about the setup from external environments, see the setup section.

Choose a reason for hiding this comment

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

If you connect to Hopsworks from an external Python environment to your own managed Hopsworks cluster, you need to provide additional connection information - the Hopsworks hostname (or IP address) and port (if it is not port 443).

import hsml

# Create a connection
connection = hsml.connection()

Choose a reason for hiding this comment

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

put the hostname and project in the example here:

connection = hsml.connection(host="my.cluster.com", project="fraud")

docs/index.md Outdated
version=1,
metrics={"accuracy": 0.94},
description="mnist model description")
model.save("/tmp/model_directory") # or /tmp/model_file

Choose a reason for hiding this comment

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

Add a line of code before this where you export the tensorflow model to the local directory:
"/tmp/model_directory"

Otherwise this code snippet doesn't actually upload a tensorflow model

docs/index.md Show resolved Hide resolved
@rktraz rktraz requested review from jimdowling and removed request for javierdlrm and davitbzh November 16, 2022 17:05
@jimdowling jimdowling requested a review from javierdlrm December 9, 2022 11:35
@@ -119,6 +119,12 @@ def get_model_registry(self, project: str = None):
"""Get a reference to a model registry to perform operations on, defaulting to the project's default model registry.
Shared model registries can be retrieved by passing the `project` argument.

!!! example
```python
mr = conn.get_model_registry() # Get the project's default model registry
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
mr = conn.get_model_registry() # Get the project's default model registry
mr = conn.get_model_registry()


!!! example
```python
model.save('model.pkl')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
model.save('model.pkl')
model.save('model.pkl') # save a single model file, or
model.save('path/to/model_directory') # save a model with multiple files

Comment on lines 115 to 119
# get model object
model = mr.get_model("citibike_mlp_model", version=1)

# delete this model version
model.delete()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# get model object
model = mr.get_model("citibike_mlp_model", version=1)
# delete this model version
model.delete()
# get model object of a specific version
model = mr.get_model("mnist", version=1)
# delete the model version
model.delete()

@@ -94,6 +108,11 @@ def get_models(self, name: str):
Getting all models from the Model Registry for a given name returns a list of model entities, one for each version registered under
the specified model name.

!!! example
```python
models = mr.get_models("churnmodel")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
models = mr.get_models("churnmodel")
models = mr.get_models("mnist")

SORT_METRICS_BY = "max" # your sorting criteria

# get best model based on custom metrics
best_model = mr.get_best_model("citibike_mlp_model",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
best_model = mr.get_best_model("citibike_mlp_model",
best_model = mr.get_best_model("mnist",

Comment on lines 40 to 45
model = mr.tensorflow.create_model(
name="bitcoin_price_model",
metrics=metrics,
description="bitcoin daily price detection model.",
input_example=[1613512800000]
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
model = mr.tensorflow.create_model(
name="bitcoin_price_model",
metrics=metrics,
description="bitcoin daily price detection model.",
input_example=[1613512800000]
)
model = mr.tensorflow.create_model(
name="mnist_classifier",
metrics=metrics,
model_schema=model_schema,
input_example=input_example,
description="MNIST Classifier"
)

Comment on lines 40 to 45
model = mr.torch.create_model(
name="electricity_price_prediction_model",
metrics=metrics,
description="Daily electricity price prediction model.",
input_example=n_step_window.example[0].numpy()
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
model = mr.torch.create_model(
name="electricity_price_prediction_model",
metrics=metrics,
description="Daily electricity price prediction model.",
input_example=n_step_window.example[0].numpy()
)
model = mr.torch.create_model(
name="mnist_classifier",
metrics=metrics,
model_schema=model_schema,
input_example=input_example,
description="MNIST Classifier"
)


HSML is the library to interact with the Hopsworks Model Registry and Model Serving. The library makes it easy to export, manage and deploy models.

However, to connect from an external Python environment additional connection information, such as the Hopsworks hostname (or IP address) and port (if it is not port 443), is required. For more information about the setup from external environments, see the setup section.
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 we can keep the first sentence as

Suggested change
However, to connect from an external Python environment additional connection information, such as the Hopsworks hostname (or IP address) and port (if it is not port 443), is required. For more information about the setup from external environments, see the setup section.
The library automatically configures itself based on the environment it is run. However, to connect from an external Python environment additional connection information, such as the Hopsworks hostname (or IP address) and port (if it is not port 443), is required. For more information about the setup from external environments, see the setup section.

docs/index.md Outdated
import hsml

# Create a connection
connection = hsml.connection(host="my.cluster.com", project="fraud")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
connection = hsml.connection(host="my.cluster.com", project="fraud")
connection = hsml.connection()
# or connection = hsml.connection(host="my.hopsworks.cluster", project="my_project")

docs/index.md Outdated
Comment on lines 56 to 66
import tensorflow as tf


model = mr.tensorflow.create_model(name="mnist",
version=1,
metrics={"accuracy": 0.94},
description="mnist model description")

export_path = "/tmp/model_directory" # or "/tmp/model_file"
tf.saved_model.save(model, export_path)
model.save(export_path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
import tensorflow as tf
model = mr.tensorflow.create_model(name="mnist",
version=1,
metrics={"accuracy": 0.94},
description="mnist model description")
export_path = "/tmp/model_directory" # or "/tmp/model_file"
tf.saved_model.save(model, export_path)
model.save(export_path)
import tensorflow as tf
export_path = "/tmp/model_directory"
tf.saved_model.save(model, export_path)
model = mr.tensorflow.create_model(name="mnist",
version=1,
metrics={"accuracy": 0.94},
description="mnist model description")
model.save(export_path) # "/tmp/model_directory" or "/tmp/model_file"

@rktraz rktraz requested review from javierdlrm and removed request for jimdowling December 21, 2022 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants