Exporter Recipes Gallery¶
A model can be converted to ONNX if torch.export.export()
is
able to convert that model into a graph. This is not always
possible but usually possible with some code changes.
These changes may not be desired as they may hurt the performance
and make the code more complex than it should be.
The conversion is a necessary step to be able to use
ONNX. Next examples shows some recurrent code patterns and
ways to rewrite them so that the exporter works.
See Exporter Recipes for an organized version of this gallery.
A couple of examples to illustrate different implementation of dot product (see also sphinx-gallery).
Getting started¶
pytorch nightly build should be installed, see Start Locally.
git clone https://github.com/sdpython/experimental-experiment.git
pip install onnxruntime-gpu pynvml
pip install -r requirements-dev.txt
export PYTHONPATH=$PYTHONPATH:<this folder>
Common Errors¶
Some of them are exposed in the examples. Others may be found at Frequent Exceptions or Errors with the Exporter.
A few tricks about dynamic shapes
Export a model using a custom type as input
Linear Regression and export to ONNX
Measures the exporter success on many test cases
to_onnx and a custom operator inplace
to_onnx and a custom operator registered with a function
to_onnx and a model with a loop (scan)
to_onnx and a model with a test
to_onnx and submodules from LLMs
torch.onnx.export and a model with a test