Wheest opened a new pull request, #14286:
URL: https://github.com/apache/tvm/pull/14286

   When attempting to run inference with an 8-bit quantized version of 
[EfficientNet](https://arxiv.org/abs/1905.11946) ([PyTorch 
implementation](https://github.com/pytorch/vision/blob/main/torchvision/models/efficientnet.py)),
 I found that the quantization process crashed, which you can reproduce with 
[this gist](https://gist.github.com/Wheest/bd4fd601a15d6813e45c9ed5cdbae64f).
   
   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](https://github.com/apache/tvm/blob/9a99fc89a2970b9fca151a573de7a5e409b5d9ee/python/tvm/relay/quantize/_partition.py#L126)
 (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](https://github.com/apache/tvm/blob/main/python/tvm/relay/quantize/_partition.py),
 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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to