Skip to content
Open
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
7 changes: 5 additions & 2 deletions onnxscript/_internal/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,11 +1101,14 @@ def ret(exp, i, suffix):
if val.value.is_graph_input():
# In ONNX, a graph-input cannot be an output of the graph.
# We need to insert a copy.
return_var = self._emit_copy(return_var, preferred_name)
suggested_name = preferred_name
if isinstance(exp, ast.Name):
suggested_name = exp.id
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A unit test would make it clear what this does. It sounds reasonable to me, but would be good to see it illustrated with an example. Specifically, if this is returning an input called X, the output cannot also be called X. Would it get renamed into something like "X_1" ?

return_var = self._emit_copy(return_var, suggested_name)
for prev_output in self._current_fn.outputs:
if prev_output.name == return_var.name:
# ONNX does not allow duplicate output names.
return_var = self._emit_copy(return_var, f"{return_var}_copy")
return_var = self._emit_copy(return_var, f"{return_var.name}_copy")
break
if self.returntype is not None:
set_type_info(return_var, self.returntype[i])
Expand Down
Loading