Skip to main content
This guide provides a step-by-step process for adding a new model architecture to TensorRT-LLM’s PyTorch backend.

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:
  1. Model Configuration: Define or reuse HuggingFace configuration
  2. Model Definition: Implement PyTorch model classes
  3. Weight Loading: Map weights from source checkpoints
  4. Model Registration: Register for auto-discovery

Step 1: Model Configuration

If the model is supported in HuggingFace transformers, reuse their config:
For new models, create a configuration class:

Step 2: Model Definition

Create modeling_mymodel.py with the model structure:

Step 3: Weight Loading

Map HuggingFace weights to TensorRT-LLM model:

Step 4: Model Registration

Core Models

Add to tensorrt_llm/models/automodel.py:
Create a separate Python package without modifying TensorRT-LLM:
Use it:

Testing

Test your model implementation:

Best Practices

Always use TensorRT-LLM’s optimized modules for best performance:
  • tensorrt_llm._torch.modules.linear.Linear
  • tensorrt_llm._torch.modules.attention.Attention
  • tensorrt_llm._torch.modules.rms_norm.RMSNorm
Use the Mapping configuration to handle distributed execution automatically.
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