# onnx/onnx-tensorrt architecture

> Architecture diagram of the GitHub repository onnx/onnx-tensorrt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/onnx/onnx-tensorrt
- Repository: https://github.com/onnx/onnx-tensorrt

## Overview

ONNX-TensorRT parses ONNX models into TensorRT network definitions, which applications can build into engines and execute. The main workflow enters through the C++ parser API, validates and imports graph nodes using operator-specific handlers, and represents tensor shapes and weights in an importer context. Separate capabilities include operator support checks, refitting, external initializer loading, and the Python backend’s engine execution path. Some subsystem links rely on the README or SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`onnxOpImporters.cpp`](https://github.com/onnx/onnx-tensorrt/blob/main/onnxOpImporters.cpp) (Operator Importers), [`ModelImporter.cpp`](https://github.com/onnx/onnx-tensorrt/blob/main/ModelImporter.cpp) (Model Importer), [`onnx_tensorrt/tensorrt_engine.py`](https://github.com/onnx/onnx-tensorrt/blob/main/onnx_tensorrt/tensorrt_engine.py) (Engine Runtime), [`ImporterContext.hpp`](https://github.com/onnx/onnx-tensorrt/blob/main/ImporterContext.hpp) (Importer Context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Parser API"]
  node_parser_api["Parser API<br/>[NvOnnxParser.h]"]
  node_parser_factory["Parser Factory<br/>[NvOnnxParser.cpp]"]
end

subgraph group_import["ONNX Import"]
  node_model_importer["Model Importer<br/>[ModelImporter.cpp]"]
  node_op_checkers["Operator Checks<br/>[onnxOpCheckers.cpp]"]
  node_op_importers["Operator Importers"]
  node_conditional["Control Flow"]
  node_loop_helpers["Loop Helpers<br/>[LoopHelpers.hpp]"]
  node_attention["Attention Helpers"]
  node_rnn["RNN Helpers<br/>[RNNHelpers.cpp]"]
  node_refitter["Model Refitter<br/>[ModelRefitter.cpp]"]
end

subgraph group_internals["Import Internals"]
  node_import_context["Importer Context"]
  node_attributes["ONNX Attributes<br/>[OnnxAttrs.cpp]"]
  node_shape_tensor["Shape Tensors<br/>[ShapeTensor.cpp]"]
  node_tensor_weights["Tensor Or Weights"]
  node_shaped_weights["Shaped Weights<br/>[ShapedWeights.hpp]"]
  node_weights_context["Weights Context<br/>[WeightsContext.cpp]"]
  node_errors["Status And Errors<br/>[Status.hpp]"]
end

subgraph group_runtime["Execution"]
  node_python_backend["Python Backend<br/>[backend.py]"]
  node_engine_runtime["Engine Runtime<br/>[tensorrt_engine.py]"]
end

node_user(("Application"))
node_trt_network["TensorRT Network"]
node_tensorrt["TensorRT"]
node_cuda["CUDA Runtime"]
node_engine_result["Inference Results"]

node_user -->|"requests parsing"| node_parser_api
node_parser_api -->|"creates parser"| node_parser_factory
node_parser_factory -->|"selects importer"| node_model_importer
node_model_importer -->|"checks support"| node_op_checkers
node_model_importer -->|"dispatches operators"| node_op_importers
node_model_importer -->|"writes network"| node_trt_network
node_model_importer -->|"uses context"| node_import_context
node_op_importers -->|"reads attributes"| node_attributes
node_op_importers -->|"uses helpers"| node_conditional
node_op_importers -->|"uses helpers"| node_loop_helpers
node_op_importers -->|"uses helpers"| node_attention
node_op_importers -->|"uses helpers"| node_rnn
node_op_importers -->|"uses shapes"| node_shape_tensor
node_import_context -->|"owns weights"| node_weights_context
node_import_context -->|"tracks values"| node_tensor_weights
node_tensor_weights -->|"represents weights"| node_shaped_weights
node_weights_context -->|"allocates storage"| node_shaped_weights
node_model_importer -->|"reports errors"| node_errors
node_user -->|"requests refit"| node_refitter
node_refitter -->|"uses weights"| node_weights_context
node_user -->|"prepares model"| node_python_backend
node_python_backend -->|"runs engine"| node_engine_runtime
node_engine_runtime -->|"executes engine"| node_tensorrt
node_engine_runtime -->|"allocates and transfers"| node_cuda
node_engine_runtime -->|"returns outputs"| node_engine_result

click node_parser_api "https://github.com/onnx/onnx-tensorrt/blob/main/NvOnnxParser.h"
click node_parser_factory "https://github.com/onnx/onnx-tensorrt/blob/main/NvOnnxParser.cpp"
click node_model_importer "https://github.com/onnx/onnx-tensorrt/blob/main/ModelImporter.cpp"
click node_op_checkers "https://github.com/onnx/onnx-tensorrt/blob/main/onnxOpCheckers.cpp"
click node_op_importers "https://github.com/onnx/onnx-tensorrt/blob/main/onnxOpImporters.cpp"
click node_conditional "https://github.com/onnx/onnx-tensorrt/blob/main/ConditionalHelpers.cpp"
click node_loop_helpers "https://github.com/onnx/onnx-tensorrt/blob/main/LoopHelpers.hpp"
click node_attention "https://github.com/onnx/onnx-tensorrt/blob/main/AttentionHelpers.cpp"
click node_rnn "https://github.com/onnx/onnx-tensorrt/blob/main/RNNHelpers.cpp"
click node_refitter "https://github.com/onnx/onnx-tensorrt/blob/main/ModelRefitter.cpp"
click node_import_context "https://github.com/onnx/onnx-tensorrt/blob/main/ImporterContext.hpp"
click node_attributes "https://github.com/onnx/onnx-tensorrt/blob/main/OnnxAttrs.cpp"
click node_shape_tensor "https://github.com/onnx/onnx-tensorrt/blob/main/ShapeTensor.cpp"
click node_tensor_weights "https://github.com/onnx/onnx-tensorrt/blob/main/TensorOrWeights.hpp"
click node_shaped_weights "https://github.com/onnx/onnx-tensorrt/blob/main/ShapedWeights.hpp"
click node_weights_context "https://github.com/onnx/onnx-tensorrt/blob/main/WeightsContext.cpp"
click node_errors "https://github.com/onnx/onnx-tensorrt/blob/main/Status.hpp"
click node_python_backend "https://github.com/onnx/onnx-tensorrt/blob/main/onnx_tensorrt/backend.py"
click node_engine_runtime "https://github.com/onnx/onnx-tensorrt/blob/main/onnx_tensorrt/tensorrt_engine.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_parser_api,node_parser_factory toneBlue
class node_model_importer,node_op_checkers,node_op_importers,node_conditional,node_loop_helpers,node_attention,node_rnn,node_refitter toneAmber
class node_import_context,node_attributes,node_shape_tensor,node_tensor_weights,node_shaped_weights,node_weights_context,node_errors toneMint
class node_python_backend,node_engine_runtime toneRose
class node_user,node_trt_network,node_tensorrt,node_cuda,node_engine_result toneIndigo
```

## Components

### Parser API

- [Parser API](https://github.com/onnx/onnx-tensorrt/blob/main/NvOnnxParser.h): `NvOnnxParser.h`
- [Parser Factory](https://github.com/onnx/onnx-tensorrt/blob/main/NvOnnxParser.cpp): `NvOnnxParser.cpp`

### ONNX Import

- [Model Importer](https://github.com/onnx/onnx-tensorrt/blob/main/ModelImporter.cpp): `ModelImporter.cpp`
- [Operator Checks](https://github.com/onnx/onnx-tensorrt/blob/main/onnxOpCheckers.cpp): `onnxOpCheckers.cpp`
- [Operator Importers](https://github.com/onnx/onnx-tensorrt/blob/main/onnxOpImporters.cpp): `onnxOpImporters.cpp`
- [Control Flow](https://github.com/onnx/onnx-tensorrt/blob/main/ConditionalHelpers.cpp): `ConditionalHelpers.cpp`
- [Loop Helpers](https://github.com/onnx/onnx-tensorrt/blob/main/LoopHelpers.hpp): `LoopHelpers.hpp`
- [Attention Helpers](https://github.com/onnx/onnx-tensorrt/blob/main/AttentionHelpers.cpp): `AttentionHelpers.cpp`
- [RNN Helpers](https://github.com/onnx/onnx-tensorrt/blob/main/RNNHelpers.cpp): `RNNHelpers.cpp`
- [Model Refitter](https://github.com/onnx/onnx-tensorrt/blob/main/ModelRefitter.cpp): `ModelRefitter.cpp`

### Import Internals

- [Importer Context](https://github.com/onnx/onnx-tensorrt/blob/main/ImporterContext.hpp): `ImporterContext.hpp`
- [ONNX Attributes](https://github.com/onnx/onnx-tensorrt/blob/main/OnnxAttrs.cpp): `OnnxAttrs.cpp`
- [Shape Tensors](https://github.com/onnx/onnx-tensorrt/blob/main/ShapeTensor.cpp): `ShapeTensor.cpp`
- [Tensor Or Weights](https://github.com/onnx/onnx-tensorrt/blob/main/TensorOrWeights.hpp): `TensorOrWeights.hpp`
- [Shaped Weights](https://github.com/onnx/onnx-tensorrt/blob/main/ShapedWeights.hpp): `ShapedWeights.hpp`
- [Weights Context](https://github.com/onnx/onnx-tensorrt/blob/main/WeightsContext.cpp): `WeightsContext.cpp`
- [Status And Errors](https://github.com/onnx/onnx-tensorrt/blob/main/Status.hpp): `Status.hpp`

### Execution

- [Python Backend](https://github.com/onnx/onnx-tensorrt/blob/main/onnx_tensorrt/backend.py): `onnx_tensorrt/backend.py`
- [Engine Runtime](https://github.com/onnx/onnx-tensorrt/blob/main/onnx_tensorrt/tensorrt_engine.py): `onnx_tensorrt/tensorrt_engine.py`

### Other components

- **Application**
- **TensorRT Network**
- **TensorRT**
- **CUDA Runtime**
- **Inference Results**

## Connections

- Application → Parser API: requests parsing (evidence: `README.md`)
- Parser API → Parser Factory: creates parser (evidence: `NvOnnxParser.cpp`)
- Parser Factory → Model Importer: selects importer (evidence: `NvOnnxParser.cpp`)
- Model Importer → Operator Checks: checks support
- Model Importer → Operator Importers: dispatches operators
- Model Importer → TensorRT Network: writes network (evidence: `README.md`)
- Model Importer → Importer Context: uses context
- Operator Importers → ONNX Attributes: reads attributes (evidence: `onnxOpImporters.cpp`)
- Operator Importers → Control Flow: uses helpers (evidence: `onnxOpImporters.cpp`)
- Operator Importers → Loop Helpers: uses helpers (evidence: `onnxOpImporters.cpp`)
- Operator Importers → Attention Helpers: uses helpers (evidence: `onnxOpImporters.cpp`)
- Operator Importers → RNN Helpers: uses helpers (evidence: `onnxOpImporters.cpp`)
- Operator Importers → Shape Tensors: uses shapes (evidence: `onnxOpImporters.cpp`)
- Importer Context → Weights Context: owns weights (evidence: `ImporterContext.hpp`)
- Importer Context → Tensor Or Weights: tracks values (evidence: `ImporterContext.hpp`)
- Tensor Or Weights → Shaped Weights: represents weights (evidence: `TensorOrWeights.hpp`)
- Weights Context → Shaped Weights: allocates storage
- Model Importer → Status And Errors: reports errors (evidence: `ModelImporter.cpp`)
- Application → Model Refitter: requests refit
- Model Refitter → Weights Context: uses weights
- Application → Python Backend: prepares model (evidence: `README.md`)
- Python Backend → Engine Runtime: runs engine (evidence: `onnx_tensorrt/backend.py`)
- Engine Runtime → TensorRT: executes engine (evidence: `onnx_tensorrt/tensorrt_engine.py`)
- Engine Runtime → CUDA Runtime: allocates and transfers (evidence: `onnx_tensorrt/tensorrt_engine.py`)
- Engine Runtime → Inference Results: returns outputs (evidence: `README.md`)
