Skip to content

Commit c0bcbaa

Browse files
author
Thiago Crepaldi
committed
Add Backends section to Tutorials left menu
This PR adds a `Backends` section to the left menu which initially will initially contain a placeholder for the series of ONNX export tutorials based on Torch Dynamo backend A table of content tree page will have static URL https://pytorch.org/tutorials/beginner/onnx/intro_onnx.html that will be referenced on PyTorch user document for torch.onnx module
1 parent e28eace commit c0bcbaa

File tree

6 files changed

+78
-8
lines changed

6 files changed

+78
-8
lines changed

.jenkins/validate_tutorials_built.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
NOT_RUN = [
1212
"beginner_source/basics/intro", # no code
13+
"beginner_source/onnx/intro_onnx",
1314
"beginner_source/translation_transformer",
1415
"beginner_source/profiler",
1516
"beginner_source/saving_loading_models",

_templates/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
</noscript>
108108

109109
<script type="text/javascript">
110-
var collapsedSections = ['PyTorch Recipes', 'Learning PyTorch', 'Image and Video', 'Audio', 'Text', 'Reinforcement Learning', 'Deploying PyTorch Models in Production', 'Code Transforms with FX', 'Frontend APIs', 'Extending PyTorch', 'Model Optimization', 'Parallel and Distributed Training', 'Mobile'];
110+
var collapsedSections = ['PyTorch Recipes', 'Learning PyTorch', 'Image and Video', 'Audio', 'Text', 'Backends', 'Reinforcement Learning', 'Deploying PyTorch Models in Production', 'Code Transforms with FX', 'Frontend APIs', 'Extending PyTorch', 'Model Optimization', 'Parallel and Distributed Training', 'Mobile'];
111111
</script>
112112

113113
<img height="1" width="1" style="border-style:none;" alt="" src="https://www.googleadservices.com/pagead/conversion/795629140/?label=txkmCPmdtosBENSssfsC&amp;guid=ON&amp;script=0"/>

beginner_source/onnx/README.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ONNX
2+
----
3+
4+
1. intro_onnx.py
5+
Introduction to ONNX
6+
https://pytorch.org/tutorials/onnx/intro_onnx.html
7+

beginner_source/onnx/intro_onnx.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
**Introduction to ONNX**
3+
4+
Introduction to ONNX
5+
====================
6+
7+
Authors:
8+
`Thiago Crepaldi <https://github.com/thiagocrepaldi>`_,
9+
10+
`Open Neural Network eXchange (ONNX) <https://onnx.ai/>`_ is an open standard
11+
format for representing machine learning models. The ``torch.onnx`` module provides APIs to
12+
capture the computation graph from a native PyTorch :class:`torch.nn.Module` model and convert
13+
it into an `ONNX graph <https://github.com/onnx/onnx/blob/main/docs/IR.md>`_.
14+
15+
The exported model can be consumed by any of the many
16+
`runtimes that support ONNX <https://onnx.ai/supported-tools.html#deployModel>`_,
17+
including Microsoft's `ONNX Runtime <https://www.onnxruntime.ai>`_.
18+
19+
.. note::
20+
Currently, there are two flavors of ONNX exporter APIs,
21+
but this tutorial will focus on the ``torch.onnx.dynamo_export``.
22+
23+
The TorchDynamo engine is leveraged to hook into Python's frame evaluation API and dynamically rewrite its
24+
bytecode into an `FX graph <https://pytorch.org/docs/stable/fx.html>`_.
25+
The resulting FX Graph is polished before it is finally translated into an
26+
`ONNX graph <https://github.com/onnx/onnx/blob/main/docs/IR.md>`_.
27+
28+
The main advantage of this approach is that the `FX graph <https://pytorch.org/docs/stable/fx.html>`_ is captured using
29+
bytecode analysis that preserves the dynamic nature of the model instead of using traditional static tracing techniques.
30+
31+
Dependencies
32+
------------
33+
34+
The ONNX exporter depends on extra Python packages:
35+
36+
- `ONNX <https://onnx.ai>`_
37+
- `ONNX Script <https://onnxscript.ai>`_
38+
39+
They can be installed through `pip <https://pypi.org/project/pip/>`_:
40+
41+
.. code-block:: bash
42+
43+
pip install --upgrade onnx onnxscript
44+
45+
.. include:: /beginner_source/basics/onnx_toc.txt
46+
47+
.. toctree::
48+
:hidden:
49+
50+
"""

beginner_source/onnx/onnx_toc.txt

Whitespace-only changes.

index.rst

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,16 @@ What's new in PyTorch tutorials?
272272
:tags: Text
273273

274274

275+
.. ONNX
276+
277+
.. customcarditem::
278+
:header: (optional) Exporting a PyTorch Model to ONNX using TorchScript backend and Running it using ONNX Runtime
279+
:card_description: Convert a model defined in PyTorch into the ONNX format and then run it with ONNX Runtime.
280+
:image: _static/img/thumbnails/cropped/optional-Exporting-a-Model-from-PyTorch-to-ONNX-and-Running-it-using-ONNX-Runtime.png
281+
:link: advanced/super_resolution_with_onnxruntime.html
282+
:tags: ONNX,Production
283+
284+
275285
.. Reinforcement Learning
276286
277287
.. customcarditem::
@@ -328,13 +338,6 @@ What's new in PyTorch tutorials?
328338
:link: advanced/cpp_export.html
329339
:tags: Production,TorchScript
330340

331-
.. customcarditem::
332-
:header: (optional) Exporting a Model from PyTorch to ONNX and Running it using ONNX Runtime
333-
:card_description: Convert a model defined in PyTorch into the ONNX format and then run it with ONNX Runtime.
334-
:image: _static/img/thumbnails/cropped/optional-Exporting-a-Model-from-PyTorch-to-ONNX-and-Running-it-using-ONNX-Runtime.png
335-
:link: advanced/super_resolution_with_onnxruntime.html
336-
:tags: Production
337-
338341
.. Code Transformations with FX
339342
340343
.. customcarditem::
@@ -902,6 +905,14 @@ Additional Resources
902905
beginner/torchtext_custom_dataset_tutorial
903906

904907

908+
.. toctree::
909+
:maxdepth: 2
910+
:includehidden:
911+
:hidden:
912+
:caption: Backends
913+
914+
beginner/onnx/intro_onnx
915+
905916
.. toctree::
906917
:maxdepth: 2
907918
:includehidden:
@@ -918,6 +929,7 @@ Additional Resources
918929
:hidden:
919930
:caption: Deploying PyTorch Models in Production
920931

932+
beginner/onnx/intro_onnx
921933
intermediate/flask_rest_api_tutorial
922934
beginner/Intro_to_TorchScript_tutorial
923935
advanced/cpp_export

0 commit comments

Comments
 (0)