Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Add TupleConstruct to allow (a, b)=SomeModule() #3357

Merged
merged 1 commit into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions nni/retiarii/converter/graph_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ def handle_single_node(node):
new_node = ir_graph.add_node(build_full_name(module_name, OpTypeName.ListConstruct, self.global_seq), node.kind())
node_index[node] = new_node
self._add_edge(ir_graph, node, graph_inputs, node_index, new_node, output_remap)
elif node.kind() == 'prim::TupleConstruct':
self.global_seq += 1
new_node = ir_graph.add_node(build_full_name(module_name, OpTypeName.TupleConstruct, self.global_seq), node.kind())
node_index[node] = new_node
self._add_edge(ir_graph, node, graph_inputs, node_index, new_node, output_remap)
elif node.kind() == 'aten::append':
self.global_seq += 1
aten_node = ir_graph.add_node(build_full_name(module_name, BasicOpsPT[node.kind()], self.global_seq), node.kind())
Expand Down
1 change: 1 addition & 0 deletions nni/retiarii/converter/op_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class OpTypeName(str, Enum):
Attr = 'Attr'
Constant = 'Constant'
ListConstruct = 'ListConstruct'
TupleConstruct = 'TupleConstruct'
LayerChoice = 'LayerChoice'
InputChoice = 'InputChoice'
ValueChoice = 'ValueChoice'
Expand Down
2 changes: 2 additions & 0 deletions nni/retiarii/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def to_forward_code(self, field: str, output: str, inputs: List[str]) -> str:
return f'{output} = {value}'
elif self.type == 'prim::ListConstruct':
return f'{output} = [{", ".join(inputs)}]'
elif self.type == 'prim::TupleConstruct':
return f'{output} = ({", ".join(inputs)})'
elif self.type == 'prim::GetAttr':
return f"{output} = {self.parameters['input']}.{self.parameters['name']}"
elif self.type == 'aten::mean':
Expand Down