Konduit Serving supports data transformations defined by the DataVec vectorization and ETL library.
from konduit import TransformProcessStep, ServingConfigfrom konduit.server import Serverfrom konduit.client import Clientfrom konduit.utils import is_port_in_usefrom pydatavec import Schema, TransformProcessfrom utils import load_java_tpimport numpy as np import randomimport timeimport jsonimport os
DataVec transformations can be defined in Python using the PyDataVec package, which can be installed from PyPi:
pip install pydatavec
Using PyDataVec requires Docker. For Windows 10 Home edition users, note that Docker Toolbox is not supported.
Run the following cell to check that your Docker installation is successful:
!docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
A Schema specifies the structure of your data. In DataVec, a TransformProcess requires the Schema of the data to be specified.
Schema objects have a number of methods that define different data types for columns: add_string_column(), add_integer_column(), add_long_column(), add_float_column(), add_double_column() and add_categorical_column().
In this short example, we append the string two to the end of values in the string column first.
The TransformProcess configuration has to be converted into JSON format to be passed to Konduit Serving.
Configure the step
The TransformProcess can now be defined in the Konduit Serving configuration with a TransformProcessStep. Here, we
configure the inputs and outputs: the schema, column names and data types should be defined here.
declare the TransformProcess using the .transform_process() method.
Note that Schema data types are not defined in the same way as PythonStep data types. See the source for a complete list of supported Schema data types:
NDArray
String
Boolean
Categorical
Float
Double
Integer
Long
Bytes
You should define the Schema data types in TransformProcessStep() as strings.
Configure the server
Configure the Server using ServingConfig to define the port using the http_port argument and data formats using the input_data_type and output_data_type arguments.
The complete configuration is as follows:
Start the server
Configure the client
Create a Client object and specify the port number as an argument:
Inference
Finally, we run the Konduit Serving instance. Recall that the TransformProcessStep() appends a string two to strings in the column first: