使用Python SDK v2删除AzureML模型

huangapple go评论80阅读模式
英文:

Delete AzureML model using python SDK v2

问题

我尝试使用 Python SDK v2 删除 AzureML 模型,但我找不到这样的功能。这有点令人惊讶,因为在 Web UI 中有这样的功能。

查看了 azure.ai.ml.entities.Modelazure.ai.ml.operations.ModelOperations(其中定义了所有 ml_client.models.<operation> 操作的类) - 未找到支持删除操作的功能。

编辑 1:
v2 CLI 也不支持删除(存档不是删除)
使用Python SDK v2删除AzureML模型

编辑 2:
作为部分解决方案,可以使用 SDK v1 来实现:

from azureml.core import Workspace, Model
workspace = ...
model = Model(workspace=workspace, name=name, version=version)
model.delete()
英文:

I'm trying to delete an AzureML model using the python SDK v2,
but I couldn't find such functionality.
its a bit surprising, cause there's such functionality in the web UI.

Was looking at both azure.ai.ml.entities.Model and azure.ai.ml.operations.ModelOperations (the class under which all ml_client.models.<operation> operations are defined) - cant find support for delete operation under them.

Edit 1:
The v2 CLI doesn't support deletion as well (archiving is not deletion)
使用Python SDK v2删除AzureML模型

Edit 2:
As partial solution, this can be achieved using SDK v1:

from azureml.core import Workspace, Model
workspace = ...
model = Model(workspace=workspace, name=name, version=version)
model.delete()

答案1

得分: 1

  • 使用 Azure CLI 和 Python SDK,我使用 Python SDK 1.49.0 删除了 Azure ML 模型。

  • 使用 Azure CLI,我得到了相同的命令。

  • 添加 Azure CLI 扩展,我能够找到删除命令。

az extension add -n azure-cli-ml
  • 使用 az 模型 delete 命令,我成功删除了 模型
az ml model delete --model-id <model_id> --workspace-name <workspace_name> --resource-group <resource_group> --subscription <subscription_id>
  • 使用 Python SDK
from azureml.core import Workspace, Model

# 用你的 AzureML 工作区详细信息替换下面的内容
subscription_id = "你的订阅 ID"
resource_group = "你的资源组"
workspace_name = "你的工作区名称"

# 用你的模型名称和版本替换下面的内容
model_name = "你的模型名称"
model_version = 2

workspace = Workspace(subscription_id, resource_group, workspace_name)

# 使用 Model 类获取模型
model = Model(workspace=workspace, name=model_name, version=model_version)

model_id = model.id

print("模型 ID:", model_id)

# 删除模型
model.delete()

print("模型已成功删除。")

使用Python SDK v2删除AzureML模型

使用Python SDK v2删除AzureML模型

英文:

> using Azure cli and python sdk I Deleted Azure ML model using python SDK 1.49.0

  • Using Azure cli I got the same command

使用Python SDK v2删除AzureML模型

  • Adding az extension i was able to find delete command
  az extension add -n azure-cli-ml

使用Python SDK v2删除AzureML模型

   az ml model delete --model-id &lt;model_id&gt; --workspace-name &lt;workspace_name&gt; --resource-group &lt;resource_group&gt; --subscription &lt;subscription_id&gt;

使用Python SDK v2删除AzureML模型

  • using python sdk

from azureml.core import Workspace, Model

# Replace with your AzureML workspace details
subscription_id = &quot;your-subscription-id&quot;
resource_group = &quot;your-resource-group&quot;
workspace_name = &quot;your-workspace-name&quot;

# Replace with your model name and version
model_name = &quot;your-model-name&quot;
model_version = 2

workspace = Workspace(subscription_id, resource_group, workspace_name)

# Get the model using the Model class
model = Model(workspace=workspace, name=model_name, version=model_version)

model = Model(workspace, name=model_name)

model_id = model.id

  

print(&quot;Model ID:&quot;, model_id)

# Delete the model
model.delete()

print(&quot;Model deleted successfully.&quot;)

使用Python SDK v2删除AzureML模型

使用Python SDK v2删除AzureML模型

huangapple
  • 本文由 发表于 2023年3月12日 19:49:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75712901.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定