Skip to main content

Overview

This guide covers best practices, performance tuning, monitoring, and scaling strategies for production TensorRT-LLM deployments.

Architecture Considerations

Choosing a Backend

PyTorch Backend

Default choice
  • Best compatibility
  • Active development
  • Full feature support
  • Easier debugging

TensorRT Backend

Maximum performance
  • Lowest latency
  • Highest throughput
  • Requires build step
  • Limited to specific models

AutoDeploy Backend

Experimental
  • Automatic optimization
  • On-the-fly quantization
  • Beta stability
Start with PyTorch backend for development and production. Switch to TensorRT backend only if you need absolute maximum performance and your model is supported.

Deployment Patterns

Best for:
  • Low to medium traffic
  • Development/testing
  • Models under 70B parameters on single GPU

Performance Tuning

Memory Management

1

Optimize KV cache allocation

config.yaml
Setting free_gpu_memory_fraction too high may cause OOM errors during traffic spikes.
2

Enable FP8 KV cache

FP8 KV cache requires Hopper GPUs (H100, H200) for best performance.
3

Monitor cache efficiency

Target metrics:
  • Cache hit rate: >50% for similar prompts
  • Free blocks: >10% of max blocks
  • Tokens per block: 32 (default)

Batching Configuration

config.yaml

CUDA Graphs

Enable CUDA graphs for 20-30% latency reduction on decode steps:
CUDA graphs increase memory usage (~500MB per batch size). Reduce batch_sizes if memory-constrained.

Overlap Scheduler

Enable compute/communication overlap (PyTorch backend only):
Overlap scheduler can improve throughput by 10-15% for multi-GPU deployments.

Monitoring and Observability

Metrics to Track

  • Time to First Token (TTFT): Prefill latency
  • Time Per Output Token (TPOT): Decode latency
  • Request throughput: Requests/second
  • Token throughput: Tokens/second
  • Queue time: Time waiting in scheduler
  • GPU utilization: Target >80%
  • GPU memory usage: Monitor for OOM
  • KV cache hit rate: Higher = better efficiency
  • Active requests: Current concurrency
  • Batch sizes: Average batch utilization
  • Request failures: HTTP 5xx errors
  • OOM errors: KV cache exhaustion
  • Timeout errors: Requests exceeding max wait time

Collecting Metrics

OpenTelemetry Integration

Export traces to observability platforms:
Requires OpenTelemetry Collector running. See OpenTelemetry docs for setup.

Scaling Strategies

Vertical Scaling (Single Node)

1

Use tensor parallelism for large models

2

Increase batch size and token limits

3

Enable all optimizations

Horizontal Scaling (Multi-Instance)

Multi-Node Scaling

For models >70B parameters, use multi-node deployment:

Security Best Practices

1

Disable trust_remote_code in production

Only enable --trust_remote_code for models from trusted sources.
2

Use authentication/authorization

Deploy behind API gateway with auth:
3

Rate limiting

4

Input validation

Set reasonable limits:

High Availability

Health Checks

Graceful Shutdown

Kubernetes Deployment

trtllm-deployment.yaml

Troubleshooting

Symptoms: Requests fail with CUDA OOM errorsSolutions:
  1. Reduce max_batch_size or max_num_tokens
  2. Lower free_gpu_memory_fraction to 0.85
  3. Enable FP8 KV cache: kv_cache_config.dtype: fp8
  4. Disable CUDA graphs if enabled
  5. Use tensor parallelism for larger models
Symptoms: TTFT or TPOT higher than expectedSolutions:
  1. Enable CUDA graphs: use_cuda_graph: true
  2. Enable overlap scheduler (PyTorch): enable_overlap_scheduler: true
  3. Increase max_num_tokens to allow larger batches
  4. Check GPU utilization (should be >80%)
  5. Reduce tokens_per_block to 16 for short requests
Symptoms: Requests/second below expectationsSolutions:
  1. Increase max_batch_size
  2. Enable KV cache reuse: enable_block_reuse: true
  3. Use async generation: generate_async()
  4. Check queue time in metrics (should be less than 100ms)
  5. Scale horizontally with load balancer
Symptoms: Server fails to start, model download issuesSolutions:
  1. Check HuggingFace token: huggingface-cli login
  2. Pre-download model: huggingface-cli download <model>
  3. Verify disk space (models can be 50GB+)
  4. Check model compatibility with backend
  5. Enable --trust_remote_code if using custom model code

Performance Checklist

1

Choose optimal backend

✅ PyTorch for compatibility, TensorRT for max performance
2

Configure KV cache

✅ free_gpu_memory_fraction: 0.95 ✅ enable_block_reuse: true ✅ dtype: fp8 (on Hopper GPUs)
3

Set batch limits

✅ max_batch_size: 256 (adjust for GPU memory) ✅ max_num_tokens: 16384
4

Enable optimizations

✅ CUDA graphs ✅ Overlap scheduler (PyTorch) ✅ Dynamic batching
5

Monitor metrics

✅ GPU utilization >80% ✅ KV cache hit rate >50% ✅ Queue time less than 100ms
6

Scale appropriately

✅ Tensor parallelism for large models ✅ Horizontal scaling for high traffic ✅ Load balancer for multi-instance

Next Steps

Distributed Inference

Multi-GPU and multi-node deployments

Benchmarking

Measure and optimize performance

Reference Configs

170+ optimized configurations

API Reference

Complete configuration reference