Skip to content

Add controlnet and vae from single file #4084

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
merged 6 commits into from
Jul 19, 2023

Conversation

patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented Jul 13, 2023

What does this PR do?

Working on solving the following issue (+ all the linked ones):
#3907

ControlNet:

from diffusers import StableDiffusionControlnetPipeline, ControlNetModel

url = "https://huggingface.co/lllyasviel/ControlNet-v1-1/blob/main/control_v11p_sd15_canny.pth"  # can also be a local path
model = ControlNetModel.from_single_file(url)

url = "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned.safetensors" # can also be a local path
pipe = StableDiffusionControlnetPipeline.from_single_file(url, controlnet=controlnet)

StableDiffusionControlnetImg2ImgPipeline and StableDiffusionControlnetIinpaintPipeline work fine as well

VAE

from diffusers import AutoencoderKL

url = "https://huggingface.co/stabilityai/sd-vae-ft-mse-original/blob/main/vae-ft-mse-840000-ema-pruned.safetensors"  # can also be local file
model = AutoencoderKL.from_single_file(url)

Also cc @vladmandic

@patrickvonplaten patrickvonplaten marked this pull request as draft July 13, 2023 21:20
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jul 13, 2023

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

@patrickvonplaten patrickvonplaten changed the title [WIP] Add controlnet from single file [WIP] Add controlnet and vae from single file Jul 17, 2023
@EmilioNicolas
Copy link

EmilioNicolas commented Jul 18, 2023

Looking forward to the merge! Thanks for the PR @patrickvonplaten

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.

Looks very nice.

Just wondering if it makes sense to make the passing of the checkpoint names a little less verbose. WDYT about the following?

model = ControlNetModel.from_single_file("lllyasviel/ControlNet-v1-1", filename="control_v11p_sd15_canny.pth")

Not too strongly opinionated about it either.

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.

awesome!

@hzhou17
Copy link

hzhou17 commented Jul 18, 2023

Thank you to everyone that has been working on this. But I still get this error:

"An error occurred during inpainting: type object 'StableDiffusionControlNetInpaintPipeline' has no attribute 'from_single_file"

diffusers version: 0.18.2

Is there something else that I need to update?

@sayakpaul
Copy link
Member

@hzhou17 I think you need to install from the branch being used in this PR:

!pip install git+https://github.com/huggingface/diffusers@add_from_single_file_controlnet_vae -q

Here's a Colab Notebook that successfully loads the checkpoints from single files into a StableDiffusionControlNetInpaintPipeline: https://colab.research.google.com/gist/sayakpaul/f99fd09d7817a6189bcc7b54b2757124/scratchpad.ipynb

@patrickvonplaten
Copy link
Contributor Author

Looks very nice.

Just wondering if it makes sense to make the passing of the checkpoint names a little less verbose. WDYT about the following?

model = ControlNetModel.from_single_file("lllyasviel/ControlNet-v1-1", filename="control_v11p_sd15_canny.pth")

Not too strongly opinionated about it either.

Yes I understand this 100% and thought about it as well - a couple of problems which made me go the current way:

@sayakpaul
Copy link
Member

@patrickvonplaten feel free to merge whenever :) Thanks for explaining #4084 (comment).

@patrickvonplaten patrickvonplaten merged commit 6b1abba into main Jul 19, 2023
@zxf2012
Copy link

zxf2012 commented Jul 20, 2023

thanks so much

@patrickvonplaten patrickvonplaten deleted the add_from_single_file_controlnet_vae branch July 20, 2023 15:45
Comment on lines -1292 to 1294
if controlnet:
controlnet_model = convert_controlnet_checkpoint(
controlnet = convert_controlnet_checkpoint(
checkpoint, original_config, checkpoint_path, image_size, upcast_attention, extract_ema
)
Copy link
Contributor

@williamberman williamberman Jul 20, 2023

Choose a reason for hiding this comment

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

iamwavecut#1 this might have introduced a bug @patrickvonplaten

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It did indeed haha. Solved as explained in iamwavecut#1

orpatashnik pushed a commit to orpatashnik/diffusers that referenced this pull request Aug 1, 2023
* Add controlnet from single file

* Updates

* make style

* finish

* Apply suggestions from code review

Co-authored-by: Sayak Paul <[email protected]>

---------

Co-authored-by: Sayak Paul <[email protected]>
orpatashnik pushed a commit to orpatashnik/diffusers that referenced this pull request Aug 1, 2023
* Add controlnet from single file

* Updates

* make style

* finish

* Apply suggestions from code review

Co-authored-by: Sayak Paul <[email protected]>

---------

Co-authored-by: Sayak Paul <[email protected]>
orpatashnik pushed a commit to orpatashnik/diffusers that referenced this pull request Aug 1, 2023
* Add controlnet from single file

* Updates

* make style

* finish

* Apply suggestions from code review

Co-authored-by: Sayak Paul <[email protected]>

---------

Co-authored-by: Sayak Paul <[email protected]>
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* Add controlnet from single file

* Updates

* make style

* finish

* Apply suggestions from code review

Co-authored-by: Sayak Paul <[email protected]>

---------

Co-authored-by: Sayak Paul <[email protected]>
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* Add controlnet from single file

* Updates

* make style

* finish

* Apply suggestions from code review

Co-authored-by: Sayak Paul <[email protected]>

---------

Co-authored-by: Sayak Paul <[email protected]>
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.

8 participants