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

I am a bit stuck: I'm trying to deploy a pytorch model which runs fine on my local computer but hangs when trying to deploy it. The model's docker container gives me this error log:

$ docker logs 4437076d479c
Starting PyTorchContainer container
Connecting to Clipper with default port: 7000
Encountered an ImportError when running container. You can use the pkgs_to_install argument when calling clipper_admin.build_model() to supply any needed Python packages.

It seems like it is not able to import some dependency. I installed the same model in a clean anaconda environment on my computer and checked exactly which dependencies I needed to install. I listed these in pkgs_to_install. I have inspected all the log files of the docker containers and I can't find the actual error message which could give me a hint as to which dependency is missing. May some error log be getting swallowed somewhere?

The model I'm trying to run is the xinntao/ESRGAN for image super-resolution.

Dependencies:
Python 3
PyTorch >= 0.4.0
Python packages: pip install numpy opencv-python

The command to deploy the model:

deploy_pytorch_model(
    clipper_conn,
    name="superresolution-model",
    version=1,
    input_type="bytes",
    func=image_enhance,
    pytorch_model=model,
    pkgs_to_install=['opencv-python','numpy','six', 'Pillow','wheel',]

the clipper_service.py is where I define the model and try to deploy.

Hi Thanks for raising this issue.

The import error is because the script is importing architecture.py and architecture.py is importing block.py. Cloupickle (package we use to serialize function) is not able to pick up and bundle these scripts directly. Basically, when we deserialize the script in container, it will run something like import architecture as arch and then architecture will import block as B.

If you consolidate all three files architecture.py, block.py, and clipper_service.py into a single clipper_service file, you should be good to go.

In few days, we will add a feature where you can directly deploy a onnx model (which you can directly export from pytorch using on line of code). This will be much easier.

Hello, @voodoohop. Happy new year!
First of all, thank you for your error report. Clipper installs the PyTorch library from pypi, but pypi has not been updated since Mar 11, 2017 and the 0.1.2 version is the last. Because xinntao/ESRGAN has 'PyTorch >= 0.4.0' dependency, you have to create a custom model container to support the latest PyTorch. Please refer to this link.

For example, if you prefer Python 3.6, no CUDA environment,

  • Create a Dockerfile like this,
  • FROM clipper/python36-closure-container:0.3
    RUN pip install https://download.pytorch.org/whl/cpu/torch-1.0.0-cp36-cp36m-linux_x86_64.whl torchvision
    
  • Build a Docker image.
  • $ docker build -t custom-model-image .
    
  • Deploy your model with base_image,
  • deploy_pytorch_model(
        clipper_conn,
        name="superresolution-model",
        version=1,
        input_type="bytes",
        func=image_enhance,
        pytorch_model=model,
        base_image='custom-model-image',
        pkgs_to_install=['opencv-python','numpy','six', 'Pillow','wheel',]