-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Move all weight initializations from private methods to constructors #5331
Merged
datumbox
merged 7 commits into
pytorch:main
from
datumbox:models/weight_init_in_constructor
Feb 2, 2022
Merged
Move all weight initializations from private methods to constructors #5331
datumbox
merged 7 commits into
pytorch:main
from
datumbox:models/weight_init_in_constructor
Feb 2, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
💊 CI failures summary and remediationsAs of commit 49037a2 (more details on the Dr. CI page):
1 failure not recognized by patterns:
This comment was automatically generated by Dr. CI (expand for details).Please report bugs/suggestions to the (internal) Dr. CI Users group. |
fmassa
approved these changes
Feb 2, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
facebook-github-bot
pushed a commit
that referenced
this pull request
Feb 11, 2022
…tructors (#5331) Summary: * Move weight initialization in constructors. * Fixing mypy for ViT. * remove unnecessary import Reviewed By: NicolasHug Differential Revision: D34140261 fbshipit-source-id: e9fd49cd5d7d39aa8d557d5f6efb9fbf92b80f94
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The main idiom for weight initialisation in TorchVision is to do it within constructors. Nevertheless, there is limited use of another idiom of placing the initialization in a separate private method and calling it from constructor. Though the two can be considered equivalent (the method is private after all), the use of the latter idiom can lead to gotchas.
It's worth noting that TorchVision users have the appetite for being able to re-initialize the weights (see #3410) and thus some might be tempted to call the private method directly. Unfortunately having such a method currently stumbles upon fundamental FX limitations and can lead to inheritance issues. Thus there are cases (for example after using TorchVision's Feature Extraction util) where if one calls the private method to reinitialize the model, the code won't work or even break. By moving the initialization within the constructor, we make it impossible for someone to shoot themselves in the foot. Until proper support is added for this feature in PyTorch (see pytorch/pytorch#71404), TorchVision should use idioms that minimize the chance of gotchas.