Inference
This section will discuss how to make inference calls against your Seldon models or pipelines.
You can make synchronous inference requests via REST or gRPC or asynchronous requests via Kafka topics. The content of your request should be an inference v2 protocol payload:
REST payloads will generally be in the JSON v2 protocol format.
gRPC and Kafka payloads must be in the Protobuf v2 protocol format.
Synchronous Requests
For making synchronous requests, the process will generally be:
Find the appropriate service endpoint (IP address and port) for accessing the installation of Seldon Core 2.
Determine the appropriate headers/metadata for the request.
Make requests via REST or gRPC.
Find the Seldon Service Endpoint
In the default Docker Compose setup, container ports are accessible from the host machine. This means you can use localhost
or 0.0.0.0
as the hostname.
The default port for sending inference requests to the Seldon system is 9000
. This is controlled by the ENVOY_DATA_PORT
environment variable for Compose.
Putting this together, you can send inference requests to 0.0.0.0:9000
.
Make Inference Requests
Let us imagine making inference requests to a model called iris
.
This iris
model has the following schema, which can be set in a model-settings.json
file for MLServer:
Examples are given below for some common tools for making requests.
An example seldon
request might look like this:
The default inference mode is REST, but you can also send gRPC requests like this:
Note: For pipelines, a synchronous request is possible if the pipeline has an outputs
section defined in its spec.
Request Routing
Seldon Routes
Seldon needs to determine where to route requests to, as models and pipelines might have the same name. There are two ways of doing this: header-based routing (preferred) and path-based routing.
Seldon can route requests to the correct endpoint via headers in HTTP calls, both for REST (HTTP/1.1) and gRPC (HTTP/2).
Use the Seldon-Model
header as follows:
For models, use the model name as the value. For example, to send requests to a model named
foo
use the headerSeldon-Model: foo
.For pipelines, use the pipeline name followed by
.pipeline
as the value. For example, to send requests to a pipeline namedfoo
use the headerSeldon-Model: foo.pipeline
.
The seldon
CLI is aware of these rules and can be used to easily send requests to your deployed resources. See the examples and the Seldon CLI docs for more information.
Extending our examples from above, the requests may look like the below when using header-based routing.
No changes are required as the seldon
CLI already understands how to set the appropriate gRPC and REST headers.
Ingress Routes
If you are using an ingress controller to make inference requests with Seldon, you will need to configure the routing rules correctly.
There are many ways to do this, but custom path prefixes will not work with gRPC. This is because gRPC determines the path based on the Protobuf definition. Some gRPC implementations permit manipulating paths when sending requests, but this is by no means universal.
If you want to expose your inference endpoints via gRPC and REST in a consistent way, you should use virtual hosts, subdomains, or headers.
The downside of using only paths is that you cannot differentiate between different installations of Seldon Core 2 or between traffic to Seldon and any other inference endpoints you may have exposed via the same ingress.
You might want to use a mixture of these methods; the choice is yours.
Virtual hosts are a way of differentiating between logical services accessed via the same physical machine(s).
Virtual hosts are defined by the Host
header for HTTP/1 and the :authority
pseudo-header for HTTP/2. These represent the same thing, and the HTTP/2 specification defines how to translate these when converting between protocol versions.
Many tools and libraries treat these headers as special and have particular ways of handling them. Some common ones are given below:
The
seldon
CLI has an--authority
flag which applies to both REST and gRPC inference calls.curl
acceptsHost
as a normal header.grpcurl
has an-authority
flag.In Go, the standard library's
http.Request
struct has aHost
field and ignores attempts to set this value via headers.In Python, the
requests
library accepts the host as a normal header.
Be sure to check the documentation for how to set this with your preferred tools and languages.
Asynchronous Requests
The Seldon architecture uses Kafka and therefore asynchronous requests can be sent by pushing inference v2 protocol payloads to the appropriate topic. Topics have the following form:
Note: If writing to a pipeline topic, you will need to include a Kafka header with the key pipeline
and the value being the name of the pipeline.
Model Inference
For a local install if you have a model iris
, you would be able to send a prediction request by pushing to the topic: seldon.default.model.iris.inputs
. The response will appear on seldon.default.model.iris.outputs
.
For a Kubernetes install in seldon-mesh
if you have a model iris
, you would be able to send a prediction request by pushing to the topic: seldon.seldon-mesh.model.iris.inputs
. The response will appear on seldon.seldon-mesh.model.iris.outputs
.
Pipeline Inference
For a local install if you have a pipeline mypipeline
, you would be able to send a prediction request by pushing to the topic: seldon.default.pipeline.mypipeline.inputs
. The response will appear on seldon.default.pipeline.mypipeline.outputs
.
For a Kubernetes install in seldon-mesh
if you have a pipeline mypipeline
, you would be able to send a prediction request by pushing to the topic: seldon.seldon-mesh.pipeline.mypipeline.inputs
. The response will appear on seldon.seldon-mesh.pipeline.mypipeline.outputs
.
Pipeline Metadata
It may be useful to send metadata alongside your inference.
If using Kafka directly as described above, you can attach Kafka metadata to your request, which will be passed around the graph. When making synchronous requests to your pipeline with REST or gRPC you can also do this.
For REST requests add HTTP headers prefixed with
X-
For gRPC requests add metadata with keys starting with
X-
You can also do this with the Seldon CLI by setting headers with the --header
argument (and also showing response headers with the --show-headers
argument)
For pipeline inference, the response also contains a x-pipeline-version
header, indicating which version of pipeline it ran inference with.
Request IDs
For both model and pipeline requests the response will contain a x-request-id
response header. For pipeline requests this can be used to inspect the pipeline steps via the CLI, e.g.:
The --offset
parameter specifies how many messages (from the latest) you want to search to find your request. If not specified the last request will be shown.
x-request-id
will also appear in tracing spans.
If x-request-id
is passed in by the caller then this will be used. It is the caller's responsibility to ensure it is unique.
The IDs generated are XIDs.
Last updated
Was this helpful?