-
Notifications
You must be signed in to change notification settings - Fork 30.2k
fix(modeling_utils): correct initialization of missing and mismatched… #40093
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?
Conversation
… keys - Update the _initialize_missing_keys method to handle both missing and mismatched keys - Ensure proper initialization of weights when loading pretrained models
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.
yep a good fix but let's isolate
src/transformers/generation/utils.py
Outdated
# Handle potential NaN values in accumulated_log_probs | ||
probs = nn.functional.softmax(accumulated_log_probs, dim=-1) | ||
# Replace NaN values with uniform distribution | ||
if torch.isnan(probs).any(): | ||
# Create a mask for NaN positions | ||
nan_mask = torch.isnan(probs) | ||
# Replace NaN with a small uniform probability | ||
probs = torch.where(nan_mask, torch.ones_like(probs) / probs.shape[-1], probs) | ||
# Renormalize to ensure probabilities sum to 1 | ||
probs = probs / probs.sum(dim=-1, keepdim=True) | ||
topk_indices = torch.multinomial(probs, num_samples=beams_to_keep) |
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.
I like that, but it needs a separate issue!
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.
I see it, but I do this because of seeing the circle ci failed and I try to solve it.
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.
I get you, the test failing is probably unrelated to your changes no?
cc @Cyrilvallez as I don't have time to check! |
Hey! The argument given is all keys present in the checkpoints - we then take the set inverse of that to init the other keys. So everything is initialized correctly 🙂🤗 So I believe this PR is wrong! Let me know if you have any repro that could make you think otherwise! |
Fixes #40001
@ArthurZucker