Python client for H2O MLOps.
Project description
An H2O MLOps Python Client for Regular Folks
This project is a work in progress and the API may change. Please send questions or feedback to support@h2o.ai.
Example
import h2o_mlops
import httpx
import time
First we have to connect to MLOps. In this example the client is detecting credentials and configuration options from the environment.
mlops = h2o_mlops.Client()
Everything Starts with a Project
A project is the main base of operations for most MLOps activities.
project = mlops.projects.create(name="demo")
mlops.projects.list(name="demo")
| name | uid
----+--------+--------------------------------------
0 | demo | 45e5a888-ec1f-4f9c-85ca-817465344b1f
You can also do project = mlops.projects.get(...)
.
Upload an Experiment
experiment = project.experiments.create(
data="/Users/jgranados/Downloads/GBM_model_python_1649367037255_1.zip",
name="experiment-from-client"
)
Some experiment attributes of interest.
experiment.scoring_artifact_types
['h2o3_mojo']
experiment.uid
'e307aa9f-895f-4b07-9404-b0728d1b7f03'
Existing experiments can be viewed and retrieved.
project.experiments.list()
| name | uid | tags
----+------------------------+--------------------------------------+--------
0 | experiment-from-client | e307aa9f-895f-4b07-9404-b0728d1b7f03 |
You can also do experiment = projects.experiments.get(...)
.
Create a Model
model = project.models.create(name="model-from-client")
Existing models can be viewed and retrieved.
project.models.list()
| name | uid
----+-------------------+--------------------------------------
0 | model-from-client | d18a677f-b800-4a4b-8642-0f59e202d225
You can also do model = projects.models.get(...)
.
Register an Experiment to a Model
In order to deploy a model, it needs to have experiments registered to it.
model.register(experiment=experiment)
model.versions()
| version | experiment_uid
----+-----------+--------------------------------------
0 | 1 | e307aa9f-895f-4b07-9404-b0728d1b7f03
model.get_experiment(model_version="latest").name
'experiment-from-client'
Deployment
What is needed for a single model deployment?
- project
- model
- environment
- scoring runtime
- name for deployment
We already have a project
and model
. Let us look at how to get the environment
.
project.environments.list()
| name | uid
----+--------+--------------------------------------
0 | DEV | a6af758e-4a98-4ae2-94bf-1c84e5e5a3ed
1 | PROD | f98afa18-91f9-4a97-a031-4924018a8b8f
environment = project.environments.list(name="DEV")[0]
You can also do project.environments.get(...)
.
Next we'll get the scoring_runtime
for our model type. Notice we're using the artifact type from the experiment to filter runtimes.
mlops.runtimes.scoring.list(artifact_type=model.get_experiment().scoring_artifact_types[0])
| name | artifact_type | uid
----+-------------------+-----------------+-------------------
0 | H2O-3 MOJO scorer | h2o3_mojo | h2o3_mojo_runtime
scoring_runtime = mlops.runtimes.scoring.list(
artifact_type=model.get_experiment().scoring_artifact_types[0]
)[0]
Now we can create a deployment.
deployment = environment.deployments.create_single(
name = "deployment-from-client",
model = model,
scoring_runtime = scoring_runtime
)
while not deployment.is_healthy():
deployment.raise_for_failure()
time.sleep(5)
deployment.status()
'HEALTHY'
Score
Once you have a deployment, you can score with it through the HTTP protocol.
response = httpx.post(
url=deployment.url_for_scoring,
json=deployment.get_sample_request()
)
response.json()
{'fields': ['C11.0', 'C11.1'],
'id': 'e307aa9f-895f-4b07-9404-b0728d1b7f03',
'score': [['0.49786656666743145', '0.5021334333325685']]}
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[0.62.1a5] - 2023-12-04
Added
- Metadata property for experiments.
[0.62.1a4] - 2023-12-01
Added
- Owner attribute for deployments, experiments, models, and projects.
- Ability to view deployment Kubernetes options (including requests, limits, affinity, and toleration).
- Ability to update deployment Kubernetes options (including scaling deployment down to zero resource usage).
- Ability to view deployment security options.
- Ability to update deployment security options (including changing passphrase for existing deployments).
- Ability to enable/disable monitoring for new and existing deployments.
Changed
- "UNHEALTY" status typo corrected to "UNHEALTHY".
[0.62.1a3] - 2023-11-20
Added
- Support for experiment artifacts.
Changed
experiment.artifact_types
renamed toexperiments.scoring_artifact_types
.
Fixed
- List methods not returning over 100 entries.
[0.62.1a2] - 2023-11-13
Added
- Support for experiment comments.
- Support for experiment tags.
- Integration of https://github.com/h2oai/cloud-discovery-py.
[0.62.1a1] - 2023-10-16
Changed
- Use MLOps 0.62.1 backend.
[0.61.1a3] - 2023-07-28
Changed
MLOpsClient
class renamed toClient
._mlops_backend
attribute renamed to_backend
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file h2o_mlops-0.62.1a5-py3-none-any.whl
.
File metadata
- Download URL: h2o_mlops-0.62.1a5-py3-none-any.whl
- Upload date:
- Size: 777.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b47697c6441861658f93c7b8a85854220318a7e1b47444d3b01f54f70db5425 |
|
MD5 | 80a497612b231743a7897a19d91792dd |
|
BLAKE2b-256 | ef48ead5a0b263863b4960e4560981d9fd6ce6885dbb8c83a9fa075ea5e10aea |