-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
Fix loading models with mismatched sizes #36463
Fix loading models with mismatched sizes #36463
Conversation
mismatched_names = [name for name, _, _ in mismatched_keys] | ||
fixed_state_dict = {k: v for k, v in state_dict.items() if k not in mismatched_names} | ||
fixed_state_dict = model_to_load._fix_state_dict_keys_on_load(fixed_state_dict) | ||
model_to_load.load_state_dict(fixed_state_dict, strict=False, assign=assign_to_params_buffers) |
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.
strict=False
does not allow loading weights with mismatched sizes, filter those keys first
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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.
Thanks! This is a much better solution than the try/catch I initially was doing.
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.
Super nice fix merging to get this asap
* Fix loading model with mismatched sizes * trigger tests
* Fix loading model with mismatched sizes * trigger tests
What does this PR do?
Fix loading model with mismatched sizes, the bug was introduced since:
Reported in
Fixes: #36464
Minimal reproducing example:
cc @ArthurZucker