Manage Models
This page describes how to create and view models, manage model versions, and delete models using the H2O MLOps Python client.
To learn more about models, see Understand models.
Prerequisites
Before you begin,
- Connect to H2O MLOps. For instructions, see Connect to H2O MLOps.
- Create a workspace. For instructions, see Create a workspace.
- Create an experiment. For instructions, see Create an experiment.
Create a model
Create a model within the workspace using the create()
method by specifying the model name and the description.
model = workspace.models.create(name="my-model", description="My Model")
The name of the model must be unique within the workspace.
View models
Count models
Get the total number of models in a workspace:
Input:
workspace.models.count()
Output:
1
List models
List all models in a workspace:
Input:
models = workspace.models.list()
models
Output:
| name | uid
---+----------+--------------------------------------
0 | my-model | 27965199-6f0f-4cbe-bf48-e59b05fa1f04
-
The output of
list()
method is displayed in a neatly formatted view. By default, only the first 50 rows are displayed to keep the output concise and manageable. -
Calling
len(models)
returns the total number of rows it contains, not just the number currently displayed. -
To customize the number of rows displayed, you can call the
show()
method with then
argument. This allows more rows to be shown when needed. For example:models.show(n=100)
This will display up to 100 models.
-
The
models
can be iterated over, as it is designed to behave like an iterator.
Filter models
Use the list()
method with key-value arguments to filter the models.
Input:
workspace.models.list(name="my-model")
This returns a list of matching models as a table.
Output:
| name | uid
---+----------+--------------------------------------
0 | my-model | 27965199-6f0f-4cbe-bf48-e59b05fa1f04
Retrieve a model
Retrieve a model by UID:
model = workspace.models.get(uid="d9a47c99-c66c-4ff9-b2b6-30faf5f413ef")
Retrieve a model by model name:
Input:
model = workspace.models.get(name="my-model")
model
Output:
<class 'h2o_mlops._models.MLOpsModel(
uid='27965199-6f0f-4cbe-bf48-e59b05fa1f04',
name='my-model',
description='My Model',
creator_uid='4c4eb198-bcbc-4442-91f6-a27deb53e9c1',
created_time=datetime.datetime(2025, 6, 3, 15, 33, 10, 882595, tzinfo=tzutc()),
last_modified_time=datetime.datetime(2025, 6, 3, 15, 33, 10, 882595, tzinfo=tzutc()),
)'>
You can also retrieve a model from the list returned by list()
using indexing.
For example, model = workspace.models.list(key=value)[index]
. The key
and value
arguments are optional.
Model properties
A model has the following main properties:
uid
: The unique identifier for the model.name
: The name of the model.description
: A description of the model.creator
: The user who created the model.created_time
: The timestamp when the model was created.last_modified_time
: The timestamp of the last modification.last_modified_by
: The user who last modified the model.version_count
: The number of versions of the model.
Update a model
You can update only the name
and description
fields of a model.
Make sure to retrieve the model instance before updating it. See Retrieve a model.
Input:
model.update(name="new-my-model", description="New My Model")
model
Output:
<class 'h2o_mlops._models.MLOpsModel(
uid='27965199-6f0f-4cbe-bf48-e59b05fa1f04',
name='new-my-model',
description='New My Model',
creator_uid='4c4eb198-bcbc-4442-91f6-a27deb53e9c1',
created_time=datetime.datetime(2025, 6, 3, 15, 33, 10, 882595, tzinfo=tzutc()),
last_modified_time=datetime.datetime(2025, 6, 3, 15, 33, 32, 502773, tzinfo=tzutc()),
)'>
Manage model versions
Register an experiment with a model
To create a new version of a model, register an experiment with it.
Use the following code:
model.register(experiment=experiment)
You can also register an experiment using the following alternative methods:
-
Register an experiment with an existing model using artifact data. No need for an
MLOpsExperiment
instance. This method creates and registers the experiment with the model.Example:
model.register(experiment="/path/experiment.zip", name="experiment-name")
-
Register an experiment and create a new model directly using artifact data. No need for
MLOpsModel
orMLOpsExperiment
instances. This method creates both the model and the experiment, then registers the experiment with the model.Example:
model = workspace.models.register(experiment="/path/experiment.zip", name="experiment-and-model-name",)
To verify that the experiment is registered with the model, run the following code:
Input:
experiment.registered_model
This returns a tuple containing the associated MLOpsModel
instance and the model version the experiment was registered to.
Output:
(<class 'h2o_mlops._models.MLOpsModel(
uid='27965199-6f0f-4cbe-bf48-e59b05fa1f04',
name='new-my-model',
description='New My Model',
creator_uid='4c4eb198-bcbc-4442-91f6-a27deb53e9c1',
created_time=datetime.datetime(2025, 6, 3, 15, 33, 10, 882595, tzinfo=tzutc()),
last_modified_time=datetime.datetime(2025, 6, 3, 15, 33, 40, 578744, tzinfo=tzutc()),
)'>,1)
List model versions
List all versions of a model:
Input:
model.versions()
Output:
| version | experiment_uid
---+-----------+--------------------------------------
0 | 1 | bdf42b57-c3de-4f33-8c37-f19a9f5f765d
Filter model versions
Use the versions()
method with key-value arguments to filter the model versions.
Input:
model.versions(version=1)
This returns a list of matching model versions as a table.
Output:
| version | experiment_uid
---+-----------+--------------------------------------
0 | 1 | bdf42b57-c3de-4f33-8c37-f19a9f5f765d
Retrieve a model version
You can retrieve a specific version of a model from the list returned by versions()
using indexing.
For example, version = model.versions(key=value)[index]
. The key
and value
arguments are optional.
Input:
model.versions(version=1)[0]
Output:
MLOpsModelVersion(
uid='7fb119cf-aaaa-42e2-985c-e71a84e6396a',
version=1,
model_uid='27965199-6f0f-4cbe-bf48-e59b05fa1f04'
experiment_uid='bdf42b57-c3de-4f33-8c37-f19a9f5f765d',
creator_uid='4c4eb198-bcbc-4442-91f6-a27deb53e9c1',
created_time='2025-06-03 03:33:40 PM',
last_modified_time='2025-06-03 03:33:40 PM',
last_modified_by='4c4eb198-bcbc-4442-91f6-a27deb53e9c1',
state='ACTIVE'
)
Retrieve the experiment
Get the experiment associated with a model version:
Input:
model.experiment(model_version=1)
If nothing is specified for the model_version
, the default value "latest"
is used.
Output:
<class 'h2o_mlops._experiments.MLOpsExperiment(
uid='bdf42b57-c3de-4f33-8c37-f19a9f5f765d',
name='H2O3 MOJO experiment',
description='GLM - Regression',
is_registered=True,
owner_username='test.user@test.com',
created_time=datetime.datetime(2025, 6, 3, 15, 33, 8, 159914, tzinfo=tzutc()),
last_modified_time=datetime.datetime(2025, 6, 3, 15, 33, 8, 159914, tzinfo=tzutc())
)'>
Unregister an experiment from a model
To remove an experiment from a model, run:
model.unregister(experiment=experiment)
After unregistering the experiment, list the available model versions to verify the change:
Input:
model.versions()
Output:
| version | experiment_uid
---+-----------+------------------
The model version created during registration is removed.
To unregister all the models, use:
model.unregister(unregister_all=True)
Delete models
This section describes two ways to delete models.
Deleting a model also deletes all of its associated versions. This action is irreversible.
Delete using a model instance
If you already have a reference to the model
object, use the delete()
method:
model.delete()
Delete using model UIDs
You can delete multiple models at once by specifying their UIDs.
Input:
workspace.models.delete(uids=["c62ced74-905a-4f06-856d-33b9f5725901"])
You can also pass a list of MLOpsModel
instances or a _utils.Table
containing models. For example: workspace.models.delete(models=[model])
.
Output:
| model_uid | is_deleted | message
---+--------------------------------------+--------------+-----------
0 | c62ced74-905a-4f06-856d-33b9f5725901 | True |
- Submit and view feedback for this page
- Send feedback about H2O MLOps to cloud-feedback@h2o.ai