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.
- 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.
models/
resnet/
config.pbtxt
1/model.onnx
2/model.onnx
tokenizer/
config.pbtxt
1/model.pyname: "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.
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 responsesThe 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.
dynamic_batching {
max_queue_delay_microseconds: 2000
}
instance_group [
{ count: 2, kind: KIND_GPU, gpus: [ 0 ] }
]- Instance groups run several copies of a model so one can compute while another copies data;
KIND_CPUplaces a model on CPU instead. - Leave
preferred_batch_sizeunset 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.
perf_analyzer -m resnet -u localhost:8001 -i grpc \
--concurrency-range 1:16:4 \
--percentile 95| Metric | Watch for |
|---|---|
nv_inference_request_success / _failure | Request rate and errors per model |
nv_inference_queue_duration_us | Time waiting for an instance: rising means add instances or GPUs |
nv_inference_compute_infer_duration_us | Pure model time: rising means a slower model or GPU contention |
nv_inference_pending_request_count | Requests waiting right now, a good autoscaling signal |
nv_gpu_utilization, nv_gpu_memory_used_bytes | Headroom 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.