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] Add tensor rank check for nn.instance_norm #13280

Merged
merged 1 commit into from
Nov 3, 2022
Merged

[Relay] Add tensor rank check for nn.instance_norm #13280

merged 1 commit into from
Nov 3, 2022

Conversation

wzh99
Copy link
Contributor

@wzh99 wzh99 commented Nov 3, 2022

This PR adds a rank check for input tensor in type inference of nn.instance_norm. I explain the reasons as follows:

First, according to the definition of Instance Normalization, it only normalizes the spatial dimensions. Therefore, the input tensor must be of at least rank 3, and otherwise the operator will not produce meaningful results.

Second, nn.instance_norm with tensor rank less than 2 leads to a problem in the SimplifyInference optimization pass. This pass finds the reduced axes before converting the operator to its lower-level computation definition:

Array<Integer> reduced_axes;
for (int i = 1; i < ndim; ++i) {
if (i != axis) reduced_axes.push_back(i);
}

If the rank of the input tensor is less than 3, reduced_axes is empty. According to GetRealAxis, all the dimensions are reduced:
if (!axis.defined() || axis.size() == 0) {
for (int i = 0; i < ndim; ++i) {
real_axis.push_back(i);
}

This is problematic because we do not actually want batch and axis dimensions to be reduced.

cc @masahi

@tvm-bot
Copy link
Collaborator

tvm-bot commented Nov 3, 2022

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

  • No users to tag found in teams: relay See #10317 for details
  • Built docs for commit 93f7698 can be found here.

Generated by tvm-bot

@github-actions github-actions bot requested a review from masahi November 3, 2022 14:47
@masahi masahi merged commit 90ed632 into apache:main Nov 3, 2022
@wzh99 wzh99 deleted the instance-norm-rank branch November 9, 2022 01:33
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 10, 2022
Add tensor rank check for `nn.instance_norm`.
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
Add tensor rank check for `nn.instance_norm`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants