Customize Model Service Docker images

Brief introduction

Xiaomi CLOUD-ML supports the Bring Your Own image feature, using the same method as Customizing Model Service Docker Images.

Usage example

When creating a Model Service, the user only has to specify the Docker image address.

cloudml models create -n linear -v v1 -u fds://cloud-ml/linear -d cloudml/tensorflow:1.0.0

Customize images

If a customized image is needed, we package the startup of the Model Service container. The user-built Docker image must comply with certain conventions, and it is also best to publish the image to a public network to enable anonymous downloading.

Below is the Docker image startup command. It will import the AKSK and FDS endpoints as environment variables, together with the mount GPU-related device directory. The operating parameters are as follows.

"/model_service.py", model_service.model_name, model_service.model_uri, model_service.model_version

The simplest image has only one file, compiled locally as model_service.py. Note that executable permissions must be added to chmod +x.

#!/usr/bin/env python

import SimpleHTTPServer
import SocketServer

def main():
  PORT = 9000
  Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
  httpd = SocketServer.TCPServer(("", PORT), Handler)
  print "serving at port", PORT
  httpd.serve_forever()

if __name__ == "__main__":
  main()

Then, to compile the Dockerfile, you need only ensure that the dependencies required by the model_service.py are installed. Official images based on Xiaomi Cloud-ML can achieve faster download sppeds but are not required.

FROM cloud-ml/dev-tensorflow-cpu:0.12.0-xm1.0.0

ADD ./model_service.py /

EXPOSE 9000

CMD /model_service.py

We can then build this container image locally.

sudo docker build -t cloudml/http_model_service .

Now, the local model service actually handles the parameters and tests the commands as follows. Then, it accesses the local 9000 ports to see if the service is normal.

sudo docker run -it -p 9000:9000 cloudml/http_model_service "/model_service.py" "mymodel" "fds://foo/bar" "v1"

Parameters introduction

  • -d indicates the Docker image address specified by the user. Note that it cannot be used simultaneously with the -F and -V parameters.