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

MLflow已注册模型UI可见但REST API无法获取问题求助

问题描述

我正在使用MLflow,实验数据在MLflow UI和REST API中都能正常获取,但通过代码或UI注册的模型,在UI中显示正常,调用REST API时却提示模型不存在。已经确认tracking URI配置正确,现在需要部署模型却遇到这个问题。

用到的代码片段:

import mlflow

mlflow.set_tracking_uri("http://localhost:5000")

# Set the experiment
mlflow.set_experiment("exp_2")

# Start MLflow
with mlflow.start_run():
    # Check if metrics present in this run_metrics if yes log that
    for metric in run_metrics:
            mlflow.log_metric(metric, run_metrics[metric])

    # We use artifact when we are saving files
    mlflow.log_artifact('confusion_matrix.png', 'confusion_materix')

    # This below code we use for tag
    mlflow.set_tag("tag1", "KNN Algo")
    mlflow.set_tags({"tag2":"Testing", "tag3":"Testing2"})

    # Send the model also
    #mlflow.sklearn.log_model(knn, "model",registered_model_name='Register_first_Model_1')
    mlflow.sklearn.log_model(knn, "model")

print('It is logged to Experiment - %s' %( experiment_name))
解决方案
  • 确认模型是否完成注册:当前代码注释掉了带registered_model_name的行,实际执行的mlflow.sklearn.log_model(knn, "model")仅将模型作为实验artifact保存,不会自动注册到模型仓库。如果是通过UI手动注册,需确认注册操作已完成,检查UI的「Registered Models」页面是否有该模型条目且状态正常。
  • 检查REST API端点格式:调用已注册模型的API端点必须符合规范,示例如下:
    • 获取已注册模型列表:GET /api/2.0/mlflow/registered-models/list
    • 获取特定模型详情:GET /api/2.0/mlflow/registered-models/get?name=<模型名称>
    • 获取模型版本:GET /api/2.0/mlflow/model-versions/get?name=<模型名称>&version=<版本号>
      确保请求中的模型名称与UI显示完全一致,注意大小写、空格等细节。
  • 验证模型阶段与权限:若模型处于Staging或Archived阶段,部分API调用需指定阶段参数;若MLflow启用了权限控制,请求需携带正确的认证信息(如token)。
  • 检查MLflow服务配置:启动MLflow服务时需明确指定--backend-store-uri和--default-artifact-root参数,确保模型注册数据和artifact数据能被服务正确读取。Mac环境下启动示例:
    mlflow server --backend-store-uri sqlite:///mlflow.db --default-artifact-root ./mlruns --host 0.0.0.0 --port 5000
    
  • 刷新服务缓存:MLflow服务可能缓存模型注册信息,尝试重启服务后重新调用API。
  • 核对模型名称准确性:通过UI注册的模型,需确认注册时填写的名称与API请求中的名称完全匹配,避免拼写错误或特殊字符导致匹配失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 21:25:20