From 18ff84ea73f02972be62937f3a62bd941e22d960 Mon Sep 17 00:00:00 2001 From: Vasilis Vryniotis Date: Wed, 27 Apr 2022 09:11:48 +0100 Subject: [PATCH 1/2] Document MobileNetV3 quantization approach --- torchvision/models/quantization/mobilenetv3.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/torchvision/models/quantization/mobilenetv3.py b/torchvision/models/quantization/mobilenetv3.py index f8fe39ed195..c82afc68316 100644 --- a/torchvision/models/quantization/mobilenetv3.py +++ b/torchvision/models/quantization/mobilenetv3.py @@ -140,6 +140,11 @@ def _mobilenet_v3_model( _replace_relu(model) if quantize: + # Instead of quantizing the model and then loading the quantized weights we take a different approach. + # We prepare the QAT model, load the QAT weights from training and then convert it. + # This is done to avoid extremely low accuracies observed on the specific model. This is rather a workaround + # for an unresolved bug on the eager quantization API detailed at: + # https://github.com/pytorch/vision/pull/3323/commits/274c6a1393384054876d701ffa1b54eb6750f1d8#r568727005 model.fuse_model(is_qat=True) model.qconfig = torch.ao.quantization.get_default_qat_qconfig(backend) torch.ao.quantization.prepare_qat(model, inplace=True) From 99190c9891fd25f261242133fa7a8836ee5b65aa Mon Sep 17 00:00:00 2001 From: Vasilis Vryniotis Date: Wed, 27 Apr 2022 09:25:36 +0100 Subject: [PATCH 2/2] Change the URL. --- torchvision/models/quantization/mobilenetv3.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/torchvision/models/quantization/mobilenetv3.py b/torchvision/models/quantization/mobilenetv3.py index c82afc68316..2d18446c13f 100644 --- a/torchvision/models/quantization/mobilenetv3.py +++ b/torchvision/models/quantization/mobilenetv3.py @@ -143,8 +143,7 @@ def _mobilenet_v3_model( # Instead of quantizing the model and then loading the quantized weights we take a different approach. # We prepare the QAT model, load the QAT weights from training and then convert it. # This is done to avoid extremely low accuracies observed on the specific model. This is rather a workaround - # for an unresolved bug on the eager quantization API detailed at: - # https://github.com/pytorch/vision/pull/3323/commits/274c6a1393384054876d701ffa1b54eb6750f1d8#r568727005 + # for an unresolved bug on the eager quantization API detailed at: https://github.com/pytorch/vision/issues/5890 model.fuse_model(is_qat=True) model.qconfig = torch.ao.quantization.get_default_qat_qconfig(backend) torch.ao.quantization.prepare_qat(model, inplace=True)