使用Python SDK v2删除AzureML模型

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

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 来实现:

  1. from azureml.core import Workspace, Model
  2. workspace = ...
  3. model = Model(workspace=workspace, name=name, version=version)
  4. 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:

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

答案1

得分: 1

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

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

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

  1. az extension add -n azure-cli-ml
  • 使用 az 模型 delete 命令,我成功删除了 模型
  1. az ml model delete --model-id <model_id> --workspace-name <workspace_name> --resource-group <resource_group> --subscription <subscription_id>
  • 使用 Python SDK
  1. from azureml.core import Workspace, Model
  2. # 用你的 AzureML 工作区详细信息替换下面的内容
  3. subscription_id = "你的订阅 ID"
  4. resource_group = "你的资源组"
  5. workspace_name = "你的工作区名称"
  6. # 用你的模型名称和版本替换下面的内容
  7. model_name = "你的模型名称"
  8. model_version = 2
  9. workspace = Workspace(subscription_id, resource_group, workspace_name)
  10. # 使用 Model 类获取模型
  11. model = Model(workspace=workspace, name=model_name, version=model_version)
  12. model_id = model.id
  13. print("模型 ID:", model_id)
  14. # 删除模型
  15. model.delete()
  16. 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
  1. az extension add -n azure-cli-ml

使用Python SDK v2删除AzureML模型

  1. 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
  1. from azureml.core import Workspace, Model
  2. # Replace with your AzureML workspace details
  3. subscription_id = &quot;your-subscription-id&quot;
  4. resource_group = &quot;your-resource-group&quot;
  5. workspace_name = &quot;your-workspace-name&quot;
  6. # Replace with your model name and version
  7. model_name = &quot;your-model-name&quot;
  8. model_version = 2
  9. workspace = Workspace(subscription_id, resource_group, workspace_name)
  10. # Get the model using the Model class
  11. model = Model(workspace=workspace, name=model_name, version=model_version)
  12. model = Model(workspace, name=model_name)
  13. model_id = model.id
  14. print(&quot;Model ID:&quot;, model_id)
  15. # Delete the model
  16. model.delete()
  17. 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:

确定