Skip to content

Commit c7c45d1

Browse files
Thiago CrepaldiThiago Crepaldititaiwangms
authored
[ONNX 3] Add ONNX registry tutorial (#2595)
* [ONNX 3] Add ONNX registry tutorial Co-authored-by: Thiago Crepaldi <thiagofc@microsoft.com> Co-authored-by: AllenTiTaiWang <titaiwang@microsoft.com>
1 parent 0bcfce2 commit c7c45d1

14 files changed

+515
-12
lines changed
Loading
7.37 KB
Loading
12.4 KB
Loading
8.41 KB
Loading
22.1 KB
Loading
6.8 KB
Loading

advanced_source/super_resolution_with_onnxruntime.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
(optional) Exporting a Model from PyTorch to ONNX and Running it using ONNX Runtime
33
===================================================================================
44
5-
.. Note::
5+
.. note::
66
As of PyTorch 2.1, there are two versions of ONNX Exporter.
77
8-
* ``torch.onnx.dynamo_export`is the newest (still in beta) exporter based on the TorchDynamo technology released with PyTorch 2.0
9-
* ``torch.onnx.export`` is based on TorchScript backend and has been available since PyTorch 1.2.0
8+
* ``torch.onnx.dynamo_export`is the newest (still in beta) exporter based on the TorchDynamo technology released with PyTorch 2.0.
9+
* ``torch.onnx.export`` is based on TorchScript backend and has been available since PyTorch 1.2.0.
1010
1111
In this tutorial, we describe how to convert a model defined
1212
in PyTorch into the ONNX format using the TorchScript ``torch.onnx.export` ONNX exporter.

beginner_source/onnx/README.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ ONNX
66
https://pytorch.org/tutorials/onnx/intro_onnx.html
77

88
2. export_simple_model_to_onnx_tutorial.py
9-
Export a PyTorch model to ONNX
9+
Exporting a PyTorch model to ONNX
1010
https://pytorch.org/tutorials/beginner/onnx/export_simple_model_to_onnx_tutorial.html
11+
12+
3. onnx_registry_tutorial.py
13+
Extending the ONNX Registry
14+
https://pytorch.org/tutorials/beginner/onnx/onnx_registry_tutorial.html

beginner_source/onnx/export_simple_model_to_onnx_tutorial.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- coding: utf-8 -*-
22
"""
33
`Introduction to ONNX <intro_onnx.html>`_ ||
4-
**Export a PyTorch model to ONNX**
4+
**Exporting a PyTorch model to ONNX** ||
5+
`Extending the ONNX Registry <onnx_registry_tutorial.html>`_
56
67
Export a PyTorch model to ONNX
78
==============================
@@ -104,7 +105,7 @@ def forward(self, x):
104105
export_output.save("my_image_classifier.onnx")
105106

106107
######################################################################
107-
# The ONNX file can be loaded back into memory and checked if it is well formed with the following code:
108+
# You can load the ONNX file back into memory and check if it is well formed with the following code:
108109

109110
import onnx
110111
onnx_model = onnx.load("my_image_classifier.onnx")
@@ -167,9 +168,9 @@ def to_numpy(tensor):
167168

168169
onnxruntime_outputs = ort_session.run(None, onnxruntime_input)
169170

170-
######################################################################
171+
####################################################################
171172
# 7. Compare the PyTorch results with the ones from the ONNX Runtime
172-
# -----------------------------------------------------------------
173+
# ------------------------------------------------------------------
173174
#
174175
# The best way to determine whether the exported model is looking good is through numerical evaluation
175176
# against PyTorch, which is our source of truth.

beginner_source/onnx/intro_onnx.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
**Introduction to ONNX** ||
3-
`Export a PyTorch model to ONNX <export_simple_model_to_onnx_tutorial.html>`_
3+
`Exporting a PyTorch model to ONNX <export_simple_model_to_onnx_tutorial.html>`_ ||
4+
`Extending the ONNX Registry <onnx_registry_tutorial.html>`_
45
56
Introduction to ONNX
67
====================
@@ -32,17 +33,37 @@
3233
Dependencies
3334
------------
3435
36+
PyTorch 2.1.0 or newer is required.
37+
3538
The ONNX exporter depends on extra Python packages:
3639
37-
- `ONNX <https://onnx.ai>`_
38-
- `ONNX Script <https://onnxscript.ai>`_
40+
- `ONNX <https://onnx.ai>`_ standard library
41+
- `ONNX Script <https://onnxscript.ai>`_ library that enables developers to author ONNX operators,
42+
functions and models using a subset of Python in an expressive, and yet simple fashion.
3943
4044
They can be installed through `pip <https://pypi.org/project/pip/>`_:
4145
4246
.. code-block:: bash
4347
4448
pip install --upgrade onnx onnxscript
4549
50+
To validate the installation, run the following commands:
51+
52+
.. code-block:: python
53+
54+
import torch
55+
print(torch.__version__)
56+
57+
import onnxscript
58+
print(onnxscript.__version__)
59+
60+
from onnxscript import opset18 # opset 18 is the latest (and only) supported version for now
61+
62+
import onnxruntime
63+
print(onnxruntime.__version__)
64+
65+
Each `import` must succeed without any errors and the library versions must be printed out.
66+
4667
Further reading
4768
---------------
4869

0 commit comments

Comments
 (0)