Education › OSS Deep Dives › Stage 4: LLM inference infrastructure

NVIDIA Triton Inference Server

The model repository, backends, dynamic batching, ensembles and model analyzer — serving many frameworks behind one API.

Advanced ~35 min read Module 9 of 10

Most companies serve more than one kind of model: an image classifier exported to ONNX, a recommender in PyTorch, a gradient-boosted tree, a tokenizer in Python, and an LLM. NVIDIA Triton Inference Server, open source in triton-inference-server/server and now branded by NVIDIA as Dynamo-Triton, serves all of them behind one HTTP and gRPC API, with batching and concurrency handled for you. This lesson covers the model repository, backends, dynamic batching and instance groups, ensembles and Python business logic, and how to measure and tune with Perf Analyzer and Model Analyzer.

After this module you can
  • Lay out a model repository with versions and a config.pbtxt
  • Pick backends and run several frameworks in one server
  • Raise GPU throughput with dynamic batching and instance groups
  • Chain pre-processing, model and post-processing with an ensemble or Python BLS
  • Measure latency and throughput and choose a configuration with the analyzer tools

The model repository

Triton serves whatever is in its model repository: a directory (local, or object storage such as S3, GCS or Azure Blob) with one folder per model, numbered version sub-folders holding the model files, and an optional config.pbtxt describing the model in protobuf text format.

Two models, one with two versions
text
models/
  resnet/
    config.pbtxt
    1/model.onnx
    2/model.onnx
  tokenizer/
    config.pbtxt
    1/model.py
resnet/config.pbtxt
text
name: "resnet"
backend: "onnxruntime"
max_batch_size: 32
input [
  { name: "input", data_type: TYPE_FP32, dims: [ 3, 224, 224 ] }
]
output [
  { name: "logits", data_type: TYPE_FP32, dims: [ 1000 ] }
]
version_policy: { latest: { num_versions: 1 } }

max_batch_size above zero tells Triton the first dimension is a batch dimension it may fill. The version policy decides which versions are served: the latest N, all, or a specific list. The model control mode decides how changes are picked up: none loads everything at start, poll watches the repository and reloads changed models, and explicit loads and unloads only on API calls, which is what you want when a deployment pipeline controls rollouts.

Backends: many frameworks, one server

A backend is the plugin that actually executes a model. Triton ships or supports backends for TensorRT, ONNX Runtime, PyTorch, OpenVINO, Python, RAPIDS FIL for tree models, TensorRT-LLM and vLLM, and you can write your own in C++ or Python. Each model's config.pbtxt names its backend, so one server process can run an ONNX vision model, a PyTorch ranker and a Python tokenizer side by side, sharing GPUs.

The Python backend runs a model.py that defines a TritonPythonModel class with initialize, execute and finalize. It is ideal for pre- and post-processing, or for models in libraries that have no dedicated backend.

tokenizer/1/model.py: a minimal Python backend model
python
import numpy as np
import triton_python_backend_utils as pb_utils


class TritonPythonModel:
    def initialize(self, args):
        self.vocab = {"hello": 1, "world": 2}

    def execute(self, requests):
        responses = []
        for request in requests:
            text = pb_utils.get_input_tensor_by_name(request, "TEXT").as_numpy()
            words = text[0].decode().lower().split()
            ids = np.array([[self.vocab.get(w, 0) for w in words]], dtype=np.int64)
            out = pb_utils.Tensor("IDS", ids)
            responses.append(pb_utils.InferenceResponse(output_tensors=[out]))
        return responses
Note

The server speaks the KServe v2 inference protocol: HTTP on port 8000, gRPC on 8001, Prometheus metrics on 8002. Health checks are /v2/health/live and /v2/health/ready, and inference is a POST to /v2/models/NAME/infer.

Throughput: dynamic batching and instance groups

GPUs are far more efficient on a batch of 16 than on 16 requests of one. The dynamic batcher holds incoming requests for a very short time and combines them into larger batches before calling the model. max_queue_delay_microseconds caps how long a request may wait, which is the lever between latency and throughput.

Batch up to 32, wait at most 2 ms, run two copies on GPU 0
text
dynamic_batching {
  max_queue_delay_microseconds: 2000
}
instance_group [
  { count: 2, kind: KIND_GPU, gpus: [ 0 ] }
]
requestsbatchesClientsHTTP :8000, gRPC :8001Dynamic batcherper-model queueONNX Runtime2 GPU instancesPython backendpre/post, BLSvLLM backendLLM
Triton puts a scheduler and dynamic batcher in front of every model, so concurrent requests are grouped into batches and run on whichever backend the model's config names.
  • Instance groups run several copies of a model so one can compute while another copies data; KIND_CPU places a model on CPU instead.
  • Leave preferred_batch_size unset unless the model performs much better at specific sizes, such as a TensorRT engine built for them.
  • The sequence batcher handles stateful models where all requests of one sequence must go to the same instance.
  • The response cache can return stored results for identical requests, useful for deterministic models with repeated inputs.

Pipelines: ensembles and BLS

Real requests often need several steps: decode an image, run a detector, crop, run a classifier, format the answer. An ensemble is a model whose config.pbtxt declares a fixed graph of other models and how outputs map to inputs; Triton runs the steps server-side without round trips to the client. When the flow needs logic, such as loops, conditionals or calling a model only if a score is high, Business Logic Scripting (BLS) lets a Python backend model call other models in the same server.

For LLMs, Triton is usually paired with an LLM-specific backend (TensorRT-LLM or vLLM) that handles in-flight batching and the KV cache, while Triton contributes the protocol, metrics, multi-model hosting and pre- and post-processing. If you serve only LLMs, a dedicated engine or a distributed framework such as Dynamo (next lesson) may be simpler.

Measure, then tune

Perf Analyzer (perf_analyzer, in the SDK container) sends load at chosen concurrency levels and reports throughput and latency percentiles, including how much time requests spent queued versus computing. Model Analyzer automates the search: it tries combinations of batch sizes, instance counts and batching delays and recommends configurations that meet your latency or memory constraints.

Throughput and latency at concurrency 1 to 16
bash
perf_analyzer -m resnet -u localhost:8001 -i grpc \
  --concurrency-range 1:16:4 \
  --percentile 95
MetricWatch for
nv_inference_request_success / _failureRequest rate and errors per model
nv_inference_queue_duration_usTime waiting for an instance: rising means add instances or GPUs
nv_inference_compute_infer_duration_usPure model time: rising means a slower model or GPU contention
nv_inference_pending_request_countRequests waiting right now, a good autoscaling signal
nv_gpu_utilization, nv_gpu_memory_used_bytesHeadroom for more instances or models

Divide nv_inference_count (inferences) by nv_inference_exec_count (model executions) to get the average batch size actually achieved; if it stays near 1 under load, batching is not happening and your config or client is the reason.

Hands-on practice

Serve two frameworks and watch batching work

  1. Clone the server repository at the release branch matching the container you will use, and run docs/examples/fetch_models.sh to download the example models.
  2. Start the matching tritonserver container with the example model repository mounted at /models (add --gpus=1 if you have a GPU; the quickstart also covers CPU-only).
  3. Check readiness with curl localhost:8000/v2/health/ready and list models with a POST to /v2/repository/index.
  4. Add the Python tokenizer model from this lesson with a config.pbtxt declaring a TEXT string input and an IDS output, and call it over HTTP.
  5. Run perf_analyzer against an image model at concurrency 1 and 16 and note throughput and p95 latency.
  6. Add dynamic_batching { max_queue_delay_microseconds: 2000 }, reload, rerun, and compare; compute average batch size from nv_inference_count over nv_inference_exec_count.
  7. Stop the containers when you are done.
Cheat sheet

NVIDIA Triton Inference Server — at a glance

Main things to focus on

  • Model repository: model folder, numbered versions, config.pbtxt.
  • One server, many backends: ONNX, PyTorch, TensorRT, Python, FIL, vLLM, TensorRT-LLM.
  • Dynamic batching trades a little queue delay for much higher GPU throughput.
  • Instance groups run multiple copies to overlap compute and data movement.
  • Ensembles for fixed graphs, Python BLS for pipelines with logic.
  • Queue time rising means add capacity; compute time rising means a slower model.

Server

tritonserver --model-repository=/modelsStart with a local or s3:// repository
--model-control-mode=explicit --load-model=NAMELoad only what you ask for
--model-control-mode=poll --repository-poll-secs=30Reload changed models automatically
8000 / 8001 / 8002HTTP / gRPC / metrics ports
GET /v2/health/readyReadiness probe

config.pbtxt

backend: "onnxruntime"Which backend executes the model
max_batch_size: 32Enable batching on the first dimension
dynamic_batching { max_queue_delay_microseconds: 2000 }Batch requests, wait at most 2 ms
instance_group [{ count: 2, kind: KIND_GPU }]Run two copies per GPU
version_policy: { latest: { num_versions: 1 } }Serve only the newest version

Inference API

POST /v2/models/NAME/inferRun inference (KServe v2 protocol)
GET /v2/models/NAME/configThe effective model configuration
POST /v2/repository/models/NAME/loadLoad or reload a model in explicit mode

Tools and metrics

perf_analyzer -m NAME --concurrency-range 1:16:4Load test a model
model-analyzer profile --model-repository /models --profile-models NAMESearch for the best config
nv_inference_queue_duration_usTime spent waiting for an instance
nv_inference_count / nv_inference_exec_countAverage achieved batch size

Common pitfalls

  • Setting max_batch_size to 0 and wondering why dynamic batching never batches.
  • A long max_queue_delay that quietly adds latency to every request at low traffic.
  • Poll mode in production, so a half-copied model file gets loaded mid-upload.
  • Doing pre-processing on the client and shipping huge raw tensors over the network.
  • Tuning by intuition instead of Perf Analyzer and Model Analyzer runs.
Quiz

Check your understanding

5 questions · 4 to pass · answers are explained as you go. Your best score is saved on this device only.

Progress and quiz scores are saved in this browser only. Back up or restore on the hub.

Was this lesson useful? Tell me what to improve →