PureML 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

ORG_ID="<org_id>"
API_ID="<api_id>"
API_KEY="<api_key>"

Once the env file is correctly loaded, you can proceed to create docker using pureml.

import pureml

env_path = "<env_path>"

pureml.docker.create(label='churn classifier:v5',
                     env_path=env_path,
                     access_token=access_token,)

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:

import pureml

pureml.docker.create('flavia_tabnet_classifier:dev_2:v1',
                     org_id=org_id,
                     access_token=access_token,
                     port=<your port number>)

Expected Output

If executed successfully, PureML returns the following message along with the URL where the model is hosted.


Taking the default predict.py file path: <path to predict.py>
Taking the requirements.txt file path: <path to requirements.txt>
FastAPI server files are created
Docker image is created
<Image: '<model name>:<model version>'>
Created Docker container
<Container: <container id>>
Prediction requests can be forwarded to 0.0.0.0:8000/predict

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. PureML obtains the model specified in the pureml.docker.create command and sends it to themodel parameter of the model_predict function.

import requests

params = {'test_data': <test data>}
headers = {'accept': 'application/json'}

response = requests.get('http://0.0.0.0:8000/predict',
                        params=params,
                        headers=headers)

predictions = response.json()

Predictions can be extracted from the json response.

Using Curl

curl -X 'GET'  'http://0.0.0.0:8000/predict?test_data=<test data>' -H 'accept: application/json'

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.

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.