Skip to content

Fix crash in GiveReadableTensorNames #199

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 14 additions & 1 deletion src/qonnx/transformation/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ def apply(self, model):
return (model, False)


class GiveUniqueTensorNames(Transformation):
"""Give unique tensor names to all tensors."""

def apply(self, model):
names = model.get_all_tensor_names()
i = 0
for name in names:
model.rename_tensor(name, f"tensor_{i}")
i += 1
# return model_was_changed = False as single iteration is always enough
return (model, False)


class GiveReadableTensorNames(Transformation):
"""Give more human-readable names to all internal tensors. You should
apply GiveUniqueNodeNames prior to this transform to avoid empty node names,
Expand All @@ -155,7 +168,7 @@ class GiveReadableTensorNames(Transformation):
def apply(self, model):
# to ensure we can use rename_tensor safely (without renaming existing
# tensors) we start by giving random names to all tensors
model = model.transform(GiveRandomTensorNames())
model = model.transform(GiveUniqueTensorNames())
graph = model.graph
for n in graph.node:
assert n.name != "", "Found empty node name"
Expand Down