Skip to content

[ONNX 1] Add Backend section to the left page of Tutorials layout page #2550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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