-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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 SD2.X clip single file load projection_dim #10770
base: main
Are you sure you want to change the base?
Conversation
Infer projection_dim from the checkpoint before loading from pretrained, override any incorrect hub config. Hub configuration for SD2.X specifies projection_dim=512 which is incorrect for SD2.X checkpoints loaded from civitai and similar. Exception was previously thrown upon attempting to load_model_dict_into_meta for SD2.X single file checkpoints. Such LDM models usually require projection_dim=1024
@Teriks could you share an example I can use to reproduce the error? Along with a link to the checkpoint you're trying to use? |
Model page: https://civitai.com/models/2711/21-sd-modern-buildings-style-md Checkpoint: https://civitai.com/api/download/models/3002?type=Model&format=PickleTensor&size=full&fp=fp16 Original Config: https://civitai.com/api/download/models/3002?type=Config&format=Other Here is a reproducible error condition script, and checkpoint to test. This exception happens with any LDM checkpoint hosted on CivitAI under SD2.0 and SD2.1 checkpoints. There is probably additional config for some models needed to make them work, the fix I am applying just makes most of them function out of the box. import diffusers
# https://civitai.com/models/2711/21-sd-modern-buildings-style-md
# This is the ckpt and YAML config from the same page
# https://civitai.com/api/download/models/3002?type=Model&format=PickleTensor&size=full&fp=fp16
# https://civitai.com/api/download/models/3002?type=Config&format=Other
# this will fail with an exception
pipe = diffusers.StableDiffusionPipeline.from_single_file(
'21SDModernBuildings_midjourneyBuildings.ckpt',
original_config='21SDModernBuildings_midjourneyBuildings.yaml') This fails with this exception due to
|
diffusers/src/diffusers/loaders/single_file_utils.py Lines 1449 to 1454 in b75b204
diffusers/src/diffusers/loaders/single_file_utils.py Lines 1488 to 1492 in b75b204
We're getting The issue is with
self.text_projection = nn.Linear(config.hidden_size, config.projection_dim, bias=False)
self.embed_dim = config.hidden_size
self.q_proj = nn.Linear(self.embed_dim, self.embed_dim) >>> torch.nn.Linear(1024, 512).state_dict()["weight"].shape
torch.Size([512, 1024])
This would be WDYT @DN6? |
Infer
projection_dim
from the checkpoint before loading from pretrained, override any incorrect hub config.Hub configuration for SD2.X specifies
projection_dim=512
which is incorrect for SD2.X checkpoints loaded from civitai and similar.Exception was previously thrown upon attempting to
load_model_dict_into_meta
for SD2.X single file checkpoints.Such LDM models usually require
projection_dim=1024
for the clip encoder.What does this PR do?
Fixes # (issue)
Before submitting
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@sayakpaul @yiyixuxu @DN6