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

Fix configuring VAE from single file mixin #6950

Merged
merged 4 commits into from
Feb 13, 2024
Merged

Fix configuring VAE from single file mixin #6950

merged 4 commits into from
Feb 13, 2024

Conversation

DN6
Copy link
Collaborator

@DN6 DN6 commented Feb 12, 2024

What does this PR do?

The scaling factor isn't correctly set when calling AutoencoderKL.from_single_file for SDXL models. It defaults to the SD scaling factor, leading to a washed out effect on the final image.

Additionally SD.Next uses the config_file argument to pass in the path to the original config file, rather than the original_config_file argument. This is missing in the current Mixin.

This PR:

  1. Allows setting VAE scaling_factor from the VAESingleFileMixin
  2. Update so that AutoencoderKL.from_single_file can accept a config_file argument as well.

Fixes # (issue)
#6923

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.

Sorry, something went wrong.

@DN6 DN6 changed the title update Fix VAE single file scaling factor Feb 12, 2024
@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 changed the title Fix VAE single file scaling factor Fix configuring VAE from single file mixin Feb 12, 2024
Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

Agree with @patrickvonplaten's comment.

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.

hey thanks!
feel free to merge if @sayakpaul and @patrickvonplaten gives ok
I have a few questions (they might be very obvious)

  1. is it that the only way to load it correctly we would need to pass the scale_factor manually?
vae = AutoencoderKL.from_single_file("https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/blob/main/sdxl.vae.safetensors", scaling_factor=0.13025)
  1. is it not possible to infer the correct config based on the checkpoint in infer_original_config_file?

@sayakpaul
Copy link
Member

I think it's because we cannot assume that the scaling factor will always be present in the single-file checkpoint format.

@yiyixuxu
Copy link
Collaborator

@sayakpaul
ohh infer_original_config_file returns a URL to the config file, currently it returns the v1 https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml

I'm just wondering if it's able to know it's sdxl and return correct config URL instead

@yiyixuxu
Copy link
Collaborator

also which one is correct config file for this vae, is it this? https://github.com/Stability-AI/generative-models/blob/main/configs/inference/sd_xl_base.yaml

@DN6
Copy link
Collaborator Author

DN6 commented Feb 13, 2024

ohh infer_original_config_file returns a URL to the config file, currently it returns the v1 https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml

I'm just wondering if it's able to know it's sdxl and return correct config URL instead

I think we can diff the state_dicts between SD 1.5, SD 2 and SDXL to see if there are unique keys for the model type that we could use to infer the config. Essentially in this case, we only have the VAE checkpoint state dict to make our guess. For the pipelines calling from_single_file we rely on using the TextEncoder and UNet to infer the model type.

I can open a follow up PR to look into it.

@yiyixuxu yiyixuxu merged commit a326d61 into main Feb 13, 2024
15 checks passed
yiyixuxu pushed a commit that referenced this pull request Feb 13, 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.

None yet

5 participants