Skip to content
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
10 changes: 9 additions & 1 deletion backends/cadence/aot/replace_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,23 @@ def maybe_remove_or_replace(self, node: torch.fx.Node) -> bool:

graph = node.graph

fit_bias = is_node_with_op(bias, "get_attr") or beta == 1.0
fit_mat2 = is_node_with_op(mat2, "get_attr")

# Handle transpose: if mat2 is a transpose op, extract the original tensor
transposed_mat2 = False
if (
mat2.op == "call_function"
not fit_mat2
and mat2.op == "call_function"
and mat2.target == exir_ops.edge.aten.transpose_copy.int
):
# mat2 is already transposed, so we use the input to the transpose
mat2 = cast(torch.fx.Node, mat2.args[0])
transposed_mat2 = True
fit_mat2 = is_node_with_op(mat2, "get_attr") or alpha == 1.0

if not (fit_bias and fit_mat2):
return False

# Multiply bias by beta if needed
if beta != 1.0:
Expand Down
Loading