Skip to content

Commit

Permalink
Add Backends section to Tutorials left menu
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Thiago Crepaldi committed Oct 3, 2023
1 parent 309c889 commit 919356b
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 8 deletions.
1 change: 1 addition & 0 deletions .jenkins/validate_tutorials_built.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

NOT_RUN = [
"beginner_source/basics/intro", # no code
"beginner_source/onnx/intro_onnx",
"beginner_source/translation_transformer",
"beginner_source/profiler",
"beginner_source/saving_loading_models",
Expand Down
2 changes: 1 addition & 1 deletion _templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
</noscript>

<script type="text/javascript">
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'];
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'];
</script>

<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"/>
Expand Down
7 changes: 7 additions & 0 deletions beginner_source/onnx/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ONNX
----

1. intro_onnx.py
Introduction to ONNX
https://pytorch.org/tutorials/onnx/intro_onnx.html

50 changes: 50 additions & 0 deletions beginner_source/onnx/intro_onnx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
**Introduction to ONNX**
Introduction to ONNX
====================
Authors:
`Thiago Crepaldi <https://github.com/thiagocrepaldi>`_,
`Open Neural Network eXchange (ONNX) <https://onnx.ai/>`_ is an open standard
format for representing machine learning models. The ``torch.onnx`` module provides APIs to
capture the computation graph from a native PyTorch :class:`torch.nn.Module` model and convert
it into an `ONNX graph <https://github.com/onnx/onnx/blob/main/docs/IR.md>`_.
The exported model can be consumed by any of the many
`runtimes that support ONNX <https://onnx.ai/supported-tools.html#deployModel>`_,
including Microsoft's `ONNX Runtime <https://www.onnxruntime.ai>`_.
.. note::
Currently, there are two flavors of ONNX exporter APIs,
but this tutorial will focus on the ``torch.onnx.dynamo_export``.
The TorchDynamo engine is leveraged to hook into Python's frame evaluation API and dynamically rewrite its
bytecode into an `FX graph <https://pytorch.org/docs/stable/fx.html>`_.
The resulting FX Graph is polished before it is finally translated into an
`ONNX graph <https://github.com/onnx/onnx/blob/main/docs/IR.md>`_.
The main advantage of this approach is that the `FX graph <https://pytorch.org/docs/stable/fx.html>`_ is captured using
bytecode analysis that preserves the dynamic nature of the model instead of using traditional static tracing techniques.
Dependencies
------------
The ONNX exporter depends on extra Python packages:
- `ONNX <https://onnx.ai>`_
- `ONNX Script <https://onnxscript.ai>`_
They can be installed through `pip <https://pypi.org/project/pip/>`_:
.. code-block:: bash
pip install --upgrade onnx onnxscript
.. include:: /beginner_source/basics/onnx_toc.txt
.. toctree::
:hidden:
"""
Empty file.
26 changes: 19 additions & 7 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ What's new in PyTorch tutorials?
:tags: Text


.. ONNX
.. customcarditem::
:header: (optional) Exporting a PyTorch Model to ONNX using TorchScript backend and Running it using ONNX Runtime
:card_description: Convert a model defined in PyTorch into the ONNX format and then run it with ONNX Runtime.
:image: _static/img/thumbnails/cropped/optional-Exporting-a-Model-from-PyTorch-to-ONNX-and-Running-it-using-ONNX-Runtime.png
:link: advanced/super_resolution_with_onnxruntime.html
:tags: ONNX,Production


.. Reinforcement Learning
.. customcarditem::
Expand Down Expand Up @@ -328,13 +338,6 @@ What's new in PyTorch tutorials?
:link: advanced/cpp_export.html
:tags: Production,TorchScript

.. customcarditem::
:header: (optional) Exporting a Model from PyTorch to ONNX and Running it using ONNX Runtime
:card_description: Convert a model defined in PyTorch into the ONNX format and then run it with ONNX Runtime.
:image: _static/img/thumbnails/cropped/optional-Exporting-a-Model-from-PyTorch-to-ONNX-and-Running-it-using-ONNX-Runtime.png
:link: advanced/super_resolution_with_onnxruntime.html
:tags: Production

.. Code Transformations with FX
.. customcarditem::
Expand Down Expand Up @@ -916,6 +919,14 @@ Additional Resources
beginner/torchtext_custom_dataset_tutorial


.. toctree::
:maxdepth: 2
:includehidden:
:hidden:
:caption: Backends

beginner/onnx/intro_onnx

.. toctree::
:maxdepth: 2
:includehidden:
Expand All @@ -932,6 +943,7 @@ Additional Resources
:hidden:
:caption: Deploying PyTorch Models in Production

beginner/onnx/intro_onnx
intermediate/flask_rest_api_tutorial
beginner/Intro_to_TorchScript_tutorial
advanced/cpp_export
Expand Down

0 comments on commit 919356b

Please sign in to comment.