You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将AzureML AutoML最优模型从model_uri注册为自定义模型而非MLflow模型?

解决方法:用AzureML原生SDK注册为自定义模型

要把这个模型注册成自定义模型(custom model),别用MLflow的register_model方法,改用AzureML Python SDK的原生模型注册接口,就能绕过MLflow的自动识别逻辑,直接标记为自定义模型。

具体步骤和代码如下:

  1. 导入AzureML必要库并获取工作区对象
  2. 从MLmodel文件提取目标运行ID
  3. 通过运行ID获取模型所在的输出路径
  4. 调用AzureML原生注册方法,明确标记为自定义模型

修改后的代码示例:

import os
from azureml.core import Workspace, Model, Run

# 加载AzureML工作区(默认读取本地config.json配置,也可手动指定参数)
ws = Workspace.from_config()

# 从MLmodel文件提取Run ID
print("Getting model path")
mlmodel_path = os.path.join(args.model_input_path, "MLmodel")
runid = ""
with open(mlmodel_path, "r") as modelfile:
    for line in modelfile:
        if "run_id" in line:
            runid = line.split(":")[1].strip()

# 获取对应运行的对象
target_run = Run.get(ws, run_id=runid)

# 获取运行中mlflow-model文件夹的路径
model_source_path = target_run.get_file_path("outputs/mlflow-model/")

# 注册为自定义模型
registered_model = Model.register(
    workspace=ws,
    model_name=registered_name,
    model_path=model_source_path,
    model_framework=None,  # 设置为None即标记为自定义模型
    description="Custom model registered from AutoML's mlflow-model output"
)

print(f"Registered custom model ID: {registered_model.id}")

关键说明:

  • 放弃MLflow的注册方法,改用AzureML原生的Model.register,不会触发MLflow的模型类型自动识别
  • model_framework=None是核心设置,让AzureML将模型归类为自定义模型,而非MLflow模型
  • 通过Run.get_file_path直接读取运行内的模型文件路径,无需构造MLflow格式的model_uri

内容的提问来源于stack exchange,提问作者Eddmik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 13:12:09