Torch-TensorRT AOT Backend Guide
Torch-TensorRT AOT Backend Guide
The Torch-TensorRT AOT (Ahead-Of-Time) backend exports models with torch.export.export(), compiles the exported program with torch_tensorrt.dynamo.compile(), and saves the compiled model for later use. This approach is ideal for production deployments where compilation happens once during tuning.
Overview
- AOT Compilation: Compiles during tuning, not at runtime
- Model Persistence: Compiled model is saved and loaded
- Fast Startup: No compilation overhead at inference time
- Production Ready: Deterministic performance
- Dynamo Export Path: Uses
torch.exportand the Torch-TensorRT Dynamo frontend
Quick Start
Configuration Options
TorchTensorRTAotBackendConfig
compile_config
Compilation settings:
By default, the engine matches the model’s loaded dtype. To request FP16 kernels via the legacy weak-typing path (deprecated in TensorRT 10.12), pair enabled_precisions with use_explicit_typing=False:
pickle_protocol
Protocol for saving compiled model:
AOT vs JIT Comparison
For a detailed explanation of JIT vs AOT backends, see the JIT vs AOT Torch-TensorRT section.
Best Practices
- Use Representative Data: Tune with inputs that match production shapes and dtypes
- Verify After Load: Test loaded model before deployment
- Version Control: Track both source code and .ait files
- GPU Compatibility: Compile on the same or a compatible GPU as deployment
Troubleshooting
Issue: Load fails on different GPU
Cause: Engine compiled for different GPU architecture.
Solution: Recompile on target GPU or use hardware compatibility level in TensorRT backend.
Next Steps
- Learn about TorchTensorRT JIT Backend
- Explore Deployment Guide
- Review TensorRT Backend for more options