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

don't load state_dict twice when using low_cpu_mem_usage in from_pretrained #16602

Merged
merged 1 commit into from
Apr 6, 2022

Conversation

patil-suraj
Copy link
Contributor

@patil-suraj patil-suraj commented Apr 5, 2022

What does this PR do?

In from_pretrained the state_dict is loaded twice when low_cpu_mem_usage is True, which is not required since the state_dict is already loaded before as we can here.

if not is_sharded:
# Time to load the checkpoint
state_dict = load_state_dict(resolved_archive_file)

So, it's fine to remove it there because when is_sharded=False, the state_dict is loaded at line 1797

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Apr 5, 2022

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

To complete the description, it's fine to remove it there because when is_sharded=False, the state_dict is loaded at line 1797.

@patil-suraj patil-suraj merged commit 47c5c05 into huggingface:main Apr 6, 2022
@patil-suraj patil-suraj deleted the load-sd-once branch April 6, 2022 09:43
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.

4 participants