简体   繁体   English

Azure 机器学习工作室:无法以 rpy2 作为依赖项部署 model

[英]Azure Machine Learning Studio: cannot deploy model with rpy2 as a dependency

I am trying to deploy a custom model on Azure Machine Learning Studio that needs rpy2 (Python wrapper for R) to run.我正在尝试在需要 rpy2(R 的 Python 包装器)运行的 Azure 机器学习工作室上部署自定义 model。 So, I created the following yml file (myenv.yml), specifying the required dependency (besides other stuff),所以,我创建了以下 yml 文件(myenv.yml),指定所需的依赖项(除了其他东西),

# Conda environment specification. The dependencies defined in this file will
# be automatically provisioned for runs with userManagedDependencies=False.

# Details about the Conda environment file format:
# https://conda.io/docs/user-guide/tasks/manage-environments.html#create-env-file-manually

name: project_environment

dependencies:
  # The python interpreter version.
  # Currently Azure ML only supports 3.5.2 and later.
- python=3.6.2    
- pip:
  - azureml-train-automl-runtime==1.8.0.post1
  - inference-schema
  - azureml-explain-model==1.8.0
  - azureml-defaults==1.8.0
  - rpy2==3.3.5
- dill==0.3.2
- numpy>=1.16.0,<=1.16.2
- pandas>=0.21.0,<=0.23.4
- scikit-learn>=0.19.0,<=0.20.3
- py-xgboost<=0.90
- fbprophet==0.5
- psutil>=5.2.2,<6.0.0

channels:
- anaconda
- conda-forge

and then ran the following script (based on https://docs.microsoft.com/en-us/azure/machine-learning/how-to-troubleshoot-deployment ):然后运行以下脚本(基于https://docs.microsoft.com/en-us/azure/machine-learning/how-to-troubleshoot-deployment ):

from azureml.core.environment import Environment
from azureml.core.model import Model, InferenceConfig
from azureml.core import Workspace
from azureml.core.webservice import AciWebservice

ws = Workspace.from_config()
model = Model(workspace = ws, name = 'test-rpy2') # this is my (registered) model that needs rpy2 to run

# create inference configuration based on the requirements defined in the YAML
myenv = Environment.from_conda_specification(name = "myenv", file_path = "myenv.yml")

inference_config = InferenceConfig(entry_script = "score.py", environment = myenv) # score.py: my custom scoring file where rpy2 is imported

# deploy the model
aci_config = AciWebservice.deploy_configuration(cpu_cores = 1, memory_gb = 1)

service = Model.deploy(workspace         = ws,
                       name              = 'test-rpy2',
                       models            = [model],
                       inference_config  = inference_config,
                       deployment_config = aci_config)

service.wait_for_deployment(show_output=True)

However, I get the following error:但是,我收到以下错误:

    Error: rpy2 in API mode cannot be built without R in the PATH or R_HOME defined. Correct this or force ABI mode-only by defining the environment variable RPY2_CFFI_MODE=ABI

I expected that the issue would be fixed by adding the line我希望通过添加该行来解决该问题

myenv.environment_variables['RPY2_CFFI_MODE'] = 'ABI'

right after the definition of myenv, but the exact same error shows up again.在 myenv 的定义之后,但完全相同的错误再次出现。

Does anyone have any idea on how to make it work?有谁知道如何使它工作?

To me, the message is saying that you can't use rpy2 because R is not installed in the Docker image.对我来说,消息是说您不能使用rpy2 ,因为 Docker 映像中未安装 R。 I think the fix is that You'll have to add R as a conda dependency.我认为解决方法是您必须添加 R 作为 conda 依赖项。 Here's some guidance .这里有一些指导 I'm not an expert on R + conda but try adding r-base and r-essentials as conda deps.我不是R + conda方面的专家,但尝试将r-baser-essentials添加为 conda deps。

another note -- I strongly recommend minimizing conda dependencies when using the azureml-sdk because azureml-sdk is only available on PyPI.另一个注意事项——我强烈建议在使用azureml-sdk时尽量减少 conda 依赖项,因为azureml-sdk仅在 PyPI 上可用。 This doc explains the challenges well. 该文档很好地解释了这些挑战。 Below is my guess on what it would look like, but i'm not confident on the mapping b/w anaconda and pip packagenames/versions.以下是我对其外观的猜测,但我对 b/w anaconda 和 pip 包名/版本的映射没有信心。

dependencies:
- python=3.6.2
- r-base 
- r-essentials
- py-xgboost<=0.90   
- pip:
  - azureml-train-automl-runtime==1.8.0.post1
  - inference-schema
  - azureml-explain-model==1.8.0
  - azureml-defaults==1.8.0
  - rpy2==3.3.5
  - dill==0.3.2
  - numpy>=1.16.0,<=1.16.2
  - pandas>=0.21.0,<=0.23.4
  - scikit-learn>=0.19.0,<=0.20.3
  - fbprophet==0.5
  - psutil>=5.2.2,<6.0.0

channels:
- anaconda
- conda-forge

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM