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

[Relay] Remove overwriting of matmul shapes when they are static #13615

Merged
merged 3 commits into from
Dec 15, 2022
Merged
Changes from 1 commit
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
32 changes: 24 additions & 8 deletions src/relay/op/nn/nn.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,36 @@ bool MatmulRel(const Array<Type>& types, int num_inputs, const Attrs& attrs,
auto sb = B_shape.size();
if (transpose_a && transpose_b) {
auto tmp = A_shape[sa - 2];
A_shape[sa - 2] = B_shape[sb - 1];
B_shape[sb - 1] = tmp;
if (A_shape[sa - 2].as<tir::AnyNode>()) {
AndrewZhaoLuo marked this conversation as resolved.
Show resolved Hide resolved
A_shape[sa - 2] = B_shape[sb - 1];
}
if (B_shape[sb - 1].as<tir::AnyNode>()) {
B_shape[sb - 1] = tmp;
}
} else if (transpose_a) {
auto tmp = A_shape[sa - 2];
A_shape[sa - 2] = B_shape[sb - 2];
B_shape[sb - 2] = tmp;
if (A_shape[sa - 2].as<tir::AnyNode>()) {
A_shape[sa - 2] = B_shape[sb - 2];
}
if (B_shape[sb - 2].as<tir::AnyNode>()) {
B_shape[sb - 2] = tmp;
}
} else if (transpose_b) {
auto tmp = A_shape[sa - 1];
A_shape[sa - 1] = B_shape[sb - 1];
B_shape[sb - 1] = tmp;
if (A_shape[sa - 1].as<tir::AnyNode>()) {
A_shape[sa - 1] = B_shape[sb - 1];
}
if (B_shape[sb - 1].as<tir::AnyNode>()) {
B_shape[sb - 1] = tmp;
}
} else {
auto tmp = A_shape[sa - 1];
A_shape[sa - 1] = B_shape[sb - 2];
B_shape[sb - 2] = tmp;
if (A_shape[sa - 1].as<tir::AnyNode>()) {
A_shape[sa - 1] = B_shape[sb - 2];
}
if (B_shape[sb - 2].as<tir::AnyNode>()) {
B_shape[sb - 2] = tmp;
}
}
reporter->Assign(types[0], TensorType(A_shape, tensor_a->dtype));
reporter->Assign(types[1], TensorType(B_shape, tensor_b_dtype));
Expand Down