Skip to content

Commit 86b2c51

Browse files
author
Thiago Crepaldi
committed
Address comments
1 parent ba7f933 commit 86b2c51

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

beginner_source/export_simple_model_to_onnx_tutorial.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
**Author**: `Thiago Crepaldi <https://github.com/thiagocrepaldi>`_
77
8-
.. Note::
8+
.. note::
99
As of PyTorch 2.1, there are two versions of ONNX Exporter.
1010
1111
* ``torch.onnx.dynamo_export`is the newest (still in beta) exporter based on the TorchDynamo technology released with PyTorch 2.0
@@ -34,7 +34,7 @@
3434
# 4. Visualize the ONNX model graph using `Netron <https://github.com/lutzroeder/netron>`_.
3535
# 5. Execute the ONNX model with `ONNX Runtime`
3636
#
37-
# Note that because the ONNX exporter uses ``onnx`` and ``onnxscript`` to translate PyTorch operators into ONNX operators,
37+
# Because the ONNX exporter uses ``onnx`` and ``onnxscript`` to translate PyTorch operators into ONNX operators,
3838
# we will need to install them.
3939
# %%
4040
# .. code-block:: bash
@@ -85,7 +85,6 @@ def forward(self, x):
8585
# As we can see, we didn't need any code change on our model.
8686
# The resulting ONNX model is saved within ``torch.onnx.ExportOutput`` as a binary protobuf file.
8787
# The exporter uses static shapes by default, so the resulting model has static dimensions.
88-
# In a future tutorial we are going to explore how to leverage dynamic shapes and other advanced features.
8988
#
9089
# We can save it to disk with the following code:
9190

@@ -98,7 +97,7 @@ def forward(self, x):
9897
# .. image:: ../_static/img/onnx/netron_web_ui.png
9998
#
10099
# Once Netron is open, we can drag and drop our ``my_image_classifier.onnx`` file into the browser or select it after
101-
# clicking on `Open model` button.
100+
# clicking the **Open model** button.
102101
#
103102
# .. image:: ../_static/img/onnx/image_clossifier_onnx_modelon_netron_web_ui.png
104103
#
@@ -117,7 +116,7 @@ def forward(self, x):
117116
print(f"Input length: {len(onnx_input)}")
118117
print(f"Sample input: {onnx_input}")
119118

120-
# in our example, the input is the same, but we can have more inputs
119+
# In our example, the input is the same, but we can have more inputs
121120
# than the original PyTorch model in more complex cases.
122121
# Now we can execute the ONNX model with ONNX Runtime.
123122

@@ -134,7 +133,7 @@ def to_numpy(tensor):
134133
return tensor.detach().cpu().numpy() if tensor.requires_grad else tensor.cpu().numpy()
135134

136135
# ONNX Runtime also requires the input to be a dictionary with
137-
# the keys being the input name and the value the Numpy tensor
136+
# the keys being the input name and the value the Numpy tensor.
138137

139138
onnxruntime_input = {k.name: to_numpy(v) for k, v in zip(ort_session.get_inputs(), onnx_input)}
140139

@@ -143,7 +142,7 @@ def to_numpy(tensor):
143142
onnxruntime_outputs = ort_session.run(None, onnxruntime_input)
144143

145144
# The output can be a single tensor or a list of tensors, depending on the model.
146-
# Let's execute the PyTorch model and use it as benchmark next
145+
# Let's execute the PyTorch model and use it as benchmark next.
147146
torch_outputs = torch_model(torch_input)
148147

149148
# We need to adapt the PyTorch output format to match ONNX's
@@ -158,5 +157,9 @@ def to_numpy(tensor):
158157
print(f"Output length: {len(onnxruntime_outputs)}")
159158
print(f"Sample output: {onnxruntime_outputs}")
160159

160+
# Conclusion
161+
# ----------
162+
161163
# That is about it! We have successfully exported our PyTorch model to ONNX format,
162-
# saved it to disk, executed it with ONNX Runtime and compared its result with PyTorch's.
164+
# saved the model to disk, viewed it using Netron, executed it with ONNX Runtime
165+
# and finally compared its numerical results with PyTorch's.

index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ What's new in PyTorch tutorials?
333333
:card_description: Build a image classifier model in PyTorch and convert it to ONNX before deploying it with ONNX Runtime.
334334
:image: _static/img/thumbnails/cropped/Exporting-PyTorch-Models-to-ONNX-Graphs.png
335335
:link: beginner/export_simple_model_to_onnx_tutorial.html
336-
:tags: ONNX
336+
:tags: Production,ONNX
337337

338338
.. customcarditem::
339339
:header: (optional) Exporting a PyTorch Model to ONNX using TorchScript backend and Running it using ONNX Runtime

0 commit comments

Comments
 (0)