-
Notifications
You must be signed in to change notification settings - Fork 6.1k
[FEAT] Model loading refactor #10604
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
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
e54c540
first draft model loading refactor
SunMarc 645abc9
revert name change
SunMarc bd81f50
fix bnb
SunMarc 17c1be2
revert name
SunMarc 72b6259
fix dduf
SunMarc b4e4f3b
fix huanyan
SunMarc 5a00dc6
style
SunMarc 3bcd6cc
Merge branch 'main' into model-loading-refactor
sayakpaul 2f671af
Update src/diffusers/models/model_loading_utils.py
SunMarc 7273a94
suggestions from reviews
SunMarc 00f0bd1
Merge remote-tracking branch 'upstream/model-loading-refactor' into m…
SunMarc c5da192
Update src/diffusers/models/modeling_utils.py
SunMarc 039eef5
remove safetensors check
SunMarc 21f94a1
Merge remote-tracking branch 'upstream/model-loading-refactor' into m…
SunMarc 337b2fc
fix default value
SunMarc aedf6af
Merge remote-tracking branch 'upstream/main' into model-loading-refactor
SunMarc 0df7010
more fix from suggestions
SunMarc d3a7dc8
revert logic for single file
SunMarc fc4af16
style
SunMarc 18d61bb
Merge remote-tracking branch 'upstream/main' into model-loading-refactor
SunMarc 26228eb
Merge branch 'main' into model-loading-refactor
sayakpaul 592c878
typing + fix couple of issues
SunMarc 31c7d95
improve speed
SunMarc 1634362
Merge remote-tracking branch 'upstream/model-loading-refactor' into m…
SunMarc 37d59f6
Update src/diffusers/models/modeling_utils.py
SunMarc b48fedc
Merge remote-tracking branch 'upstream/main' into model-loading-refactor
SunMarc 2753abe
fp8 dtype
SunMarc abd3a91
add tests
SunMarc d1c4a61
rename resolved_archive_file to resolved_model_file
SunMarc bcbd493
format
SunMarc 0b1e9f5
map_location default cpu
SunMarc a078342
add utility function
SunMarc 52c7104
switch to smaller model + test inference
SunMarc 28211a4
Apply suggestions from code review
SunMarc e6a8093
rm comment
SunMarc 69dda9a
add log
SunMarc 68a6211
Apply suggestions from code review
SunMarc c2a72d3
add decorator
SunMarc 712f6b8
Merge remote-tracking branch 'upstream/model-loading-refactor' into m…
SunMarc e00d1c4
cosine sim instead
SunMarc 65aec7f
fix use_keep_in_fp32_modules
SunMarc f1138d3
comm
SunMarc 176d30f
Merge branch 'main' into model-loading-refactor
sayakpaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1593,18 +1593,9 @@ def create_diffusers_clip_model_from_ldm( | |
raise ValueError("The provided checkpoint does not seem to contain a valid CLIP model.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DN6 would you like to run the slow single-file tests to ensure we're not breaking anything here (if not already)? |
||
|
||
if is_accelerate_available(): | ||
unexpected_keys = load_model_dict_into_meta(model, diffusers_format_checkpoint, dtype=torch_dtype) | ||
load_model_dict_into_meta(model, diffusers_format_checkpoint, dtype=torch_dtype) | ||
else: | ||
_, unexpected_keys = model.load_state_dict(diffusers_format_checkpoint, strict=False) | ||
|
||
if model._keys_to_ignore_on_load_unexpected is not None: | ||
for pat in model._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: | ||
logger.warning( | ||
f"Some weights of the model checkpoint were not used when initializing {cls.__name__}: \n {[', '.join(unexpected_keys)]}" | ||
) | ||
model.load_state_dict(diffusers_format_checkpoint, strict=False) | ||
sayakpaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if torch_dtype is not None: | ||
model.to(torch_dtype) | ||
|
@@ -2061,16 +2052,7 @@ def create_diffusers_t5_model_from_checkpoint( | |
diffusers_format_checkpoint = convert_sd3_t5_checkpoint_to_diffusers(checkpoint) | ||
|
||
if is_accelerate_available(): | ||
unexpected_keys = load_model_dict_into_meta(model, diffusers_format_checkpoint, dtype=torch_dtype) | ||
if model._keys_to_ignore_on_load_unexpected is not None: | ||
for pat in model._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: | ||
logger.warning( | ||
f"Some weights of the model checkpoint were not used when initializing {cls.__name__}: \n {[', '.join(unexpected_keys)]}" | ||
) | ||
|
||
load_model_dict_into_meta(model, diffusers_format_checkpoint, dtype=torch_dtype) | ||
else: | ||
model.load_state_dict(diffusers_format_checkpoint) | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.