Delete registered model
This page describes how to delete or batch delete registered models using the H2O MLOps Python client.
Constants​
The following constants are used in the provided sample script:
MLOPS_API_URL
: The URL endpoint for the MLOps Gateway component. You can verify the correct URL by navigating to the API URL in your browser. It should provide a page with a list of available routes.TOKEN_ENDPOINT_URL
: Defines the token endpoint URL of the Identity Provider. This uses Keycloak as the Identity Provider. Keycloak Realm should be provided.REFRESH_TOKEN
: The user's refresh token for authentication.CLIENT_ID
: The client ID for authentication.PROJECT_NAME
: The name of the project where the target experiment is located.REGISTERED_MODEL_NAME
: The name of the registered model that you want to delete.
Batch deletion-specific constants​
PROJECT_NAMES
: List containing the names of projects where the experiments are present. For example,["project01", "project02"]
REGISTERED_MODEL_NAMES
: List of registered model names that you want to delete.
Functions​
_get_project_id(projects)
: Returns the ID of the specified project._get_registered_model_id(models)
: Returns the ID of the registered model specified inREGISTERED_MODEL_NAME
.
Workflow​
- Initialize the token provider using the provided refresh token.
- Set up the H2O MLOps client with the gateway URL and token provider.
- List all projects for the user.
- Using the
_get_project_id(projects)
function, identify and fetch the ID of the project specified inPROJECT_NAME
. - For the identified project, list all registered models.
- Using the
_get_registered_model_id(models) function
, identify and fetch the ID of the registered model specified inREGISTERED_MODEL_NAME
. - Delete the registered model using the fetched model ID.
Sample script: Delete registered model​
# List MLOps Projects for the user.
prj: mlops.StorageProject
projects: mlops.StorageListProjectsResponse = mlops_client.storage.project.list_projects(
mlops.StorageListProjectsRequest()
)
try:
prj = _get_project_id(projects.project)
except LookupError:
# Error if a project is not found.
raise ValueError("There is no project with the given name.")
models: mlops.StorageListRegisteredModelsResponse = mlops_client.storage.registered_model.list_registered_models(
mlops.StorageListRegisteredModelsRequest(project_id=prj.id)
)
# Get the ID for the Registered Model.
model: mlops.StorageRegisteredModel
try:
model = _get_registered_model_id(models.registered_models)
except:
raise ValueError("Registered model not found in the project.")
# Delete the Registered Model.
deleted_registered_model: mlops.StorageDeleteRegisteredModelResponse = mlops_client.storage.registered_model.delete_registered_model(
mlops.StorageDeleteRegisteredModelRequest(model_id=model.id)
)
Sample script: Batch delete registered models​
### Main
# List MLOps Projects for the user.
prj: mlops.StorageProject
projects: mlops.StorageListProjectsResponse = mlops_client.storage.project.list_projects(
mlops.StorageListProjectsRequest()
)
prj_ids = _get_project_id(projects.project)
to_be_deleted_project_model_ids:list[str] = []
models: mlops.StorageRegisteredModel
# Get all ids for the models to be deleted. This can be across multiple projects.
for id in prj_ids:
models: mlops.StorageListRegisteredModelsResponse = mlops_client.storage.registered_model.list_registered_models(
mlops.StorageListRegisteredModelsRequest(project_id=id)
)
model_ids = _get_registered_model_id(models.registered_models)
to_be_deleted_project_model_ids = to_be_deleted_project_model_ids + model_ids
# Delete the registered model.
batch_deleted_registered_model: mlops.StorageBatchDeleteRegisteredModelResponse = mlops_client.storage.registered_model.batch_delete_registered_model(
mlops.StorageBatchDeleteRegisteredModelRequest(model_ids=to_be_deleted_project_model_ids)
)
Feedback
- Submit and view feedback for this page
- Send feedback about H2O MLOps to cloud-feedback@h2o.ai