This repository was archived by the owner on Feb 7, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -797,20 +797,28 @@ def __call__(self, graph): # type: (Graph) -> Graph
797
797
output_names = set ([str (output_ [0 ]) for output_ in graph .outputs ])
798
798
799
799
nodes_to_be_removed = []
800
- use_set = set ()
800
+ uses = {}
801
801
802
- for node in graph .nodes :
803
- for _input in node .inputs :
804
- use_set .add (_input )
802
+ for _output in output_names :
803
+ uses [_output ] = uses .get (_output , 0 ) + 1
805
804
806
805
for node in graph .nodes :
806
+ for _input in node .inputs :
807
+ uses [_input ] = uses .get (_input , 0 ) + 1
808
+
809
+ for node in reversed (graph .nodes ):
807
810
output_used = False
808
811
for _output in node .outputs :
809
- if _output in output_names or _output in use_set :
812
+ if _output in uses :
810
813
output_used = True
811
814
break
815
+
812
816
if not output_used :
813
817
# Remove current node
818
+ for _input in node .inputs :
819
+ uses [_input ] -= 1
820
+ if uses [_input ] == 0 :
821
+ del uses [_input ]
814
822
nodes_to_be_removed .append (node .name )
815
823
for parent in node .parents :
816
824
parent .children .remove (node )
@@ -821,7 +829,7 @@ def __call__(self, graph): # type: (Graph) -> Graph
821
829
transformed_nodes .append (node )
822
830
823
831
for _input in input_names :
824
- if _input not in use_set :
832
+ if _input not in uses :
825
833
for i in range (len (graph .inputs )):
826
834
if graph .inputs [i ][0 ] is _input :
827
835
graph .inputs .remove (graph .inputs [i ])
You can’t perform that action at this time.
0 commit comments