[Single File] Support loading Comfy UI Flux checkpoints #9243
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.
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 themodel.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
documentation guidelines, and
here are tips on formatting docstrings.
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.