Skip to content

Commit 0afd428

Browse files
committed
address formatting
1 parent 35238bc commit 0afd428

File tree

6 files changed

+27
-24
lines changed

6 files changed

+27
-24
lines changed

beginner_source/onnx/README.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ ONNX
1010
https://pytorch.org/tutorials/beginner/onnx/export_simple_model_to_onnx_tutorial.html
1111

1212
3. onnx_registry_tutorial.py
13-
Extending the ONNX Registry
13+
Extending the ONNX exporter operator support
1414
https://pytorch.org/tutorials/beginner/onnx/onnx_registry_tutorial.html
1515

1616
4. export_control_flow_model_to_onnx_tutorial.py
17-
Export a Pytorch model with a test to ONNX
17+
Export a model with control flow to ONNX
1818
https://pytorch.org/tutorials/beginner/onnx/export_control_flow_model_to_onnx_tutorial.html

beginner_source/onnx/export_control_flow_model_to_onnx_tutorial.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
**Introduction to ONNX** ||
3+
`Introduction to ONNX <intro_onnx.html>`_ ||
44
`Exporting a PyTorch model to ONNX <export_simple_model_to_onnx_tutorial.html>`_ ||
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**
67
7-
Export a control flow model to ONNX
8+
Export a model with control flow to ONNX
89
==========================================
910
1011
**Author**: `Xavier Dupré <https://github.com/xadupre>`_.
1112
12-
Tests cannot be exported into ONNX unless they refactored
13+
Conditional logic cannot be exported into ONNX unless they refactored
1314
to use :func:`torch.cond`. Let's start with a simple model
1415
implementing a test.
1516
"""
1617

17-
from onnx.printer import to_text
1818
import torch
1919

2020
class ForwardWithControlFlowTest(torch.nn.Module):
@@ -48,17 +48,17 @@ def forward(self, x):
4848
# %%
4949
# As expected, it does not export.
5050
try:
51-
torch.export.export(model, (x,))
51+
torch.export.export(model, (x,), strict=False)
5252
raise AssertionError("This export should failed unless pytorch now supports this model.")
5353
except Exception as e:
5454
print(e)
5555

5656
# %%
5757
# It does export with :func:`torch.onnx.export` because
58-
# it uses JIT to trace the execution.
58+
# the exporter falls back to use JIT tracing as the graph capturing strategy.
5959
# But the model is not exactly the same as the initial model.
60-
ep = torch.onnx.export(model, (x,), dynamo=True)
61-
print(to_text(ep.model_proto))
60+
onnx_program = torch.onnx.export(model, (x,), dynamo=True)
61+
print(onnx_program.model)
6262

6363

6464
# %%
@@ -87,18 +87,18 @@ def neg(x):
8787
# %%
8888
# Let's see what the fx graph looks like.
8989

90-
print(torch.export.export(model, (x,)).graph)
90+
print(torch.export.export(model, (x,), strict=False))
9191

9292
# %%
9393
# Let's export again.
9494

95-
ep = torch.onnx.export(model, (x,), dynamo=True)
96-
print(to_text(ep.model_proto))
95+
onnx_program = torch.onnx.export(model, (x,), dynamo=True)
96+
print(onnx_program.model)
9797

9898

99-
# %%
100-
# Let's optimize to see a small model.
99+
# %%
100+
# We can optimize the model and get rid of the model local functions created to capture the control flow branches.
101101

102-
ep = torch.onnx.export(model, (x,), dynamo=True)
103-
ep.optimize()
104-
print(to_text(ep.model_proto))
102+
onnx_program = torch.onnx.export(model, (x,), dynamo=True)
103+
onnx_program.optimize()
104+
print(onnx_program.model)

beginner_source/onnx/export_simple_model_to_onnx_tutorial.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"""
33
`Introduction to ONNX <intro_onnx.html>`_ ||
44
**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>`_
67
78
Export a PyTorch model to ONNX
89
==============================

beginner_source/onnx/intro_onnx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""
22
**Introduction to ONNX** ||
33
`Exporting a PyTorch model to ONNX <export_simple_model_to_onnx_tutorial.html>`_ ||
4-
`Extending the ONNX Registry <onnx_registry_tutorial.html>`_
4+
`Extending the ONNX exporter operator support <onnx_registry_tutorial.html>`_ ||
5+
`Export a model with control flow to ONNX <export_control_flow_model_to_onnx_tutorial.html>`_
56
67
Introduction to ONNX
78
====================

beginner_source/onnx/onnx_registry_tutorial.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""
22
`Introduction to ONNX <intro_onnx.html>`_ ||
33
`Exporting a PyTorch model to ONNX <export_simple_model_to_onnx_tutorial.html>`_ ||
4-
**Extending the ONNX Exporter Operator Support**
4+
**Extending the ONNX exporter operator support** ||
5+
`Export a model with control flow to ONNX <export_control_flow_model_to_onnx_tutorial.html>`_
56
67
Extending the ONNX Exporter Operator Support
78
============================================

beginner_source/onnx/onnx_toc.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
| 1. `Exporting a PyTorch model to ONNX <export_simple_model_to_onnx_tutorial.html>`_
2-
| 2. `Extending the ONNX registry <onnx_registry_tutorial.html>`_
3-
| 3. `Export a Pytorch model with a test to ONNX <export_control_flow_model_to_onnx_tutorial>`_
2+
| 2. `Extending the ONNX exporter operator support <onnx_registry_tutorial.html>`_
3+
| 3. `Export a model with control flow to ONNX <export_control_flow_model_to_onnx_tutorial.html>`_

0 commit comments

Comments
 (0)