英文:
Delete AzureML model using python SDK v2
问题
我尝试使用 Python SDK v2 删除 AzureML 模型,但我找不到这样的功能。这有点令人惊讶,因为在 Web UI 中有这样的功能。
查看了 azure.ai.ml.entities.Model
和 azure.ai.ml.operations.ModelOperations
(其中定义了所有 ml_client.models.<operation>
操作的类) - 未找到支持删除操作的功能。
编辑 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)
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 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("模型已成功删除。")
英文:
> 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
- Adding az extension i was able to find delete command
az extension add -n azure-cli-ml
az ml model delete --model-id <model_id> --workspace-name <workspace_name> --resource-group <resource_group> --subscription <subscription_id>
- using python sdk
from azureml.core import Workspace, Model
# Replace with your AzureML workspace details
subscription_id = "your-subscription-id"
resource_group = "your-resource-group"
workspace_name = "your-workspace-name"
# Replace with your model name and version
model_name = "your-model-name"
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("Model ID:", model_id)
# Delete the model
model.delete()
print("Model deleted successfully.")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论