onnx2torch
ONNX to PyTorch converter
What it is and what it does
onnx2torch is a converter that transforms ONNX model files into native PyTorch modules. It accepts either a file path or a loaded ONNX model object and returns a PyTorch nn.Module that can be used directly for inference or training. The converter is designed to be extensible—you can register custom PyTorch layers for unsupported ONNX operations using a decorator pattern, and converted models can be exported back to ONNX using torch.onnx.export.
The package supports a curated set of models including popular segmentation architectures (DeepLabV3+, UNet, HRNet), detection models (YOLOv3, YOLOv5, RetinaNet), classification networks (ResNet, MobileNet, EfficientNet, ViT), and transformers (Swin, GPT-J). However, it covers only a limited number of ONNX operations, so not all ONNX models will convert successfully. The maintainers explicitly encourage users to report unsupported models and operations.
Use it for:
- Convert a pre-trained ONNX model to PyTorch for fine-tuning or inference in a PyTorch-native pipeline.
- Integrate ONNX-exported models from other frameworks into a PyTorch codebase.
- Extend the converter with custom layers to support domain-specific ONNX operations not yet in the core library.
- Validate ONNX model behavior by running inference in PyTorch and comparing outputs against ONNX Runtime.
- Deploy ONNX models trained elsewhere as native PyTorch modules without maintaining separate inference code.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts ONNX models to PyTorch modules with a simple API, supporting a limited but growing set of operations and popular model architectures.
Yes, if you need to convert ONNX models to PyTorch and your model uses supported operations. The package is stable and permissively licensed, with low install friction. However, verify that your specific ONNX model's operations are supported before committing to it—the converter does not support all ONNX operations, and maintenance has slowed. If your model is unsupported, you may need to implement custom converters or consider alternatives.
Install
onnx2torch on PyPI
pip
pip install onnx2torchuv
uv add onnx2torchpoetry
poetry add onnx2torchInstalling onnx2torch
Before you install
Low install friction with a pure Python wheel. Maintenance is aging—last release was over a year ago, though the repository remains active and the project is marked Production/Stable.
License in practice
Apache License 2.0 is permissive; you may use, modify, and distribute this package freely in commercial and private projects provided you include the license and attribute the original work.
Quickstart
pip install onnx2torch
import torch
from onnx2torch import convert
torch_model = convert("/path/to/model.onnx")
output = torch_model(torch.randn(1, 3, 224, 224))
Requires torch and torchvision installed; conversion success depends on whether the ONNX model's operations are in the supported set.
Verify before relying
- Whether all operations in your specific ONNX model are currently supported by this version.
- Performance characteristics of converted models compared to native PyTorch implementations.
- Compatibility with ONNX opset versions beyond those documented in the description.
Package facts
| License | Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 4 — numpy, onnx, torch, torchvision |
| Maintenance | aging — 737 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 225,660/month — #9,216 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: onnx2torch-1.5.15-py3-none-any.whl
Keywords: AI, onnx, torch, onnx2torch, converters
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
pnnxExports and converts PyTorch neural network…
permissive · top 15,000 on PyPI
tf2onnxConverts TensorFlow, Keras, TensorFlow.js, and…
permissive · top 15,000 on PyPI
onnxmltoolsConverts machine learning models from multiple…
permissive · top 5,000 on PyPI
onnx2tfConverts ONNX model files to LiteRT,…
permissive · top 5,000 on PyPI
onnxsimSimplifies ONNX neural network models by…
permissive · top 15,000 on PyPI
onnxconverter-commonProvides common utilities and functions for…
permissive · top 5,000 on PyPI
onnx-graphsurgeonONNX GraphSurgeon lets you programmatically…
permissive · top 15,000 on PyPI
litert-torchConverts PyTorch models to .tflite format for…
permissive · top 15,000 on PyPI
torchprofileCounts multiply-accumulate operations (MACs) in…
permissive · top 15,000 on PyPI
hoptorchProvides a safe wrapper around PyTorch's scan…
permissive · top 15,000 on PyPI