Skip to content

Fix QuantizableMobileNetV3 weight loading issue #4966

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 2 commits into from
Nov 21, 2021

Conversation

datumbox
Copy link
Contributor

Fixes #4959

cc @pmeier, @NicolasHug This is a bug which wasn't caught due to our current testing strategy. Anything that depends on loading the real weights of the models is currently not covered.

@datumbox datumbox added bug module: models.quantization Issues related to the quantizable/quantized models labels Nov 20, 2021
@facebook-github-bot
Copy link

facebook-github-bot commented Nov 20, 2021

💊 CI failures summary and remediations

As of commit 9d1a609 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


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.

Copy link
Contributor

@prabhat00155 prabhat00155 left a comment

Choose a reason for hiding this comment

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

Thanks @datumbox! Should we add a unit test to cover this?

@datumbox
Copy link
Contributor Author

@prabhat00155 Yes, we should. Unfortunately we can't do it yet. To test it we would need to download the weights and try to load them on the model. Our current practice is to avoid downloading the weights in all tests to avoid flakiness. I think we should review this an redesign our model testing approach. This is probably a big effort and we should plan for it.

@datumbox datumbox merged commit b567028 into pytorch:main Nov 21, 2021
@datumbox datumbox deleted the bug/mobnet3_quantize_weights branch November 21, 2021 21:34
@pmeier
Copy link
Collaborator

pmeier commented Nov 22, 2021

IIUC, we want to test loading the state dict, right? If yes, the solution is probably not that hard to achieve. Can't we have a separate test that loads the model with pretrained=False and then does something like

from collections import OrderedDict

state_dict = OrderedDict([(name, torch.randn_like(weight)) for name, weight in model.state_dict()])
model.load_state_dict(state_dict)
torch.testing.assert_close(model.state_dict(), state_dict)

@datumbox
Copy link
Contributor Author

@pmeier It's a creative proposal. :) Unfortunately I don't think this tests all scenarios because it assumes that the current keys retrieved from mode.state_dict() are the same as in the stored weights. This can be an incorrect assumption, especially when large scale refactoring is involved (see #4487). Moreover, there are situations where depending on the parameters passed to the builder methods, the behaviour changes. An example of this is the current bug fix. I don't believe you can cover this with the proposed trick. What we need to do is download the weights and ensure they still load properly.

@pmeier
Copy link
Collaborator

pmeier commented Nov 22, 2021

In that case, there is probably little we can do besides #4772 or downloading the weights in the background while doing something not I/O bound such as compiling torchvision.

facebook-github-bot pushed a commit that referenced this pull request Nov 30, 2021
Reviewed By: NicolasHug

Differential Revision: D32694308

fbshipit-source-id: 1fde05de57fb7d0911a8b86ea364f66dc33bfe78
datumbox added a commit to datumbox/vision that referenced this pull request Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ciflow/default cla signed module: models.quantization Issues related to the quantizable/quantized models
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QuantizableMobileNetV3 Can not load pretrained model
4 participants