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

[Core] Harmonize single file ckpt model loading #6971

Merged
merged 6 commits into from
Feb 14, 2024

Conversation

sayakpaul
Copy link
Member

What does this PR do?

Currently, we make use of set_module_tensor_to_device in the single file loading utilities to speed up model loading time. However, in src/models/modeling_utils.py, we already have a utility called load_model_dict_into_meta() that abstracts the boilerplate code.

def load_model_dict_into_meta(

This PR updates the single file utilities to use load_model_dict_into_meta() as well.

I have run the single-file SLOW tests, but @DN6, feel free to do so on your end, too, just to be sure.

@sayakpaul sayakpaul requested a review from DN6 February 14, 2024 03:57
@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.

for pat in vae._keys_to_ignore_on_load_unexpected:
unexpected_keys = [k for k in unexpected_keys if re.search(pat, k) is None]

if len(unexpected_keys) > 0:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Small nit. Since unexpected_keys is always of type list we can just use

if unexpected_keys:
   ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I followed what's done in modeling_utils.py to be consistent.

@@ -48,6 +48,7 @@ def build_sub_model_components(
load_safety_checker=False,
model_type=None,
image_size=None,
torch_dtype=None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice catch!

Copy link
Collaborator

@DN6 DN6 left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏽

@sayakpaul sayakpaul merged commit 4343ce2 into main Feb 14, 2024
15 checks passed
@sayakpaul sayakpaul deleted the single-file-ckpt-model-loading branch February 14, 2024 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants