Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A couple of ir utilities #1972

Merged
merged 6 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Address PR feedback
gramalingam committed Dec 6, 2024
commit 4bcffd5165a2dacd853e6af9b88fe559bd5c5879
12 changes: 10 additions & 2 deletions onnxscript/rewriter/_ir_utils.py
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@
from onnxscript.optimizer import basic_constant_propagation


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."""
def display_slice(x: ir.Value | ir.Node, backward: bool = True, depth_limit: int = 5) -> None:
"""Display the (backward or forward) subgraph from a given value or node upto a certain depth."""
slice = []

def visit(node: ir.Node, depth):
@@ -51,6 +51,14 @@


def get_numpy_value(val: ir.Value | None) -> np.ndarray | None:
gramalingam marked this conversation as resolved.
Show resolved Hide resolved
"""Convenience wrapper to get (optional) numpy value from an optional IR Value.

Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
This is intended for use in optimizations/rewriting. Note that this does not
yet handle the distinction between inputs with default values (values that are
both graph inputs and graph initializers), which should not be treated as a
constant, and true constant values. The caller should make the distinction, as
a value does not contain enough information to determine this. (TODO)
"""
if val is None:
return None
const_value = val.const_value