Skip to content

Commit

Permalink
Merge branch 'fix/layout-propagation' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
iksnagreb committed Jan 20, 2025
2 parents 771bb0a + dd2a3f7 commit 5bbbda7
Showing 1 changed file with 17 additions and 3 deletions.
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

0 comments on commit 5bbbda7

Please sign in to comment.