Skip to content

Add Differential Diffusion to Kolors #9423

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 17 commits into from
Oct 11, 2024

Conversation

saqlain2204
Copy link
Contributor

@saqlain2204 saqlain2204 commented Sep 12, 2024

What does this PR do?

Adds Differential Diffusion to Kolors

Fixes Partially #8924

@a-r-r-o-w @DN6

import torch

from diffusers.utils import load_image
from pipeline_kolors_differential_img2img import KolorsDifferentialImg2ImgPipeline

pipe = KolorsDifferentialImg2ImgPipeline.from_pretrained(
             "Kwai-Kolors/Kolors-diffusers", variant="fp16", torch_dtype=torch.float16
       )
pipe.enable_model_cpu_offload()

source_image = load_image(
    "https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/20240329211129_4024911930.png"
)
map = load_image(
    "https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/gradient_mask_2.png"
)
prompt = "a green pear"
negative_prompt = "blurry"

image = pipe(
    prompt=prompt,
    negative_prompt=negative_prompt,
    image=source_image,
    num_inference_steps=28,
    guidance_scale=4.5,
    strength=1.0,
    map=map,
).images[0]

@saqlain2204
Copy link
Contributor Author

saqlain2204 commented Sep 12, 2024

I am not able to load kolors in colab free tier. Tried to resolve it by using memory optimizations, but it dint work. Am I going wrong somewhere?

@saqlain2204 saqlain2204 changed the title Kolors diffdiff Add Differential Diffusion to Kolors Sep 12, 2024
@a-r-r-o-w
Copy link
Member

Thanks for working on this! For Kolors, I think @asomoza might be able to share some suggestions on how to save memory and minimal VRAM requirements as he worked on it. If it doesn't work on a free-tier colab, I'll try and test the PR :)

@saqlain2204
Copy link
Contributor Author

Sure. Thanks :)

@asomoza
Copy link
Member

asomoza commented Oct 7, 2024

Hi @saqlain2204 sorry I missed this for so long. Kolors uses a big text encoder and a custom one that isn't in transformers yet so we can't optimize it for now, so for the time being, we can't use a quantized version of it.

As I remember the text encoder is around 10GB and the unet 6 GB so they won't fit in the free tier colab GPU, don't remember how much RAM it has to store them in the CPU, but it should work with enable_model_cpu_offload. There was a problem before where the VRAM wasn't getting freed but that was fixed a while ago, maybe you can try again.

If it doesn't work like this, sadly we won't be able to optimize it just yet so it can run on the free tier colab.

@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Oct 9, 2024

should we merge this? @asomoza

@saqlain2204
Copy link
Contributor Author

Hi @asomoza ,
Thanks for the suggestions. Will try running it by making the above changes and update it here.

@asomoza
Copy link
Member

asomoza commented Oct 9, 2024

@saqlain2204 can you update the description with the typical examples we use for diff-diff, you can get them from the SD3 implementation.

This way you and we can make sure it works which is pretty much the only requirement for community pipelines. From a quick look, it seems you're missing the map/mask input so there's no way to pass the depthmap/mask to the pipeline call method.

@saqlain2204
Copy link
Contributor Author

I have updated. Can you please review it.

Copy link
Member

@asomoza asomoza left a comment

Choose a reason for hiding this comment

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

we need a couple of fixes, the rest looks good

@asomoza
Copy link
Member

asomoza commented Oct 10, 2024

@saqlain2204 can you please run make style and make quality

@asomoza
Copy link
Member

asomoza commented Oct 11, 2024

thanks!

@asomoza asomoza merged commit 3033f08 into huggingface:main Oct 11, 2024
7 of 8 checks passed
@saqlain2204
Copy link
Contributor Author

👍

@saqlain2204 saqlain2204 deleted the kolors-diffdiff branch October 11, 2024 13:48
@saqlain2204
Copy link
Contributor Author

Thanks @a-r-r-o-w @asomoza !

sayakpaul pushed a commit that referenced this pull request Oct 11, 2024
* Added diff diff support for kolors img2img

* Fized relative imports

* Fized relative imports

* Added diff diff support for Kolors

* Fized import issues

* Added map

* Fized import issues

* Fixed naming issues

* Added diffdiff support for Kolors img2img pipeline

* Removed example docstrings

* Added map input

* Updated latents

Co-authored-by: Álvaro Somoza <[email protected]>

* Updated `original_with_noise`

Co-authored-by: Álvaro Somoza <[email protected]>

* Improved code quality

---------

Co-authored-by: Álvaro Somoza <[email protected]>
sayakpaul added a commit that referenced this pull request Oct 16, 2024
…#9622)

* log a warning when there are missing keys in the LoRA loading.

* handle missing keys and unexpected keys better.

* add tests

* fix-copies.

* updates

* tests

* concat warning.

* Add Differential Diffusion to Kolors (#9423)

* Added diff diff support for kolors img2img

* Fized relative imports

* Fized relative imports

* Added diff diff support for Kolors

* Fized import issues

* Added map

* Fized import issues

* Fixed naming issues

* Added diffdiff support for Kolors img2img pipeline

* Removed example docstrings

* Added map input

* Updated latents

Co-authored-by: Álvaro Somoza <[email protected]>

* Updated `original_with_noise`

Co-authored-by: Álvaro Somoza <[email protected]>

* Improved code quality

---------

Co-authored-by: Álvaro Somoza <[email protected]>

* FluxMultiControlNetModel (#9647)

* tests

* Update src/diffusers/loaders/lora_pipeline.py

Co-authored-by: YiYi Xu <[email protected]>

* fix

---------

Co-authored-by: M Saqlain <[email protected]>
Co-authored-by: Álvaro Somoza <[email protected]>
Co-authored-by: hlky <[email protected]>
Co-authored-by: YiYi Xu <[email protected]>
sayakpaul pushed a commit that referenced this pull request Dec 23, 2024
* Added diff diff support for kolors img2img

* Fized relative imports

* Fized relative imports

* Added diff diff support for Kolors

* Fized import issues

* Added map

* Fized import issues

* Fixed naming issues

* Added diffdiff support for Kolors img2img pipeline

* Removed example docstrings

* Added map input

* Updated latents

Co-authored-by: Álvaro Somoza <[email protected]>

* Updated `original_with_noise`

Co-authored-by: Álvaro Somoza <[email protected]>

* Improved code quality

---------

Co-authored-by: Álvaro Somoza <[email protected]>
sayakpaul added a commit that referenced this pull request Dec 23, 2024
…#9622)

* log a warning when there are missing keys in the LoRA loading.

* handle missing keys and unexpected keys better.

* add tests

* fix-copies.

* updates

* tests

* concat warning.

* Add Differential Diffusion to Kolors (#9423)

* Added diff diff support for kolors img2img

* Fized relative imports

* Fized relative imports

* Added diff diff support for Kolors

* Fized import issues

* Added map

* Fized import issues

* Fixed naming issues

* Added diffdiff support for Kolors img2img pipeline

* Removed example docstrings

* Added map input

* Updated latents

Co-authored-by: Álvaro Somoza <[email protected]>

* Updated `original_with_noise`

Co-authored-by: Álvaro Somoza <[email protected]>

* Improved code quality

---------

Co-authored-by: Álvaro Somoza <[email protected]>

* FluxMultiControlNetModel (#9647)

* tests

* Update src/diffusers/loaders/lora_pipeline.py

Co-authored-by: YiYi Xu <[email protected]>

* fix

---------

Co-authored-by: M Saqlain <[email protected]>
Co-authored-by: Álvaro Somoza <[email protected]>
Co-authored-by: hlky <[email protected]>
Co-authored-by: YiYi Xu <[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.

4 participants