-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Fix missing initializations for models created in 2023 #39239
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
base: main
Are you sure you want to change the base?
Fix missing initializations for models created in 2023 #39239
Conversation
cc @Cyrilvallez as we are also working on putting the default in the PreTrainedModel |
Super happy to see you're following again on a new batch of models @bvantuan! 🚀🤗 Let me know when this is ready! |
Yes, of course! Really excited to keep contributing whenever I have time. |
[For maintainers] Suggested jobs to run (before merge) run-slow: align, autoformer, bridgetower, bros, clap, clvp, efficientnet, fastspeech2_conformer, informer, kosmos2, mgp_str, mobilevit, mobilevitv2, mra, nllb_moe, owlv2 |
elif isinstance(module, BrosRelationExtractor): | ||
nn.init.normal_(module.dummy_node, std=std) |
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.
elif isinstance(module, nn.Embedding): | ||
module.weight.data.normal_(mean=0.0, std=factor * 0.02) | ||
|
||
elif isinstance(module, nn.LayerNorm): | ||
elif isinstance(module, (nn.LayerNorm, nn.BatchNorm2d)): |
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.
elif isinstance(module, nn.Linear): | ||
shape = module.weight.data.shape | ||
gain = 1.0 | ||
scale = 1.0 # extra scale for gain | ||
if module.bias is not None: | ||
module.bias.data.zero_() | ||
if shape[0] > shape[1]: | ||
gain = math.sqrt(shape[0] / shape[1]) | ||
if shape[0] == self.config.vocab_size and shape[1] == self.config.hidden_size: # final projection? | ||
scale = 0.5 | ||
|
||
gain *= scale | ||
nn.init.orthogonal_(module.weight, gain=gain) | ||
elif isinstance(module, nn.Embedding): | ||
shape = module.weight.data.shape | ||
gain = 1e-4 * math.sqrt(max(shape[0], shape[1])) | ||
nn.init.orthogonal_(module.weight, gain=gain) |
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.
Cc @Cyrilvallez ! The PR is now ready and awaiting your review😊. |
What does this PR do?
Fixes missing weight initializations for models created in 2023.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@Cyrilvallez