排查
使用 Azure 机器学习时,可能会收到以下错误:
TypeError: Descriptors cannot not be created directly. If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0." It is followed by the proposition to install the appropriate version of protobuf library.
If you cannot immediately regenerate your protos, some other possible workarounds are:
1. Downgrade the protobuf package to 3.20.x or lower.
2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
尤其是在使用 AutoML 时,你可能会注意到此错误。
原因
此问题是由 protobuf 4.0.0 中引入的中断性变更引起的。 有关详细信息,请参阅 https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates。
解决方法
对于本地开发环境或计算实例,请安装 Azure 机器学习 SDK 1.42.0.post1 或更高版本。
pip install azureml-sdk[automl,explain,notebooks]>=1.42.0
若要详细了解如何更新 Azure 机器学习环境(用于训练或部署),请参阅以下文章:
若要验证已安装的 SDK 的版本,请使用以下命令:
pip show azureml-core
此命令应该返回类似“Version: 1.42.0.post1
”的信息。
提示
如果无法升级 Azure 机器学习 SDK 安装,则可将环境中的 protobuf 版本固定到 3.20.1
。 以下示例是一个演示如何固定版本的 conda.yml
文件:
name: model-env
channels:
- conda-forge
dependencies:
- python=3.8
- numpy=1.21.2
- pip=21.2.4
- scikit-learn=0.24.2
- scipy=1.7.1
- pandas>=1.1,<1.2
- pip:
- inference-schema[numpy-support]==1.3.0
- xlrd==2.0.1
- mlflow== 1.26.0
- azureml-mlflow==1.41.0
- protobuf==3.20.1
后续步骤
有关 protobuf 4.0.0 中的中断性变更的详细信息,请参阅 https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates。
若要详细了解如何更新 Azure 机器学习环境(用于训练或部署),请参阅以下文章: