Skip to content

[IR] Display constant tensors for Value #2248

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 17 commits into from
May 1, 2025
16 changes: 12 additions & 4 deletions onnxscript/ir/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1836,14 +1836,22 @@ def __init__(

def __repr__(self) -> str:
value_name = self.name if self.name else "anonymous:" + str(id(self))

type_text = f", type={self.type!r}" if self.type is not None else ""
shape_text = f", shape={self.shape!r}" if self.shape is not None else ""
producer = self.producer()
if producer is None:
producer_text = "None"
producer_text = ""
elif producer.name is not None:
producer_text = producer.name
producer_text = f", producer='{producer.name}'"
else:
producer_text = f", producer=anonymous_node:{id(producer)}"
index_text = f", index={self.index()}" if self.index() is not None else ""
if self.const_value is not None:
const_value_text = f", const_value={self.const_value!r}"
else:
producer_text = f"anonymous_node:{id(producer)}"
return f"{self.__class__.__name__}({value_name!r}, type={self.type!r}, shape={self.shape}, producer={producer_text}, index={self.index()})"
const_value_text = ""
return f"{self.__class__.__name__}(name={value_name!r}{type_text}{shape_text}{producer_text}{index_text}{const_value_text})"

def __str__(self) -> str:
value_name = self.name if self.name is not None else "anonymous:" + str(id(self))
Expand Down
Loading