Skip to content

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

Open
wants to merge 30 commits into
base: main
Choose a base branch
from

Conversation

bvantuan
Copy link
Contributor

@bvantuan bvantuan commented Jul 6, 2025

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

@bvantuan bvantuan marked this pull request as draft July 6, 2025 15:14
@ArthurZucker
Copy link
Collaborator

cc @Cyrilvallez as we are also working on putting the default in the PreTrainedModel

@Cyrilvallez
Copy link
Member

Super happy to see you're following again on a new batch of models @bvantuan! 🚀🤗 Let me know when this is ready!

@bvantuan
Copy link
Contributor Author

bvantuan commented Jul 7, 2025

Yes, of course! Really excited to keep contributing whenever I have time.

Copy link
Contributor

github-actions bot commented Jul 9, 2025

[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

Comment on lines +605 to +606
elif isinstance(module, BrosRelationExtractor):
nn.init.normal_(module.dummy_node, std=std)
Copy link
Contributor Author

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)):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +445 to +461
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bvantuan
Copy link
Contributor Author

bvantuan commented Jul 9, 2025

Cc @Cyrilvallez ! The PR is now ready and awaiting your review😊.

@bvantuan bvantuan marked this pull request as ready for review July 9, 2025 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants