Skip to main content
Version: v0.64.0

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 in REGISTERED_MODEL_NAME.

Workflow

  1. Initialize the token provider using the provided refresh token.
  2. Set up the H2O MLOps client with the gateway URL and token provider.
  3. List all projects for the user.
  4. Using the _get_project_id(projects) function, identify and fetch the ID of the project specified in PROJECT_NAME.
  5. For the identified project, list all registered models.
  6. Using the _get_registered_model_id(models) function, identify and fetch the ID of the registered model specified in REGISTERED_MODEL_NAME.
  7. 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