Skip to content

Document MobileNetV3 quantization approach #5891

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

Merged
merged 3 commits into from
Apr 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions torchvision/models/quantization/mobilenetv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ 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/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)
Expand Down