TensorRT icon indicating copy to clipboard operation
TensorRT copied to clipboard

[BUG] Resent50 model with wrong precision after quantization with tensorrt int8PTQ

Open lixiaolx opened this issue 3 years ago • 6 comments

Description

When using resnet50 of the timm model library, when PTQint8 is quantized, the accuracy becomes worse. In the same environment, the accuracy before and after quantization on torchvision can basically be aligned.

  1. First of all, what is the method used by TRT to quantify the model, and what is the implementation principle?
  2. I compared and analyzed the model structure of timm and torchvision and found no difference, but there are some differences in the tensor bias data corresponding to some bn layers, but I don’t think it should be the reason for the difference in quantification, right?

ref: https://github.com/rwightman/pytorch-image-models/issues/1412

lixiaolx avatar Aug 18 '22 06:08 lixiaolx

Did you do the int8 calibration with real data? and how many images you are using for calibration?

zerollzeng avatar Aug 18 '22 12:08 zerollzeng

Did you do the int8 calibration with real data? and how many images you are using for calibration?

I use imagenet1k_pytorch for 50000 val images. 512 images of val were randomly selected during quantization

lixiaolx avatar Aug 18 '22 12:08 lixiaolx

Resnet50 accuracy is in our L1 and QA test, I will be surprised if we had accuracy issue for it. Have you checked the code that do the calibration and make sure the preprocessing of input images is correct?

zerollzeng avatar Aug 18 '22 12:08 zerollzeng

@zerollzeng ,The verification script I used for my test is as follows: https://github.com/rmccorm4/tensorrt-utils/blob/master/int8/calibration/ImagenetCalibrator.py There is only so much difference in the code between the two tests, but the accuracy difference between the two models after quantization is too large timm:

net = timm.create_model('resnet50', pretrained=True) model = torch.jit.script(net).eval().cuda()

torchvision:

import torchvision.models as models mod = models.resnet50(pretrained=True).eval() mod_jit = torch.jit.script(mod) model = mod_jit.cuda()

lixiaolx avatar Aug 18 '22 12:08 lixiaolx

@zerollzeng Can you provide the contact information, email or something? Contact you privately

lixiaolx avatar Aug 22 '22 12:08 lixiaolx

as for BN layers, i found there exists BN layers after trt - pytorch_quantization, exported to ONNX model. but it isn't appeared through other resnet50 quantization repo

ijpq avatar Aug 23 '22 11:08 ijpq

I will close this issue, now we have release https://github.com/NVIDIA/TensorRT-Model-Optimizer for quantization, thanks all!

ttyio avatar May 14 '24 16:05 ttyio