Skip to content

Create short tensor str for nodes #2262

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

Merged
merged 4 commits into from
May 2, 2025
Merged
Changes from all commits
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
14 changes: 13 additions & 1 deletion onnxscript/ir/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,18 @@
idx: int


def _short_tensor_str_for_node(x: Value) -> str:
if x.const_value is None:
return ""
if x.const_value.size <= 10:
try:
data = x.const_value.numpy().tolist()
except Exception: # pylint: disable=broad-except
return "{...}"
return f"{{{data}}}"
return "{...}"

Check warning on line 1316 in onnxscript/ir/_core.py

View check run for this annotation

Codecov / codecov/patch

onnxscript/ir/_core.py#L1311-L1316

Added lines #L1311 - L1316 were not covered by tests


class Node(_protocols.NodeProtocol, _display.PrettyPrintable):
"""IR Node.

Expand Down Expand Up @@ -1468,7 +1480,7 @@
+ ", ".join(
[
(
f"%{_quoted(x.name) if x.name else 'anonymous:' + str(id(x))}{x._constant_tensor_part()}"
f"%{_quoted(x.name) if x.name else 'anonymous:' + str(id(x))}{_short_tensor_str_for_node(x)}"
if x is not None
else "None"
)
Expand Down
Loading