Ventu API¶
-
class
ventu.ventu.Ventu(req_schema, resp_schema, use_msgpack=False, *args, **kwargs)[source]¶ Ventu: built for deep learning model serving
Parameters: - req_schema – request schema defined with
pydantic.BaseModel - resp_schema – response schema defined with
pydantic.BaseModel - use_msgpack (bool) – use msgpack for serialization or not (default: JSON)
- args –
- kwargs –
To create a model service, inherit this class and implement:
preprocess(optional)postprocess(optional)inference(for standalone HTTP service)batch_inference(when working with batching service)
-
app¶ Falcon application with SpecTree validation
-
batch_inference(batch)[source]¶ batch inference the preprocessed data
Parameters: batch – a list of data after preprocessReturns: a list of inference results
-
health_check(batch=False)[source]¶ health check for model inference (can also be used to warm-up)
Parameters: batch (bool) – batch inference or single inference (default) Return bool: Trueif passed health check
-
inference(data)[source]¶ inference the preprocessed data
Parameters: data – data after preprocessReturns: inference result
-
postprocess(data)[source]¶ postprocess the inference result
Parameters: data – data after inferenceor one item of thebatch_inferenceReturns: as defined in resp_schema
-
preprocess(data)[source]¶ preprocess the data
Parameters: data – as defined in req_schemaReturns: this will be the input data of inferenceor one item of the input data ofbatch_inference
-
run_http(host=None, port=None)[source]¶ run the HTTP service
Parameters: - host (string) – host address
- port (int) – service port
-
run_socket(addr=None)[source]¶ run as an inference worker
Parameters: addr (string) – socket file address
-
sock¶ socket used for communication with batching service
this is a instance of
ventu.protocol.BatchProtocol
- req_schema – request schema defined with
Config¶
Check pydantic.BaseSettings
-
class
ventu.config.Config[source]¶ default config, can be rewrite with environment variables begin with
ventu_Variables: - name – default service name shown in OpenAPI
- version – default service version shown in OpenAPI
- host – default host address for the HTTP service
- port – default port for the HTTP service
- socket – default socket file to communicate with batching service
Protocol¶
-
class
ventu.protocol.BatchProtocol(infer, req_schema, resp_schema, use_msgpack)[source]¶ protocol used to communicate with batching service
Parameters: - infer – model infer function (contains preprocess, batch_inference and postprocess)
- req_schema – request schema defined with pydantic
- resp_schema – response schema defined with pydantic
- use_msgpack (bool) – use msgpack for serialization or not (default: JSON)
-
process(conn)[source]¶ process batch queries and return the inference results
Parameters: conn – socket connection
HTTP service¶
-
ventu.service.create_app(infer, health_check, req_schema, resp_schema, use_msgpack, config)[source]¶ create
falconapplicationParameters: - infer – model infer function (contains preprocess, inference, and postprocess)
- health_check – model health check function (need examples provided in schema)
- req_schema – request schema defined with
pydantic.BaseModel - resp_schema – request schema defined with
pydantic.BaseModel - use_msgpack (bool) – use msgpack for serialization or not (default: JSON)
- config – configs
ventu.config.Config
Returns: a
falconapplication