Skip to main content

Overview

The trtllm-serve command starts an OpenAI-compatible server that supports REST and gRPC endpoints. It provides the simplest way to deploy TensorRT-LLM models in production with minimal configuration.
trtllm-serve supports all three backends: PyTorch (default), TensorRT, and AutoDeploy.

Quick Start

Start a server with a HuggingFace model:
The server will start on localhost:8000 by default.

Command-Line Options

Basic Configuration

string
required
Model path or HuggingFace model name (e.g., meta-llama/Llama-3.1-8B-Instruct)
string
default:"localhost"
Server hostname
int
default:"8000"
Server port
string
default:"pytorch"
Inference backend: pytorch, tensorrt, or _autodeploy

Parallelism Configuration

int
default:"1"
Tensor parallelism size (split model across GPUs)
int
default:"1"
Pipeline parallelism size (split layers across GPUs)
int
Expert parallelism size for MoE models

Performance Tuning

int
default:"256"
Maximum number of concurrent requests
int
default:"8192"
Maximum tokens across all requests in a batch
int
Maximum sequence length (prompt + generation). Auto-detected from model config if not specified.
float
default:"0.9"
Fraction of GPU memory to use for KV cache

OpenAI-Compatible Endpoints

The server exposes these OpenAI-compatible endpoints:

Chat Completions

Text Completions

Streaming Responses

Advanced Configuration with YAML

For complex configurations, use a YAML file with --config:
config.yaml
Start the server with the config:
The YAML file mirrors the structure of TorchLlmArgs. All nested configuration classes can be specified.

Multi-Node Deployment with Slurm

Deploy large models across multiple nodes using Slurm:
trtllm-llmapi-launch is a wrapper script that handles MPI initialization for multi-node deployments.

gRPC Server Mode

For high-performance use cases with external routers (e.g., sgl-router), use gRPC mode:
gRPC mode accepts pre-tokenized inputs and returns raw token IDs. It does not support --tool_parser, --chat_template, or disaggregated serving.

Monitoring and Metrics

Health Endpoint

Metrics Endpoint

Enable performance metrics in your config:
Query runtime statistics:
Metrics are stored in a queue and removed once retrieved. Poll regularly if you need to retain metrics.

Custom Tokenizers

Use custom tokenizers for specialized models:
Or specify a Python import path:

Multimodal Models

For vision-language models (VLMs), disable KV cache reuse:
vlm-config.yaml
Send multimodal requests:

Production Best Practices

1

Use YAML configuration files

Store configurations in version-controlled YAML files instead of long command lines.
2

Enable KV cache reuse

Set enable_block_reuse: true in kv_cache_config for improved throughput with repetitive prompts.
3

Tune batch size and token limits

Adjust max_batch_size and max_num_tokens based on your GPU memory and workload.
4

Monitor metrics

Enable enable_iter_perf_stats and poll /metrics to track GPU utilization and KV cache efficiency.
5

Use custom model names

Specify --served_model_name to expose a user-friendly model name in the API instead of the path.

Next Steps

LLM API

Use the Python LLM API for programmatic access

Distributed Inference

Scale to multi-GPU and multi-node deployments

Production Guide

Best practices for production deployments

Disaggregated Serving

Optimize TTFT and TPOT independently