Skip to content

Commit

Permalink
Use graph order for display
Browse files Browse the repository at this point in the history
  • Loading branch information
gramalingam committed Dec 3, 2024
1 parent 1461ece commit 6c2c7ee
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions onnxscript/rewriter/_ir_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
def display_slice(x: ir.Value | ir.Node, backward: bool = True, depth_limit: int = 5):
"""Display the subgraph computing a given value or node upto a certain depth."""
slice = []

def visit(node: ir.Node, depth):
if node in slice:
return
slice.append(node)
if (depth < depth_limit):
if depth < depth_limit:
if backward:
for inp in node.inputs:
if inp is not None and inp.producer() is not None:
Expand All @@ -24,12 +25,23 @@ def visit(node: ir.Node, depth):
for out in node.outputs:
for consumer, _ in out.uses():
visit(consumer, depth + 1)

if isinstance(x, ir.Node):
visit(x, 0)
elif isinstance(x, ir.Value) and x.producer() is not None:
visit(x.producer(), 0)

Check failure

Code scanning / lintrunner

MYPY/arg-type Error

Argument 1 to "visit" has incompatible type "Node | None"; expected "Node" To disable, use # type: ignore[arg-type]
for node in reversed(slice):
node.display()
if slice:
graph = slice[0].graph
if graph:
# Display nodes in same order as in graph:
# Currently doesn't handle (control-flow) subgraphs
for node in graph:
if node in slice:
node.display()
else:
for node in reversed(slice):
node.display()


def get_const_value(value: ir.Value) -> ir.TensorProtocol | None:
node = value.producer()
Expand Down

0 comments on commit 6c2c7ee

Please sign in to comment.