TorchVision Detection Models fail to export to onnx with dynamo=True
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.9k
- Forks
- 7.3k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 13
Description
Description
TorchVision detection models (Faster R-CNN, RetinaNet, etc.) cannot be exported to ONNX using dynamo=True in torch.onnx.export(), while classification models export successfully.
Reproduction
import torch
import torchvision.models as models
model = models.detection.fasterrcnn_resnet50_fpn(weights='DEFAULT')
model.eval()
dummy_input = torch.randn(1, 3, 224,224)
torch.onnx.export(
model,
dummy_input,
"fasterrcnn.onnx",
opset_version=18,
input_names=['input'],
output_names=['output'],
dynamo=True
)
Error
torch.onnx.OnnxExporterError: Failed to export the model with torch.export().
This is step 1/3 of exporting the model to ONNX.
Versions
Collecting environment information...
PyTorch version: 2.7.1+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A
OS: Microsoft Windows 11 Pro (10.0.26100 64-bit)
GCC version: Could not collect
Clang version: Could not collect
CMake version: version 3.31.9
Libc version: N/A
Python version: 3.11.9 (tags/v3.11.9:de54cf5, Apr 2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.26100-SP0
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
CPU:
Name: Genuine Intel(R) 0000
Manufacturer: GenuineIntel
Family: 1
Architecture: 9
ProcessorType: 3
DeviceID: CPU0
CurrentClockSpeed: 1600
MaxClockSpeed: 1600
L2CacheSize: 16384
L2CacheSpeed: None
Revision: None
Versions of relevant libraries:
[pip3] flake8==7.3.0
[pip3] flake8-annotations-complexity==0.1.0
[pip3] flake8-broken-line==1.0.0
[pip3] flake8-bugbear==24.12.12
[pip3] flake8-builtins==2.5.0
[pip3] flake8-class-attributes-order==0.3.0
[pip3] flake8-coding==1.3.2
[pip3] flake8-comprehensions==3.16.0
[pip3] flake8-debugger==4.1.2
[pip3] flake8-docstrings==1.7.0
[pip3] flake8-eradicate==1.5.0
[pip3] flake8-executable==2.1.3
[pip3] flake8-expression-complexity==0.0.11
[pip3] flake8-pep3101==2.1.0
[pip3] flake8-plugin-utils==1.3.3
[pip3] flake8-print==5.0.0
[pip3] flake8-pytest-style==2.1.0
[pip3] flake8-quotes==3.4.0
[pip3] flake8-rst-docstrings==0.3.1
[pip3] flake8-string-format==0.3.0
[pip3] flake8-variables-names==0.0.6
[pip3] mypy==1.16.1
[pip3] mypy_extensions==1.1.0
[pip3] numpy==2.2.6
[pip3] onnx==1.18.0
[pip3] onnxruntime==1.22.1
[pip3] torch==2.7.1
[conda] Could not collect
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided Faster R-CNN reproduction and the torch.onnx.export() entry point using dynamo=True, then compare its failure with a classification model that exports successfully. Trace the torch.export() failure for TorchVision detection models and add coverage for the reported case; done means the reproduction exports successfully to ONNX with the specified settings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-vision, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100