Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using R SDK in Azure ML Web Service container #403

Open
lehmus opened this issue Nov 6, 2020 · 0 comments
Open

Using R SDK in Azure ML Web Service container #403

lehmus opened this issue Nov 6, 2020 · 0 comments
Assignees

Comments

@lehmus
Copy link

lehmus commented Nov 6, 2020

What is the recommended way to install Azure ML R SDK in a Docker container and deploy as a Web Service? I am trying to deploy an Azure ML Web Service Endpoint in an Azure Container Instance. I have made a custom Docker image and registered it as an Environment in Azure ML Workspace. I have a minimal inference script as follows:

library(azuremlsdk)

init <- function() {

  function(data) {

    sp_auth <- service_principal_authentication(
      tenant_id = "<TENANT_ID>",
      service_principal_id = "<SP_ID>",
      service_principal_password = "<SP_PW>"
    )
    aml_workspace <- get_workspace(
      name = "<WORKSPACE>",
      auth = sp_auth,
      subscription_id = "<SUBSCRIPTION_ID>"
    )

    return('{"result": "Hello, world"}')
  }
}

The deployment is successful and the container starts up without errors. However, when I call the Web Service endpoint, the following error occurs:

home/dockeruser/miniconda/lib/python3.7/site-packages/rpy2/rinterface/__init__.py:146: RRuntimeWarning: No non-system installation of Python could be found.
Would you like to download and install Miniconda?
Miniconda is an open source environment management system for Python.
See https://docs.conda.io/en/latest/miniconda.html for more details.


  warnings.warn(x, RRuntimeWarning)
Would you like to install Miniconda? [Y/n]:
Traceback (most recent call last):
  File "/home/dockeruser/miniconda/lib/python3.7/site-packages/rpy2/rinterface/__init__.py", line 158, in consoleRead
text = input(prompt)
EOFError
:
EOF when reading a line
/home/dockeruser/miniconda/lib/python3.7/site-packages/rpy2/rinterface/__init__.py:146: RRuntimeWarning: Error: missing value where TRUE/FALSE needed

A similar error was reported in Azure ML Notebook Compute Instances, see issue #361. The error was fixed there by changing the Notebook environment. How can I circumvent this issue in AML Web Service container, where there is no way to give input?

Note that the error is thrown when I call the functions service_principal_authentication and get_workspace. If I remove those commands and leave library(azuremlsdk), the script is executed successfully and response is returned as expected.

This is my full Dockerfile:

FROM ubuntu

ARG PYTHON_VERSION=3.7
ARG CONDA_VERSION=4.8.3
ARG AZUREML_SDK_VERSION=1.13.0
ARG DEBIAN_FRONTEND=noninteractive

USER root:root

ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8

RUN apt-get update --fix-missing && \
    apt-get upgrade -y && \
    apt-get install -y bzip2 wget curl gcc && \
    apt-get install -y fuse

# Azure CLI
RUN apt-get install -y apt-transport-https lsb-release gnupg
RUN CLI_REPO="$(lsb_release -cs)" && \
    curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.asc.gpg && \
    echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ ${CLI_REPO} main" > /etc/apt/sources.list.d/azure-cli.list && \
    apt-get update && \
    apt-get install -y azure-cli

# Clean OS installation files
RUN apt-get clean -y && \
    rm -rf /var/lib/apt/lists/*

# Docker user
RUN useradd --create-home dockeruser
WORKDIR /home/dockeruser
USER dockeruser

# Miniconda
ENV CONDA_PATH=/home/dockeruser/miniconda
ENV PATH="${PATH}:${CONDA_PATH}/bin/"
RUN wget -qO /home/dockeruser/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-py37_$CONDA_VERSION-Linux-x86_64.sh && \
    bash /home/dockeruser/miniconda.sh -b -p $CONDA_PATH && \
    rm /home/dockeruser/miniconda.sh
RUN conda init bash

# Essential Azure ML Service & R dependencies from conda
RUN conda install -qy conda=${CONDA_VERSION} python=${PYTHON_VERSION} && \
    conda install --channel r -qy conda=${CONDA_VERSION} r-essentials rpy2 r-reticulate r-devtools r-testthat && \
    conda clean -aqy

RUN pip install azureml-defaults==${AZUREML_SDK_VERSION} && \
    pip install azureml-dataprep[pandas,fuse] && \
    pip install inference-schema

# Clean conda installation files
RUN rm -rf $CONDA_PATH/pkgs && \
    find $CONDA_PATH -type d -name __pycache__ -prune | xargs rm -rf

# Azure ML Service dependencies
ENV TAR=/bin/tar
RUN R -e 'remotes::install_github("https://github.com/Azure/azureml-sdk-for-r", build_vignettes = TRUE)'
RUN R -e 'azuremlsdk::install_azureml()'

As a side note, I am also seeing errors when installing Azure ML R SDK in Docker. The SDK requires the dependency httpuv, which produces thousands of lines of errors like warning: 'template<class> class std::auto_ptr' is deprecated. This is the beginning of the error messages:

In file included from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/bind/mem_fn.hpp:25:0,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/mem_fn.hpp:22,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/bind/bind.hpp:26,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/bind.hpp:22,
                 from callback_registry.cpp:1:
/home/dockeruser/miniconda/lib/R/library/BH/include/boost/get_pointer.hpp:48:40: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
 template<class T> T * get_pointer(std::auto_ptr<T> const& p)
                                        ^~~~~~~~
In file included from /home/dockeruser/miniconda/x86_64-conda_cos6-linux-gnu/include/c++/7.3.0/memory:80:0,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/config/no_tr1/memory.hpp:21,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/get_pointer.hpp:14,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/bind/mem_fn.hpp:25,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/mem_fn.hpp:22,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/bind/bind.hpp:26,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/bind.hpp:22,
                 from callback_registry.cpp:1:
/home/dockeruser/miniconda/x86_64-conda_cos6-linux-gnu/include/c++/7.3.0/bits/unique_ptr.h:51:28: note: declared here
   template<typename> class auto_ptr;
                            ^~~~~~~~
In file included from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/smart_ptr/shared_ptr.hpp:28:0,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/shared_ptr.hpp:17,
                 from callback_registry.cpp:2:
/home/dockeruser/miniconda/lib/R/library/BH/include/boost/smart_ptr/detail/shared_count.hpp:356:33: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
     explicit shared_count( std::auto_ptr<Y> & r ): pi_( new sp_counted_impl_p<Y>( r.get() ) )
                                 ^~~~~~~~
In file included from /home/dockeruser/miniconda/x86_64-conda_cos6-linux-gnu/include/c++/7.3.0/memory:80:0,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/config/no_tr1/memory.hpp:21,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/get_pointer.hpp:14,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/bind/mem_fn.hpp:25,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/mem_fn.hpp:22,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/bind/bind.hpp:26,
                 from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/bind.hpp:22,
                 from callback_registry.cpp:1:
/home/dockeruser/miniconda/x86_64-conda_cos6-linux-gnu/include/c++/7.3.0/bits/unique_ptr.h:51:28: note: declared here
   template<typename> class auto_ptr;
                            ^~~~~~~~
In file included from /home/dockeruser/miniconda/lib/R/library/BH/include/boost/shared_ptr.hpp:17:0,
                 from callback_registry.cpp:2:
/home/dockeruser/miniconda/lib/R/library/BH/include/boost/smart_ptr/shared_ptr.hpp:256:65: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
 template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R >

It doesn't matter if I install the CRAN version (1.10.0) or Github version (1.13.0) of the SDK, these errors always persist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants