MLflow 1.24.0部署模型至Databricks遇格式错误求助
核心错误提示
Unrecognized content type parameters: format. IMPORTANT: The MLflow Model scoring protocol has changed in MLflow version 2.0. If you are seeing this error, you are likely using an outdated scoring request format. To resolve the error, either update your request format or adjust your MLflow Model's requirements file to specify an older version of MLflow (for example, change the 'mlflow' requirement specifier to 'mlflow==1.30.0'). If you are making a request using the MLflow client (e.g. via mlflow.pyfunc.spark_udf()), upgrade your MLflow client to a version >= 2.0 in order to use the new request format.
当前环境与输入信息
- MLflow版本:
mlflow==1.24.0(无权限升级) - 当前使用的JSON输入格式:
[ { "input1":12, "input2":290.0, "input3":'red' } ]
尝试解决后遇到的新错误
参考方案执行spark_udf()时触发:
TypeError:spark_udf() got an unexpected keyword argument 'env_manager'
1. 适配MLflow 1.x的请求格式
MLflow 2.0修改了评分协议,1.24.0需遵循1.x版本规范:
- 请求头的Content-Type直接用
application/json,不要添加format参数 - 修正JSON格式:JSON规范要求字符串用双引号,把
'red'改成"red",修正后输入:
[ { "input1":12, "input2":290.0, "input3":"red" } ]
2. 修复spark_udf()参数错误
env_manager是MLflow 2.0新增参数,1.24.0不支持,需移除该参数,改用1.x版本的配置方式:
- 错误写法(含env_manager):
mlflow.pyfunc.spark_udf(spark, model_uri="models:/my_model/1", env_manager="local")
- 正确写法(移除env_manager,如需指定环境用conda_env参数):
mlflow.pyfunc.spark_udf(spark, model_uri="models:/my_model/1") # 若模型依赖特定conda环境,可传入环境文件路径 # mlflow.pyfunc.spark_udf(spark, model_uri="models:/my_model/1", conda_env="/path/to/conda_env.yml")
额外验证步骤
- 确保模型的
requirements.txt中指定mlflow==1.24.0,避免客户端与模型端版本不匹配 - 在Databricks部署时,选择与MLflow 1.24.0兼容的运行环境,不要默认使用2.0+版本环境
内容的提问来源于stack exchange,提问作者Sara

