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

fix removal of consecutive tranposes with branches #162

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
17 changes: 17 additions & 0 deletions src/qonnx/transformation/channels_last.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ def move_transpose_past_eltwise(transpose_node, eltwise_node, model: ModelWrappe
# scalar input, always broadcastable, no action needed
continue
elif ndim == ndim_inp:
p_nodes = model.find_direct_predecessors(eltwise_node)
for pn in p_nodes:
if pn.output[0] == eltwise_inp:
break
pn_shape = model.get_tensor_shape(pn.output[0])
if pn_shape == subgraph_inp_shape:
# input with matching shape, inverse transpose not needed
continue
# input with matching dimensions, add inverse transpose
new_t_inp = model.make_new_valueinfo_name()
inv_perm = np.argsort(perm)
Expand Down Expand Up @@ -323,6 +331,15 @@ def apply(self, model):
if inp == output_tensor_name:
target_node.input[i] = input_tensor

n_successors = model.find_direct_successors(n)
if n_successors is None:
continue

for ns in n_successors:
for i, inp in enumerate(ns.input):
if inp == n.output[0]:
ns.input[i] = input_tensor

# remove old nodes
graph.node.remove(n)
graph.node.remove(successor_node)
Expand Down
Loading