If none of the provided model deployers meet your needs, you will need to create your own model container. In this tutorial, we will walk through two common use cases for creating your own model containers.
If the only reason you cannot use one of the pre-existing model deployers is because your function relies on custom Python packages that cannot be installed via pip, creating a custom model container is straightforward. You will create a new Docker image to serve as the base image for the Python closure deployer. To create this image, create a Dockerfile with the following contents.
First, start with the Python deployers base image as the base image for your new Docker image:
Next, install the custom Python packages into the Docker container. If they are local modules that need to be copied, use the COPY command. If you need to download or compile anything, use the RUN command.
For example, to create a custom model container for Python 3.6 that includes some local Python modules, you would write the following Dockerfile:
FROM clipper/python36-closure-container:0.3 # Create a directory to copy the local module into RUN mkdir -p /python-deps # Copy the module from your local filesystem into the Docker image COPY /path/to/local/module /python-deps/ # Add the module to your PYTHONPATH so the Python interpreter # can find it ENV PYTHONPATH="$PYTHONPATH:/python-deps/
Once you have create the Dockerfile, you must build it to create a Docker image. From the directory where the Dockerfile is saved, run the following command:
docker build -t custom-model-image .
All files referenced in COPY or ADD commands must be inside the context of the build command, and that it will recursively copy entire directory trees.
Once you’ve successfully built your custom base image, specify it as the base image in
the Python closure deployer. For example, to use your custom base image to deploy a
Python function called
myfunc as a model
named “custom-model” with version 1 that takes strings as input, you would issue the following command:
deploy_python_closure(clipper_conn, "custom-model", 1, "strings", myfunc, base_image='custom-model-image')
If you want to be able to use the Docker image on other machines, push it to a Docker registry
docker push command.
If your prediction function cannot be pickled, you will need to explicitly package the function in the container.