Skip to content

Triton Inference Server

Interactive Diagram

새 탭 ↗

Background: where serving fits in an ML pipeline

Section titled “Background: where serving fits in an ML pipeline”

This post is a 2021 record of validating model serving with an inference server on Kubernetes. First, here is where serving sits in an ML pipeline.

StageWhat it does
Data PrepIngestion, exploratory data analysis (EDA), transformation, validation, and splitting into training, validation, and test sets
Model CreationTraining and validating the model, then training at scale on more data and GPUs with hyperparameter tuning
Roll outDeploying to production, serving, monitoring accuracy and latency, and logging requests

Serving is the stage that exposes a deployed model as a service. It splits into real-time (online) serving, which answers each request directly, and batch serving, which processes accumulated data in bulk. Triton in this post covers real-time serving; declaring serving through a Kubernetes CRD continues in the KFServing record.

Triton Inference Server is a cloud and edge inference platform optimized for both CPU and GPU workloads. It supports HTTP/REST and gRPC, so remote clients can submit inference requests to any model that the server manages.

  • Features
    • Support for multiple deep-learning frameworks
    • Concurrent model execution
    • Dynamic batching
    • KFServing-compatible protocol support

This post is less about exhaustively reviewing Triton’s feature set and more about validating how to deploy and test Triton in a Kubernetes environment. It also serves as groundwork for model serving with KFServing and for testing InferenceService resources.

On Kubernetes, Triton is usually deployed as a straightforward Deployment and Service pair, but internally it is organized around the following components.

  • Model Repository

    • A filesystem-based repository that stores models for Triton inference. It can be backed by mounted volumes or object storage.
    • When starting Triton Server, point --model-store at the repository directory.
  • Client Request Scheduling / Routing

    • Inference requests can arrive over HTTP/REST, gRPC, or the C API.
    • Requests are internally routed to a scheduler for each model.
    • Triton applies the scheduling and execution logic associated with each model loaded from the model repository.
  • Framework Backends

    • Requests are dispatched to the backend that matches the model framework.
    • The backend performs inference and returns the result.
  • Monitoring

    • Triton exposes readiness, liveness, throughput, and latency metrics that can be integrated with Kubernetes monitoring.
  • Triton High-Level Architecture Triton high-level architecture: HTTP and gRPC requests, model repository, per-model schedulers and backends Source: Triton Inference Server docs, Architecture, NVIDIA Corporation, BSD-3-Clause

Triton Inference Server Github Repository https://github.com/triton-inference-server/server See Triton Inference Server Architecture https://github.com/triton-inference-server/server/blob/main/docs/user_guide/architecture.md

A Helm chart is provided for deploying Triton to AWS EKS. The official guide still mentions Tiller, but this setup was installed with Helm v3 without using that component. By default Triton runs as a Deployment, and high availability is handled by increasing the replica count.

  • Work order
    1. Create an Amazon EKS cluster
    2. Configure an Amazon S3 model repository
    3. Deploy the triton-inference-server Helm chart
    4. Deploy the prometheus-operator Helm chart for monitoring
    5. Configure the Triton SDK client and run inference tests

Triton Inference Server AWS Deploy Guide https://github.com/triton-inference-server/server/tree/main/deploy/aws Triton Quick Start Guide https://github.com/triton-inference-server/server/blob/main/docs/getting_started/quickstart.md

  • Map the AWS Access Key for accessing S3 in values.yaml
  • Modify imageName, modelRepositoryPath, cpu, etc.
  • Create the Service as a LoadBalancer, creating an Amazon Classic Load Balancer
replicaCount: 1
service:
type: LoadBalancer
image:
imageName: nvcr.io/nvidia/tritonserver:21.04-py3
pullPolicy: IfNotPresent
modelRepositoryPath: s3://kloudbank-triton-inference-server-repository/model_repository
# numGpus: 1
numCpus: 1
secret:
...
  • result
Terminal window
$ kubectl get all -n triton
NAME READY STATUS RESTARTS AGE
pod/kloudbank-triton-inference-server-xxxxxxxxxx-xxxxx 1/1 Running 0 39m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kloudbank-triton-inference-server LoadBalancer 10.0.0.35 <External-IP> 8000:31422/TCP,8001:31024/TCP,8002:30129/TCP 3h24m
service/kloudbank-triton-inference-server-metrics ClusterIP 10.0.0.36 <none> 8080/TCP 3h24m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/kloudbank-triton-inference-server 1/1 1 1 3h24m
NAME DESIRED CURRENT READY AGE
replicaset.apps/kloudbank-triton-inference-server-xxxxxxxxxx 1 1 1 3h24m
  • logs
Terminal window
# Framework Backend
I0526 03:39:25.498911 1 server.cc:543]
+-------------+-----------------------------------------------------------------+--------+
| Backend | Path | Config |
+-------------+-----------------------------------------------------------------+--------+
| tensorrt | <built-in> | {} |
| pytorch | /opt/tritonserver/backends/pytorch/libtriton_pytorch.so | {} |
| tensorflow | /opt/tritonserver/backends/tensorflow1/libtriton_tensorflow1.so | {} |
| onnxruntime | /opt/tritonserver/backends/onnxruntime/libtriton_onnxruntime.so | {} |
| openvino | /opt/tritonserver/backends/openvino/libtriton_openvino.so | {} |
+-------------+-----------------------------------------------------------------+--------+
# load the Model from the Model Repository
I0526 03:39:25.498991 1 server.cc:586]
+----------------------+---------+--------+
| Model | Version | Status |
+----------------------+---------+--------+
| densenet_onnx | 1 | READY |
| inception_graphdef | 1 | READY |
| simple | 1 | READY |
| simple_dyna_sequence | 1 | READY |
| simple_identity | 1 | READY |
| simple_int8 | 1 | READY |
| simple_sequence | 1 | READY |
| simple_string | 1 | READY |
+----------------------+---------+--------+
...
# default Service Port (HTTP, GRPC, Metric)
I0526 03:39:25.500218 1 grpc_server.cc:4028] Started GRPCInferenceService at 0.0.0.0:8001
I0526 03:39:25.500467 1 http_server.cc:2761] Started HTTPService at 0.0.0.0:8000
I0526 03:39:25.541702 1 http_server.cc:2780] Started Metrics Service at 0.0.0.0:8002
...

Deploy stable/prometheus to monitor inference requests. When installing it, set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false so Prometheus can discover and scrape Triton’s metrics.

  • Grafana dashboard provided by Triton
    • Inference-processing metrics are tracked separately for each model in the repository (eight models in this example).
    • A scheduling queue is also exposed per model.

See grafana dashboard.json https://github.com/triton-inference-server/server/blob/main/deploy/aws/dashboard.json

Triton can load and serve models only when they follow the required repository directory structure. In this example, an Amazon S3 model repository was populated with the sample models and then used to test inference requests against the Triton server running on EKS.

See triton sample model https://github.com/triton-inference-server/server/tree/main/docs/examples/model_repository

  • Run the triton-inference-server SDK Docker container
Terminal window
docker pull nvcr.io/nvidia/tritonserver:21.04-py3-sdk
docker run -it --rm --net=host nvcr.io/nvidia/tritonserver:21.04-py3-sdk
  • Result of entering the SDK container and running image_client to test an HTTP request
Terminal window
# run densenet_onnx
root@docker-desktop:/workspace# /workspace/install/bin/image_client -m densenet_onnx -c 3 -s INCEPTION -u <External-IP>:8000 /workspace/images/mug.jpg
Request 0, batch size 1
Image '/workspace/images/mug.jpg':
15.349564 (504) = COFFEE MUG
13.227464 (968) = CUP
10.424892 (505) = COFFEEPOT
# run inception_graphdef
root@docker-desktop:/workspace# /workspace/install/bin/image_client -m inception_graphdef -c 3 -s INCEPTION -u <External-IP>:8000 /workspace/images/mug.jpg
Request 0, batch size 1
Image '/workspace/images/mug.jpg':
0.754047 (505) = COFFEE MUG
0.157066 (969) = CUP
0.002878 (968) = ESPRESSO
  • Monitoring results for each processed model