Skip to content

Commit

Permalink
use set for unreachable nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
kylesayrs committed Jun 25, 2024
1 parent edd435f commit 60613fe
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/deepsparse/utils/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""

import os
from typing import Any, List, Optional, Sequence, Tuple
from typing import Any, List, Optional, Sequence, Tuple, Set

import onnx.helper
import onnx.shape_inference
Expand Down Expand Up @@ -84,8 +84,8 @@ def _collect_new_outputs(self, names: List[str]) -> List[ValueInfoProto]:
def _dfs_search_reachable_nodes(
self,
node_output_name: str,
graph_input_names: List[str],
reachable_nodes: List[NodeProto],
graph_input_names: Set[str],
reachable_nodes: Set[NodeProto],
) -> None:
if node_output_name in graph_input_names:
return
Expand All @@ -95,7 +95,7 @@ def _dfs_search_reachable_nodes(
continue
if node in reachable_nodes:
continue
reachable_nodes.append(node)
reachable_nodes.add(node)
for name in node.input:
self._dfs_search_reachable_nodes(
name, graph_input_names, reachable_nodes
Expand All @@ -106,9 +106,9 @@ def _collect_reachable_nodes(
input_names: List[str],
output_names: List[str],
) -> List[NodeProto]:
reachable_nodes = list() # type: ignore
reachable_nodes = set() # type: ignore
for name in output_names:
self._dfs_search_reachable_nodes(name, input_names, reachable_nodes)
self._dfs_search_reachable_nodes(name, set(input_names), reachable_nodes)
# needs to be topology sorted.
nodes = [n for n in self.graph.node if n in reachable_nodes]
return nodes
Expand Down

0 comments on commit 60613fe

Please sign in to comment.