Let's quickly review what we have here. RuntimeManager simply manages our service, i.e. starts it, stops it, and holds all necessary data. RuntimeService is a service that actually implements thePredict(PredictRequest) RPC function.
The model will be stored inside the /model directory in the Docker container. The structure of /model is a follows:
model
├── contract.protobin
└── files
├── ...
└── ...
Thecontract.protobin file will be created by the Manager service. It contains a binary representation of the ModelContract message.
files directory contains all files of your model.
To run this service let's create an another file main.py.
from runtime import RuntimeManager
import os
import time
import logging
logging.basicConfig(level=logging.INFO)
if __name__ == '__main__':
runtime = RuntimeManager('/model', port=int(os.getenv('APP_PORT', "9090")))
runtime.start()
try:
while True:
time.sleep(60 * 60 * 24)
except KeyboardInterrupt:
runtime.stop()
Publish Runtime
Before we can use the runtime, we have to package it into a container.
To add requirements for installing dependencies, create a requirements.txt file and put inside:
grpcio==1.12.1
googleapis-common-protos==1.5.3
Create a Dockerfile to build our image:
FROM python:3.6.5
ADD . /app
RUN pip install -r /app/requirements.txt
ENV APP_PORT=9090
VOLUME /model
WORKDIR /app
CMD ["python", "main.py"]
APP_PORT is an environment variable used by Hydrosphere. When Hydrosphere invokes Predict method, it does so via the defined port.
The structure of the runtime folder should now look like this:
Remember that the registry has to be accessible to the Hydrosphere platform so it can pull the runtime whenever it has to run a model with this runtime.
That's it. You have just created a simple runtime that you can use in your own projects. It is an almost identical version of our python runtime implementation. You can always look up details there.