Host your deep learning models easily.
Project description
Ventu
Serving the deep learning models easily.
Install
pip install vento
Features
- Only need to implement Model(
inference
,preprocess
,postprocess
) - request & response data check using pydantic
- API document using SpecTree
- backend service using falcon
- dynamic batching with using Unix Domain Socket
- health check
Example
Single Service Demo
source code can be found in single_service_demo.py
from ventu import Ventu
from typing import Tuple
from pydantic import BaseModel
import logging
import numpy
import onnxruntime
# define the input schema
class Input(BaseModel):
text: Tuple[(str,) * 3]
# define the output schema
class Output(BaseModel):
label: Tuple[(bool,) * 3]
class CustomModel(Ventu):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# load model
self.sess = onnxruntime.InferenceSession('./sigmoid.onnx')
self.input_name = self.sess.get_inputs()[0].name
self.output_name = self.sess.get_outputs()[0].name
def preprocess(self, data: Input):
# data format is defined in ``Input``
words = [sent.split(' ')[:4] for sent in data.text]
# padding
words = [word + [''] * (4 - len(word)) for word in words]
# build embedding
emb = [[
numpy.random.random(5) if w else [0] * 5
for w in word]
for word in words]
return numpy.array(emb, dtype=numpy.float32)
def inference(self, data):
# model inference
return self.sess.run([self.output_name], {self.input_name: data})[0]
def postprocess(self, data):
# generate the same format as defined in ``Output``
return {'label': [bool(numpy.mean(d) > 0.5) for d in data]}
if __name__ == "__main__":
logger = logging.getLogger()
formatter = logging.Formatter(fmt='%(asctime)s - %(levelname)s - %(module)s - %(message)s')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
model = CustomModel(Input, Output)
model.run_http(host='localhost', port=8000)
"""
# try with `httpie`
## health check
http :8000/health
## inference
http POST :8000/inference text:='["hello", "world", "test"]'
"""
Dynamic Batching Demo
WIP
Run with Gunicorn
gunicorn -w 2 ventu.app
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ventu-0.2.0.tar.gz
(5.0 kB
view details)
Built Distribution
ventu-0.2.0-py3-none-any.whl
(5.7 kB
view details)
File details
Details for the file ventu-0.2.0.tar.gz
.
File metadata
- Download URL: ventu-0.2.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dd8ae0d6588e3c2400e00d709a049f1e397e5652f08e164524997aa4ec6590f |
|
MD5 | 6ad9447940ce8945cf7b90c2c314b7f6 |
|
BLAKE2b-256 | c4f7401c3e5b78a1de016bfd45687fb5bc7f473f15b9844653fa007e1c1abeb2 |
File details
Details for the file ventu-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: ventu-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef9f11676ff34d367ca088d6d02cd324c6f94a96e39d483bb2a7cfd6785c56d0 |
|
MD5 | 566623e54db9c20babd89344bdb0b13a |
|
BLAKE2b-256 | 5e865394b66984851946d180e3d5681b02cf2ad2f9b2b81bc756dfe48f5d1770 |