Investigate ONNX models
Project description
The main feature is about patches: it helps exporting pytorch models into ONNX, mostly designed for LLMs using dynamic caches.
with bypass_export_some_errors(patch_transformers=True) as f:
ep = torch.export.export(model, args, kwargs=kwargs, dynamic_shapes=dynamic_shapes)
# ...
It also implements tools to investigate, validate exported models (ExportedProgramm, ONNXProgram, …). See documentation of onnx-diagnostic and bypass_export_some_errors.
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
Snapshot of usefuls tools
string_type
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])
onnx_dtype_name
import onnx
from onnx_diagnostic.helpers.onnx_helper import onnx_dtype_name
itype = onnx.TensorProto.BFLOAT16
print(onnx_dtype_name(itype))
print(onnx_dtype_name(7))
>>> BFLOAT16 >>> INT64
max_diff
Returns the maximum discrancies across nested containers containing tensors.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file onnx_diagnostic-0.4.0-py3-none-any.whl.
File metadata
- Download URL: onnx_diagnostic-0.4.0-py3-none-any.whl
- Upload date:
- Size: 232.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9497899d5bb160e9dce0d5b8d5d12e4ca9136a90a30784f06c795b03834e0014
|
|
| MD5 |
c9c92ea944fde1cf569cd665039be974
|
|
| BLAKE2b-256 |
73e68583efd410e2f7bce66401cb00c5388e864707453c16487d40fe403be33b
|