Prerequisites
- Working TensorRT-LLM installation
- Understanding of PyTorch and Transformer architectures
- Familiarity with your target model architecture
Overview
Adding a new model involves four main steps:- Model Configuration: Define or reuse HuggingFace configuration
- Model Definition: Implement PyTorch model classes
- Weight Loading: Map weights from source checkpoints
- Model Registration: Register for auto-discovery
Step 1: Model Configuration
If the model is supported in HuggingFace transformers, reuse their config:Step 2: Model Definition
Createmodeling_mymodel.py with the model structure:
Step 3: Weight Loading
Map HuggingFace weights to TensorRT-LLM model:Step 4: Model Registration
Core Models
Add totensorrt_llm/models/automodel.py:
Out-of-Tree Models (Recommended)
Create a separate Python package without modifying TensorRT-LLM:Testing
Test your model implementation:Best Practices
Use TensorRT-LLM Optimized Modules
Use TensorRT-LLM Optimized Modules
Always use TensorRT-LLM’s optimized modules for best performance:
tensorrt_llm._torch.modules.linear.Lineartensorrt_llm._torch.modules.attention.Attentiontensorrt_llm._torch.modules.rms_norm.RMSNorm
Handle Tensor Parallelism
Handle Tensor Parallelism
Use the
Mapping configuration to handle distributed execution automatically.Follow Existing Patterns
Follow Existing Patterns
Study existing models like
modeling_llama.py as reference implementations.Next Steps
Custom Kernels
Learn how to write custom CUDA kernels
Model Configuration
Explore model configuration options