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

使用Feature Store API向MLflow记录模型时遇TypeError错误

解决Databricks Feature Store log_model时的TypeError错误

问题背景

在Databricks 10.4 LTS ML(Spark 3.2.1、Scala 2.12)集群上,执行以下fs.log_model代码时触发类型错误:

fs.log_model(
    model,
    artifact_path="fs_model",
    flavor=mlflow.sklearn,
    training_set=fs_training_set,
)

报错日志核心内容:

TypeError: join() argument must be str, bytes, or os.PathLike object, not 'dict'

栈追踪显示问题出在MLflow底层的os.path.join调用,原因是Feature Store尝试读取conda环境配置时,获取到的conda_file是字典类型而非预期的文件路径字符串。

解决方案

方案1:显式传入conda环境配置

直接在fs.log_model中指定conda_env参数,传入预定义的conda环境字典,绕过自动读取逻辑:

# 定义适配的conda环境
conda_env = {
    "name": "mlflow-feature-store-env",
    "channels": ["conda-forge"],
    "dependencies": [
        "python=3.8.10",
        "scikit-learn>=1.0",
        "pip",
        {
            "pip": [
                "mlflow>=1.26.0",
                "databricks-feature-store"
            ]
        }
    ]
}

# 调用log_model时传入conda_env
fs.log_model(
    model,
    artifact_path="fs_model",
    flavor=mlflow.sklearn,
    training_set=fs_training_set,
    conda_env=conda_env
)

方案2:升级Databricks Runtime

该问题属于版本兼容性bug,升级到Databricks 11.3 LTS及以上版本可直接修复,新版本优化了Feature Store与MLflow的交互逻辑。

方案3:拆分模型记录与特征集关联

先通过MLflow原生API记录模型,再用Feature Store关联训练集:

import mlflow

with mlflow.start_run() as run:
    # 用MLflow原生API记录模型
    mlflow.sklearn.log_model(model, artifact_path="base_model")
    # 关联Feature Store训练集
    fs.log_model(
        model_uri=f"runs:/{run.info.run_id}/base_model",
        artifact_path="fs_model",
        training_set=fs_training_set
    )

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 21:14:57