Skip to content

Commit 33c878a

Browse files
authored
Data description/repr shorter (#644)
1 parent 3ab8667 commit 33c878a

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

returnn/tf/util/data.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,8 +1592,6 @@ def get_description(self, with_name=True, with_placeholder=False, catch_exceptio
15921592
else:
15931593
if self.dtype != "float32":
15941594
keys.append("dtype")
1595-
if with_name:
1596-
keys.insert(0, "name")
15971595
if with_placeholder:
15981596
keys.append("placeholder")
15991597
if not self.available_for_inference:
@@ -1604,6 +1602,17 @@ def get_description(self, with_name=True, with_placeholder=False, catch_exceptio
16041602
if not self.batch or self.batch.beam != self.beam:
16051603
keys.append("beam")
16061604
args = []
1605+
if with_name:
1606+
name = getattr(self, "name", None)
1607+
args += [repr(name) if name else "<undefined>"]
1608+
try:
1609+
batch_shape_meta = "[%s]" % ",".join(self.get_batch_axes_short_description())
1610+
except Exception as exc:
1611+
if catch_exceptions:
1612+
batch_shape_meta = "<!%s: %s>" % (type(exc).__name__, exc)
1613+
else:
1614+
raise
1615+
args += [batch_shape_meta]
16071616
for key in keys:
16081617
try:
16091618
value_repr = repr(getattr(self, key))
@@ -1613,15 +1622,16 @@ def get_description(self, with_name=True, with_placeholder=False, catch_exceptio
16131622
else:
16141623
raise
16151624
args += ["%s=%s" % (key, value_repr)]
1616-
try:
1617-
batch_shape_meta = "[%s]" % ",".join(self.get_batch_axes_short_description())
1618-
except Exception as exc:
1619-
if catch_exceptions:
1620-
batch_shape_meta = "<!%s: %s>" % (type(exc).__name__, exc)
1621-
else:
1622-
raise
1623-
args += ["batch_shape_meta=" + batch_shape_meta]
1624-
return "Data(%s)" % ", ".join(args)
1625+
if self.control_flow_ctx:
1626+
try:
1627+
value_repr = self.control_flow_ctx.repr_inner()
1628+
except Exception as exc:
1629+
if catch_exceptions:
1630+
value_repr = "<!%s: %s>" % (type(exc).__name__, exc)
1631+
else:
1632+
raise
1633+
args += ["ctx=" + value_repr]
1634+
return "Data{%s}" % ", ".join(args)
16251635

16261636
def get_batch_axes_short_description(self, special_axes=True):
16271637
"""

0 commit comments

Comments
 (0)