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

[Single File] Support loading Comfy UI Flux checkpoints #9243

Merged
merged 1 commit into from
Aug 23, 2024
Merged

Conversation

DN6
Copy link
Collaborator

@DN6 DN6 commented Aug 22, 2024

What does this PR do?

ComfyUI single file checkpoints sometimes have different prefixes for certain model components. For example all diffusion models have the prefix model.diffusion_model which follows the naming convention used in the originial SD repo. This also applies to ComfyUI checkpoints for Flux, where the model.diffusion_model prefix is added to the original state dict keys.

In certain cases the Autoencoder prefix might be "vae" which is the case for Flux.

This PR adds additional checks to account for these differences.

Note: It would be better to actually refactor our single file loading to remove all these prefixes before running the conversion. This PR is a bit of a band aid solution because a lot of our loading logic is written with the assumption that the prefixes remain in the checkpoints.

The individual model conversion functions rely on these prefixes to extract the relevant weights of the model components, but they end up removing the prefixes during the actual conversion of the weights. Rewriting these conversion functions would be a bit involved, and require a bit of time to make sure there are no backwards breaking changes. I'll open a future PR to do a proper clean up of the conversion logic.

Fixes # (issue)

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@DN6 DN6 requested a review from yiyixuxu August 22, 2024 09:27
@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.

@DN6 DN6 mentioned this pull request Aug 22, 2024
6 tasks
Copy link
Collaborator

@yiyixuxu yiyixuxu left a comment

Choose a reason for hiding this comment

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

thanks!

@@ -267,7 +270,6 @@
"cond_stage_model.transformer.",
"conditioner.embedders.0.transformer.",
]
OPEN_CLIP_PREFIX = "conditioner.embedders.0.model."
Copy link
Collaborator

Choose a reason for hiding this comment

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

did we just happen to find this line not needed (i.e. this is not relevant to the fix)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah it was left over and not used anywhere.

@DN6 DN6 merged commit 255ac59 into main Aug 23, 2024
18 checks passed
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