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

[InferDataLayouts] Add fallback for layout propagation #145

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
20 changes: 17 additions & 3 deletions src/qonnx/transformation/infer_data_layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,23 @@ def _dims_to_layout(model, node, ndims):
else:
return DataLayout.UNKNOWN
else:
# propagate input layout to output
# TODO this won't work for concat, squeeze/unsqueeze/reshape...
return model.get_tensor_layout(node.input[0])
# Check whether there is a layout annotation for the first input
# TODO: There are multi-input operations, why should the first
# determine the output layout?
if layout := model.get_tensor_layout(node.input[0]):
# If annotation present: propagate input layout to output
# TODO: this won't work for concat, squeeze/unsqueeze/reshape...
return layout
# Fallback to the same defaults as for the FINN-Ops above
else:
if ndims == 4:
return DataLayout.NHWC
elif ndims == 3:
return DataLayout.NWC
elif ndims == 2:
return DataLayout.NC
else:
return DataLayout.UNKNOWN


def _infer_node_data_layout(model, node):
Expand Down
Loading