fromgoogle.cloudimportaiplatformdefdelete_model_sample(model_id:str,project:str,location:str):
"""
DeleteaModelresource.Args:model_id:TheIDofthemodeltodelete.Parentresourcenameofthemodelisalsoaccepted.project:Theproject.location:Theregionname.ReturnsNone.
"""
# Initialize the client.aiplatform.init(project=project,location=location)# Get the model with the ID 'model_id'. The parent_name of Model resource can be also# 'projects/<your-project-id>/locations/<your-region>/models/<your-model-id>'
model=aiplatform.Model(model_name=model_id)# Delete the model.model.delete()
删除模型版本
控制台
从 Google Cloud 控制台的 Vertex AI 部分,进入 Model Registry 页面。
fromgoogle.cloudimportaiplatformdefdelete_model_version_sample(model_id:str,version_id:str,project:str,location:str):
"""
DeleteaModelversion.Args:model_id:TheIDofthemodeltodelete.Parentresourcenameofthemodelisalsoaccepted.version_id:TheversionIDorversionaliasofthemodeltodelete.project:TheprojectID.location:Theregionname.ReturnsNone.
"""
# Initialize the client.aiplatform.init(project=project,location=location)# Initialize the Model Registry resource with the ID 'model_id'.The parent_name of Model resource can be also# 'projects/<your-project-id>/locations/<your-region>/models/<your-model-id>'
model_registry=aiplatform.models.ModelRegistry(model=model_id)# Delete the model version with the version 'version'.model_registry.delete_version(version=version_id)
fromtypingimportListfromgoogle.cloudimportaiplatformdefdelete_aliases_model_version_sample(model_id:str,version_aliases:List[str],version_id:str,project:str,location:str,):
"""
Deletealiasestoamodelversion.Args:model_id:TheIDofthemodel.version_aliases:Theversionaliasestoassign.version_id:TheversionIDofthemodeltoassignthealiasesto.project:TheprojectID.location:Theregionname.ReturnsNone.
"""
# Initialize the client.aiplatform.init(project=project,location=location)# Initialize the Model Registry resource with the ID 'model_id'.The parent_name of Model resource can be also# 'projects/<your-project-id>/locations/<your-region>/models/<your-model-id>'
model_registry=aiplatform.models.ModelRegistry(model=model_id)# Remove the version aliases to the model version with the version 'version'.model_registry.remove_version_aliases(target_aliases=version_aliases,version=version_id)
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-11-21。"],[],[],null,["# Delete a model from Vertex AI Model Registry\n\nLearn how to delete a model you no longer need from the Vertex AI Model Registry.\n\nIf you want to delete a BigQuery ML from Vertex AI Model Registry,\nyou must first delete it from BigQuery ML. To learn more,\nsee [BigQuery ML and Vertex AI Model Registry](/bigquery-ml/docs/managing-models-vertex).\n\nIf you want to delete a model that is deployed to an endpoint, you\nneed to undeploy it first. Otherwise, you are unable to delete the model.\n\nDelete a model\n--------------\n\n### Console\n\n1. Go to the **Model Registry** page from the Vertex AI section\n in the Google Cloud console.\n\n [Go to the Model Registry page](https://console.cloud.google.com/vertex-ai/models)\n2. Select **More actions** from the model you want to delete.\n more_vert\n\n3. Select **Delete model**.\n When you delete the model, all associated model versions and evaluations are\n deleted from your Google Cloud project.\n\n4. Click **Delete** on the confirmation screen.\n\n### gcloud\n\n\nBefore using any of the command data below,\nmake the following replacements:\n\n- \u003cvar translate=\"no\"\u003eMODEL_ID\u003c/var\u003e: The ID of your model.\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: Your Google Cloud [project ID](/resource-manager/docs/creating-managing-projects#identifiers).\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: Your project's region. For example, `us-central1`.\n\n\nExecute the\n\nfollowing\n\ncommand:\n\n#### Linux, macOS, or Cloud Shell\n\n**Note:** Ensure you have initialized the Google Cloud CLI with authentication and a project by running either [gcloud init](/sdk/gcloud/reference/init); or [gcloud auth login](/sdk/gcloud/reference/auth/login) and [gcloud config set project](/sdk/gcloud/reference/config/set). \n\n```bash\ngcloud ai models delete MODEL_ID \\\n --project=PROJECT_ID \\\n --region=LOCATION\n```\n\n#### Windows (PowerShell)\n\n**Note:** Ensure you have initialized the Google Cloud CLI with authentication and a project by running either [gcloud init](/sdk/gcloud/reference/init); or [gcloud auth login](/sdk/gcloud/reference/auth/login) and [gcloud config set project](/sdk/gcloud/reference/config/set). \n\n```bash\ngcloud ai models delete MODEL_ID `\n --project=PROJECT_ID `\n --region=LOCATION\n```\n\n#### Windows (cmd.exe)\n\n**Note:** Ensure you have initialized the Google Cloud CLI with authentication and a project by running either [gcloud init](/sdk/gcloud/reference/init); or [gcloud auth login](/sdk/gcloud/reference/auth/login) and [gcloud config set project](/sdk/gcloud/reference/config/set). \n\n```bash\ngcloud ai models delete MODEL_ID ^\n --project=PROJECT_ID ^\n --region=LOCATION\n```\n\n\u003cbr /\u003e\n\n### API\n\n\nDelete a model using the Vertex AI SDK for Python.\n\n### Python\n\n\n from google.cloud import aiplatform\n\n\n def delete_model_sample(model_id: str, project: str, location: str):\n \"\"\"\n Delete a Model resource.\n Args:\n model_id: The ID of the model to delete. Parent resource name of the model is also accepted.\n project: The project.\n location: The region name.\n Returns\n None.\n \"\"\"\n # Initialize the client.\n aiplatform.init(project=project, location=location)\n\n # Get the model with the ID 'model_id'. The parent_name of Model resource can be also\n # 'projects/\u003cyour-project-id\u003e/locations/\u003cyour-region\u003e/models/\u003cyour-model-id\u003e'\n model = aiplatform.Model(model_name=model_id)\n\n # Delete the model.\n model.delete()\n\nDelete a model version\n----------------------\n\n### Console\n\n1. Go to the **Model Registry** page from the Vertex AI section\n in the Google Cloud console.\n\n [Go to the Model Registry page](https://console.cloud.google.com/vertex-ai/models)\n2. Expand the model to view its model versions. Select the version that you want to delete.\n\n3. Select the **More actions** from the model version.\n menu more_vert.\n\n4. Select **Delete version**. All associated model evaluations are deleted when you delete your version.\n\n### gcloud\n\n\nBefore using any of the command data below,\nmake the following replacements:\n\n- \u003cvar translate=\"no\"\u003eMODEL_VERSION_ID\u003c/var\u003e: The ID of the model version to delete.\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: Your Google Cloud [project ID](/resource-manager/docs/creating-managing-projects#identifiers).\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: Your project's region. For example, `us-central1`.\n\n\nExecute the\n\nfollowing\n\ncommand:\n\n#### Linux, macOS, or Cloud Shell\n\n**Note:** Ensure you have initialized the Google Cloud CLI with authentication and a project by running either [gcloud init](/sdk/gcloud/reference/init); or [gcloud auth login](/sdk/gcloud/reference/auth/login) and [gcloud config set project](/sdk/gcloud/reference/config/set). \n\n```bash\ngcloud ai models delete-version MODEL_VERSION_ID \\\n --project=PROJECT_ID \\\n --region=LOCATION\n```\n\n#### Windows (PowerShell)\n\n**Note:** Ensure you have initialized the Google Cloud CLI with authentication and a project by running either [gcloud init](/sdk/gcloud/reference/init); or [gcloud auth login](/sdk/gcloud/reference/auth/login) and [gcloud config set project](/sdk/gcloud/reference/config/set). \n\n```bash\ngcloud ai models delete-version MODEL_VERSION_ID `\n --project=PROJECT_ID `\n --region=LOCATION\n```\n\n#### Windows (cmd.exe)\n\n**Note:** Ensure you have initialized the Google Cloud CLI with authentication and a project by running either [gcloud init](/sdk/gcloud/reference/init); or [gcloud auth login](/sdk/gcloud/reference/auth/login) and [gcloud config set project](/sdk/gcloud/reference/config/set). \n\n```bash\ngcloud ai models delete-version MODEL_VERSION_ID ^\n --project=PROJECT_ID ^\n --region=LOCATION\n```\n\n\u003cbr /\u003e\n\n### API\n\n### Python\n\n\n from google.cloud import aiplatform\n\n\n def delete_model_version_sample(\n model_id: str, version_id: str, project: str, location: str\n ):\n \"\"\"\n Delete a Model version.\n Args:\n model_id: The ID of the model to delete. Parent resource name of the model is also accepted.\n version_id: The version ID or version alias of the model to delete.\n project: The project ID.\n location: The region name.\n Returns\n None.\n \"\"\"\n # Initialize the client.\n aiplatform.init(project=project, location=location)\n\n # Initialize the Model Registry resource with the ID 'model_id'.The parent_name of Model resource can be also\n # 'projects/\u003cyour-project-id\u003e/locations/\u003cyour-region\u003e/models/\u003cyour-model-id\u003e'\n model_registry = aiplatform.models.ModelRegistry(model=model_id)\n\n # Delete the model version with the version 'version'.\n model_registry.delete_version(version=version_id)\n\nDelete a model version with the default alias\n---------------------------------------------\n\n### Console\n\n1. From the Model Registry, select the model name to view its model versions.\n2. Select the version that you want, and from the **Actions** button more_vert click **Delete**. A warning opens since you're attempting to delete the default alias version. Set another version as default first.\n3. Select what version you want to make default for the model from the drop-down.\n4. On the confirmation screen, click **Set and delete.**\n\n### API\n\n### Python\n\n\n from typing import List\n\n from google.cloud import aiplatform\n\n\n def delete_aliases_model_version_sample(\n model_id: str,\n version_aliases: List[str],\n version_id: str,\n project: str,\n location: str,\n ):\n \"\"\"\n Delete aliases to a model version.\n Args:\n model_id: The ID of the model.\n version_aliases: The version aliases to assign.\n version_id: The version ID of the model to assign the aliases to.\n project: The project ID.\n location: The region name.\n Returns\n None.\n \"\"\"\n # Initialize the client.\n aiplatform.init(project=project, location=location)\n\n # Initialize the Model Registry resource with the ID 'model_id'.The parent_name of Model resource can be also\n # 'projects/\u003cyour-project-id\u003e/locations/\u003cyour-region\u003e/models/\u003cyour-model-id\u003e'\n model_registry = aiplatform.models.ModelRegistry(model=model_id)\n\n # Remove the version aliases to the model version with the version 'version'.\n model_registry.remove_version_aliases(\n target_aliases=version_aliases, version=version_id\n )"]]