onnx-diagnostic: investigate onnx models¶
onnx-diagnostic helps investigating onnx models, exporting models into onnx. It implements tools used to understand issues.
Source are sdpython/onnx-diagnostic.
Contents
More
Getting started¶
git clone https://github.com/sdpython/onnx-diagnostic.git
cd onnx-diagnostic
pip install -e .
or
pip install onnx-diagnostic
Enlightening Examples¶
Torch Export
Use DYNAMIC or AUTO when exporting if dynamic shapes has constraints
Steel method forward to guess the dynamic shapes (with Tiny-LLM)
Investigate ONNX models
Some Usefuls Tools
import torch
from onnx_diagnostic.helpers import string_type
inputs = (
torch.rand((3, 4), dtype=torch.float16),
[
torch.rand((5, 6), dtype=torch.float16),
torch.rand((5, 6, 7), dtype=torch.float16),
]
)
# with shapes
print(string_type(inputs, with_shape=True))
>>> (T10s3x4,#2[T10s5x6,T10s5x6x7])
import onnx
from onnx_diagnostic.helpers import onnx_dtype_name
itype = onnx.TensorProto.BFLOAT16
print(onnx_dtype_name(itype))
print(onnx_dtype_name(7))
>>> BFLOAT16
>>> INT64
onnx_diagnostic.helpers.max_diff()
, …
The documentation was updated on:
2025-03-27 16:00:46.825026
With the following versions:
numpy: 2.2.4
ml_dtypes: 0.5.1
sklearn: 1.6.1
onnx: 1.18.0
onnxruntime: 1.21.0+cu126
onnxscript: 0.3.0.dev20250301
torch: 2.8.0.dev20250324+cu126
transformers: 4.51.0.dev0
timm: 1.0.14
has_onnxruntime_training: True
Size of the package:
lines chars
ext dir
.py 3558 102940
export 355 10320
reference 1333 38318
torch_export_patches 1115 39993
torch_models 612 19341