Skip to content

small tweaks for parsing thibaudz controlnet checkpoints #3657

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

Conversation

williamberman
Copy link
Contributor

re: #2774

Comment on lines +78 to +93

# small workaround to get argparser to parse a boolean input as either true _or_ false
def parse_bool(string):
if string == "True":
return True
elif string == "False":
return False
else:
raise ValueError(f"could not parse string as bool {string}")

parser.add_argument(
"--use_linear_projection", help="Override for use linear projection", required=False, type=parse_bool
)

parser.add_argument("--cross_attention_dim", help="Override for cross attention_dim", required=False, type=int)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are overrides for these two configs which aren't correctly set for the config file https://huggingface.co/thibaud/controlnet-sd21/blob/main/control_v11p_sd21_openpose.yaml

Comment on lines +349 to +350
if skip_extract_state_dict:
unet_state_dict = checkpoint
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this allows us to skip the initial key trimming for when the root level checkpoint doesn't need to be trimmed. If we don't manually skip it, the unet_state_dict will be empty because none of the keys have the expected prefix

Comment on lines +986 to +992
# Some controlnet ckpt files are distributed independently from the rest of the
# model components i.e. https://huggingface.co/thibaud/controlnet-sd21/
if "time_embed.0.weight" in checkpoint:
skip_extract_state_dict = True
else:
skip_extract_state_dict = False

Copy link
Contributor Author

@williamberman williamberman Jun 3, 2023

Choose a reason for hiding this comment

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

In the controlnet case, we can manually perform the check if this is the root level state dict

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 3, 2023

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

@patrickvonplaten
Copy link
Contributor

Nice! Good to merge for me once the following tests pass:

class StableDiffusionPipelineCkptTests(unittest.TestCase):

@williamberman
Copy link
Contributor Author

confirmed pass!

@williamberman williamberman merged commit 462956b into huggingface:main Jun 5, 2023
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
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