Docker
SuperAlign uses Docker-py to create containers for the models.
Installing Prerequisites
Before you start creating the container for your model, install the following clients on your machine. If not explicitly specified, use the latest available version of the specified components.
Download docker
Docker Engine is an open source containerization technology for building and containerizing your applications.
To use GPU for the container, you need GPU to be installed in your system. Follow steps from below link and get ready for packaging:
Download container toolkit
NVIDIA container toolkit is a wrapper around a docker container to provide access to system GPUs for the container.
Create your prediction function
Refer to Prediction Section on to how to create a prediction function and add it to a version of a model.
Creating Docker Container
Creating a docker container is way too easy to package your updated data than you think.
Create a .env
file
Once the env file is correctly loaded, you can proceed to create docker using pureml
.
Changing the port number
By default pureml host container on 0.0.0.0:8000
. If that port is already in use, the below command can be explicitly provided to change port to your custom port:
Expected Output
If executed successfully, SuperAlign returns the following message along with the URL where the model is hosted.
The model is hosted at 0.0.0.0:8000/predict
. Users can get predictions by sending get requests to the API.
Sending Requests to the API
Using Requests
The API call expects a parameter named test_data
that contains data to be tested. This data
will be passed on to the data parameter set in the model_predict
function. SuperAlign obtains the model specified in the pureml.docker.create
command and sends it to themodel parameter of the model_predict
function.
Predictions can be extracted from the json response.
Using Curl
Accepted Input and Output types
The description of input and output data types is required to create the docker container. Here is the list of available data types:
Input datatypes
The JSON data received by the API endpoint will convert the data into the required datatype specified by the user. For the image data type, API will load the received file though pillow library and convert it into a numpy ndarray before passing it into the prediction function.
- Numpy array: ‘numpy ndarray’
- Pandas dataframe: ‘pandas dataframe’
- string: ‘text
- Image: ‘image’
Output datatypes
The model output will be converted into a JSON string and returned to the user upon an API call. Here are the supported output datatypes.
- Numpy array: ‘numpy ndarray
- Pandas dataframe: ‘pandas dataframe
- string: ‘text