You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Suggested Patch: Refactoring with :func:`torch.cond`
115
+
# --------------------------------------------
116
+
#
117
+
# To make the control flow exportable, the tutorial demonstrates replacing the
118
+
# forward method in ``ForwardWithControlFlowTest`` with a refactored version that
119
+
# uses :func:`torch.cond``.
120
+
#
121
+
# Details of the Refactoring:
122
+
#
123
+
# Two helper functions (identity2 and neg) represent the branches of the conditional logic:
124
+
# * :func:`torch.cond`` is used to specify the condition and the two branches along with the input arguments.
125
+
# * The updated forward method is then dynamically assigned to the ``ForwardWithControlFlowTest`` instance within the model. A list of submodules is printed to confirm the replacement.
Copy file name to clipboardExpand all lines: beginner_source/onnx/export_simple_model_to_onnx_tutorial.py
+39-29
Original file line number
Diff line number
Diff line change
@@ -2,26 +2,27 @@
2
2
"""
3
3
`Introduction to ONNX <intro_onnx.html>`_ ||
4
4
**Exporting a PyTorch model to ONNX** ||
5
-
`Extending the ONNX Registry <onnx_registry_tutorial.html>`_
5
+
`Extending the ONNX exporter operator support <onnx_registry_tutorial.html>`_ ||
6
+
`Export a model with control flow to ONNX <export_control_flow_model_to_onnx_tutorial.html>`_
6
7
7
8
Export a PyTorch model to ONNX
8
9
==============================
9
10
10
-
**Author**: `Ti-Tai Wang <https://github.com/titaiwangms>`_ and `Xavier Dupré <https://github.com/xadupre>`_
11
+
**Author**: `Ti-Tai Wang <https://github.com/titaiwangms>`_, `Justin Chu <justinchu@microsoft.com>`_, `Thiago Crepaldi <https://github.com/thiagocrepaldi>`_.
11
12
12
13
.. note::
13
-
As of PyTorch 2.1, there are two versions of ONNX Exporter.
14
+
As of PyTorch 2.5, there are two versions of ONNX Exporter.
14
15
15
-
* ``torch.onnx.dynamo_export`` is the newest (still in beta) exporter based on the TorchDynamo technology released with PyTorch 2.0
16
-
* ``torch.onnx.export`` is based on TorchScript backend and has been available since PyTorch 1.2.0
16
+
* ``torch.onnx.export(..., dynamo=True)`` is the newest (still in beta) exporter using ``torch.export`` and Torch FX to capture the graph. It was released with PyTorch 2.5
17
+
* ``torch.onnx.export`` uses TorchScript and has been available since PyTorch 1.2.0
0 commit comments