Skip to content
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 load_checkpoint_in_model behavior when unexpected keys are in the checkpoint #2588

Merged
merged 3 commits into from
Mar 26, 2024

Conversation

fxmarty
Copy link
Contributor

@fxmarty fxmarty commented Mar 26, 2024

Up to now, load_checkpoint_in_model would behave differently when the checkpoint to be loaded has unexpected keys compared to the model state_dict keys.

With device_map=None input, we are currently not erroring out, while with device_map not None, we are erroring out.

This PR aligns the behavior of both, defaulting to strict=False, and logs the unloaded keys.

buffer_names = [name for name, _ in model.named_buffers()]
for checkpoint_file in checkpoint_files:
checkpoint = load_state_dict(checkpoint_file, device_map=device_map)
loaded_checkpoint = load_state_dict(checkpoint_file, device_map=device_map)
Copy link
Contributor Author

@fxmarty fxmarty Mar 26, 2024

Choose a reason for hiding this comment

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

This variable is renamed because it overrides the function input checkpoint needed later.

@HuggingFaceDocBuilderDev

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.

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

LGTM ! Thanks for fixing this !

@fxmarty fxmarty merged commit 4378b56 into main Mar 26, 2024
25 checks passed
@fxmarty fxmarty deleted the align-behavior-unexpected-param-in-state-dict branch March 26, 2024 15:36
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