Skip to content

Adding multiweight support to Quantized MobileNetV2 and MobileNetV3 #4859

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

Conversation

datumbox
Copy link
Contributor

@datumbox datumbox commented Nov 4, 2021

Fixes #4674

Verified with:

python -u train_quantization.py --test-only --weights ImageNet1K_QNNPACK_RefV1 --model mobilenet_v2 --device cpu

python -u train_quantization.py --test-only --weights ImageNet1K_QNNPACK_RefV1 --model mobilenet_v3_large --device cpu

cc @bjuncek

@facebook-github-bot
Copy link

facebook-github-bot commented Nov 4, 2021

💊 CI failures summary and remediations

As of commit 9988a6c (more details on the Dr. CI page):


  • 1/1 failures introduced in this PR

1 failure not recognized by patterns:

Job Step Action
CircleCI binary_libtorchvision_ops_android Build 🔁 rerun

This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@datumbox datumbox added enhancement module: models.quantization Issues related to the quantizable/quantized models prototype labels Nov 4, 2021
@datumbox datumbox requested a review from jdsgomes November 4, 2021 14:42
Copy link
Contributor Author

@datumbox datumbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few clarifications to assist review:

@@ -4,8 +4,7 @@
from .googlenet import *
from .inception import *
from .mnasnet import *
from .mobilenetv2 import *
from .mobilenetv3 import *
from .mobilenet import *
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For BC reasons, we need to maintain the .mobilenet space.

kwargs["num_classes"] = len(weights.meta["categories"])
if "backend" in weights.meta:
kwargs["backend"] = weights.meta["backend"]
backend = kwargs.pop("backend", "qnnpack")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backend here is qnnpack

]


def _mobilenet_v3_model(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept this method instead on dumping everything in the public method because on the future we might want to support also the _small version of the model and this method will remain unchanged.


if quantize:
torch.quantization.convert(model, inplace=True)
model.eval()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check carefully lines 44-54 comparing to original. This is a simplification of the code.

Copy link
Contributor

@jdsgomes jdsgomes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@datumbox datumbox merged commit eb48a1d into pytorch:main Nov 4, 2021
@datumbox datumbox deleted the prototype/quantmobilenets_multiweight branch November 4, 2021 16:26
facebook-github-bot pushed a commit that referenced this pull request Nov 8, 2021
…leNetV3 (#4859)

Summary:
* Adding multiweight suport on Quant MobileNetV2 and MobileNetV3.

* Fixing enum name.

* Fixing lint.

Reviewed By: kazhang

Differential Revision: D32216681

fbshipit-source-id: 60e2d3c02508c65ec865e603c7155a74cb6bd8b3
cyyever pushed a commit to cyyever/vision that referenced this pull request Nov 16, 2021
…ytorch#4859)

* Adding multiweight suport on Quant MobileNetV2 and MobileNetV3.

* Fixing enum name.

* Fixing lint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multi-pretrained weights: Add model builders for Quantization
3 participants