Skip to content

Conversation

@Wheest
Copy link
Contributor

@Wheest Wheest commented Mar 13, 2023

When attempting to run inference with an 8-bit quantized version of EfficientNet (PyTorch implementation), I found that the quantization process crashed, which you can reproduce with this gist.

Upon closer inspection, I believe that the issue is related to the "Squeeze-and-Excitation block", where we multiply the output of a sigmoid with an earlier output.

Sample IR:

  %363 = sigmoid(%362);
  %364 = multiply(%362, %363);
  %365 = nn.adaptive_avg_pool2d(%364, output_size=[1, 1]);
  %366 = nn.conv2d(%365, %features.7.0.block.2.fc1.weight, padding=[0, 0, 0, 0], channels=48, kernel_size=[1, 1]);
  %367 = nn.bias_add(%366, %features.7.0.block.2.fc1.bias);
  %368 = sigmoid(%367);
  %369 = multiply(%367, %368);

However this fails when we attempt to quantize, because the mul operation quantization operation does not cover this case (where lhs_cond is False, but rhs_cond is True).

I've updated the relevant files to cover this case, and with this fix the model can successfully compile.

Looking at the quantization code, this is not the only place where assumptions about LHS and RHS are being made.

However, I think it's only "general purpose" ops, like mul and add where we need to be agnostic.
Looking around, I don't see any obvious cases we aren't covering right now, but perhaps there are some tests that could be added.

Potential reviewers: @zhiics @jwfromm @anijain2305; listed as having quantization familiarity

@tvm-bot
Copy link
Collaborator

tvm-bot commented Mar 13, 2023

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.

Generated by tvm-bot

Revert black formatting from my text editor, which I had assumed matched TVM's linter
@masahi masahi merged commit ccc0b91 into apache:main Mar 14, 2023
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