onnx_ir.traversal¶
Utilities for traversing the IR graph.
- class onnx_ir.traversal.RecursiveGraphIterator(graph_like, *, recursive=None, reverse=False, enter_graph=None, exit_graph=None)[source]¶
- Parameters:
- __abstractmethods__ = frozenset({})¶
- __annotations__ = {}¶
- __dict__ = mappingproxy({'__module__': 'onnx_ir.traversal', '__init__': <function RecursiveGraphIterator.__init__>, '__iter__': <function RecursiveGraphIterator.__iter__>, '__next__': <function RecursiveGraphIterator.__next__>, '_recursive_node_iter': <function RecursiveGraphIterator._recursive_node_iter>, '_iterate_subgraphs': <function RecursiveGraphIterator._iterate_subgraphs>, '__reversed__': <function RecursiveGraphIterator.__reversed__>, '__orig_bases__': (collections.abc.Iterator[onnx_ir.Node], collections.abc.Reversible[onnx_ir.Node]), '__dict__': <attribute '__dict__' of 'RecursiveGraphIterator' objects>, '__weakref__': <attribute '__weakref__' of 'RecursiveGraphIterator' objects>, '__doc__': None, '__abstractmethods__': frozenset(), '_abc_impl': <_abc._abc_data object>, '__annotations__': {}})¶
- __init__(graph_like, *, recursive=None, reverse=False, enter_graph=None, exit_graph=None)[source]¶
Iterate over the nodes in the graph, recursively visiting subgraphs.
This iterator allows for traversing the nodes of a graph and its subgraphs in a depth-first manner. It supports optional callbacks for entering and exiting subgraphs, as well as a callback recursive to determine whether to visit subgraphs contained within nodes.
Added in version 0.1.6: Added the enter_graph and exit_graph callbacks.
- Parameters:
graph_like (Graph | Function | GraphView) – The graph to traverse.
recursive (Callable[[Node], bool] | None) – A callback that determines whether to recursively visit the subgraphs contained in a node. If not provided, all nodes in subgraphs are visited.
reverse (bool) – Whether to iterate in reverse order.
enter_graph (Callable[[Graph | Function | GraphView], None] | None) – An optional callback that is called when entering a subgraph.
exit_graph (Callable[[Graph | Function | GraphView], None] | None) – An optional callback that is called when exiting a subgraph.
- __module__ = 'onnx_ir.traversal'¶
- __next__()[source]¶
Return the next item from the iterator. When exhausted, raise StopIteration
- Return type:
- __orig_bases__ = (collections.abc.Iterator[onnx_ir.Node], collections.abc.Reversible[onnx_ir.Node])¶
- __weakref__¶
list of weak references to the object (if defined)