Skip to content

Commit 50cc591

Browse files
committed
fix build error
1 parent 0740801 commit 50cc591

File tree

4 files changed

+10
-20
lines changed

4 files changed

+10
-20
lines changed
3.52 KB
Loading
-22.1 KB
Binary file not shown.
19 KB
Loading

beginner_source/onnx/onnx_registry_tutorial.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def forward(self, input_x, input_y):
9999
# NOTE: All attributes must be annotated with type hints.
100100
@onnxscript.script(custom_aten)
101101
def custom_aten_add(input_x, input_y, alpha: float = 1.0):
102-
alpha = opset18.CastLike(alpha, input_y)
103102
input_y = opset18.Mul(input_y, alpha)
104103
return opset18.Add(input_x, input_y)
105104

@@ -130,9 +129,9 @@ def custom_aten_add(input_x, input_y, alpha: float = 1.0):
130129
# graph node name is the function name
131130
assert onnx_program.model_proto.graph.node[0].op_type == "custom_aten_add"
132131
# function node domain is empty because we use standard ONNX operators
133-
assert onnx_program.model_proto.functions[0].node[3].domain == ""
132+
assert onnx_program.model_proto.functions[0].node[2].domain == ""
134133
# function node name is the standard ONNX operator name
135-
assert onnx_program.model_proto.functions[0].node[3].op_type == "Add"
134+
assert onnx_program.model_proto.functions[0].node[2].op_type == "Add"
136135

137136

138137
######################################################################
@@ -231,33 +230,24 @@ def custom_aten_gelu(input_x, approximate: str = "none"):
231230

232231

233232
######################################################################
234-
# Let's inspect the model and verify the model uses :func:`custom_aten_gelu` instead of
235-
# :class:`aten::gelu`. Note the graph has one graph nodes for
236-
# ``custom_aten_gelu``, and inside ``custom_aten_gelu``, there is a function
237-
# node for ``Gelu`` with namespace ``com.microsoft``.
233+
# Let's inspect the model and verify the model uses op_type ``Gelu``
234+
# from namespace ``com.microsoft``.
235+
#
236+
# Note that :func:`custom_aten_gelu` does not exist in the graph, because
237+
# the funtions with less than 3 operators are inlined automatically.
238238
#
239239

240240
# graph node domain is the custom domain we registered
241241
assert onnx_program.model_proto.graph.node[0].domain == "com.microsoft"
242242
# graph node name is the function name
243-
assert onnx_program.model_proto.graph.node[0].op_type == "custom_aten_gelu"
244-
# function node domain is the custom domain we registered
245-
assert onnx_program.model_proto.functions[0].node[0].domain == "com.microsoft"
246-
# function node name is the node name used in the function
247-
assert onnx_program.model_proto.functions[0].node[0].op_type == "Gelu"
243+
assert onnx_program.model_proto.graph.node[0].op_type == "Gelu"
248244

249245

250246
######################################################################
251-
# The following diagram shows ``custom_aten_gelu_model`` ONNX graph using Netron:
247+
# The following diagram shows ``custom_aten_gelu_model`` ONNX graph using Netron,
248+
# we can see the ``Gelu`` node from module ``com.microsoft`` used in the function:
252249
#
253250
# .. image:: /_static/img/onnx/custom_aten_gelu_model.png
254-
# :width: 70%
255-
# :align: center
256-
#
257-
# Inside the ``custom_aten_gelu`` function, we can see the ``Gelu`` node from module
258-
# ``com.microsoft`` used in the function:
259-
#
260-
# .. image:: /_static/img/onnx/custom_aten_gelu_function.png
261251
#
262252
# That is all we need to do. As an additional step, we can use ONNX Runtime to run the model,
263253
# and compare the results with PyTorch.

0 commit comments

Comments
 (0)