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

[Community] AnimateDiff + Controlnet Pipeline #5928

Merged

Conversation

a-r-r-o-w
Copy link
Member

@a-r-r-o-w a-r-r-o-w commented Nov 25, 2023

What does this PR do?

Community pipeline version for #5866.

Colab Notebook

Before submitting

Who can review?

@yiyixuxu @patrickvonplaten

@a-r-r-o-w
Copy link
Member Author

a-r-r-o-w commented Nov 25, 2023

Hi @charchit7 @staghado @EdoardoBotta. I've opened this PR since I had some free time today and was trying to implement the community version of this as Yiyi suggested. I was only able to get in touch with charchit7 on discord and it seems like he's a little busy currently. If you're still interested, and if anyone else is looking to help out with the implementation, please DM on wandereronarock#0000 (Arrow#1334) so I can add you as a collaborator to my fork and colab notebook.

@charchit7
Copy link
Contributor

charchit7 commented Nov 25, 2023

Sure, go ahead @a-r-r-o-w I'll hope in 5 days. You can add me if that'll not be too late. (Ref PR : #5872)
Also, please check the issue No. is 5866.

@EdoardoBotta
Copy link
Contributor

EdoardoBotta commented Nov 25, 2023

@a-r-r-o-w I'm interested in being added. I have also been experimenting with the pipelines at https://github.com/EdoardoBotta/diffusers/blob/controlanimate/examples/community/animatediff_controlnet.py. It would be great to merge the changes.

@a-r-r-o-w
Copy link
Member Author

Sure, go ahead @a-r-r-o-w I'll hope in 5 days. You can add me if that'll not be too late. (Ref PR : #5872)
Also, please check the issue No. is 5866.

@charchit7 Sure! Thanks for pointing out the incorrect issue number - fixed.

@a-r-r-o-w I'm interested in being added. I have also been experimenting with the pipelines at https://github.com/EdoardoBotta/diffusers/blob/controlanimate/examples/community/animatediff_controlnet.py. It would be great to merge the changes.

@EdoardoBotta Sending a collaborator invite to my fork. After taking a quick look, it seems like we've both adopted code from existing pipelines and have similar changes for the most part. I've currently commented out all MultiControlNet related stuff since I wanted a single one to work first. Would be great if you could add in those changes!

@a-r-r-o-w
Copy link
Member Author

a-r-r-o-w commented Nov 25, 2023

@yiyixuxu Seems like it works, however I'm not too sure about the quality. Will run a few experiments to see if this can be improved.

Edit: Referencing #5881 here because of the similarity in output quality.

Results
SG161222/Realistic_Vision_V5.1_noVAE
gif-1 gif-2
CardosAnime
gif-1 gif-2

@a-r-r-o-w a-r-r-o-w marked this pull request as ready for review November 26, 2023 00:29
@a-r-r-o-w a-r-r-o-w changed the title [WIP] [Community] AnimateDiff + Controlnet Pipeline [Community] AnimateDiff + Controlnet Pipeline Nov 26, 2023
a-r-r-o-w and others added 2 commits November 26, 2023 08:09
Co-Authored-By: EdoardoBotta <[email protected]>
@yiyixuxu
Copy link
Collaborator

cc @DN6 here

@charchit7 charchit7 mentioned this pull request Nov 27, 2023
6 tasks
Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

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

Super cool pipeline!
Could you also add a short section to https://github.com/huggingface/diffusers/blob/main/examples/community/README.md ?

@a-r-r-o-w
Copy link
Member Author

Ah, forgot doing that. Doing so now

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

@a-r-r-o-w a-r-r-o-w mentioned this pull request Dec 5, 2023
2 tasks
@loboere
Copy link

loboere commented Dec 6, 2023

How can I make the controlnet only affect the first frame or certain frames?
I want animatediff to generate the animation based on the frames affected by controlnet
I want to use a single image canny ,but currently it affects all frames, animatediff can't do much since controlnet canny affects all frames

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

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

Good to merge for me once all tests are green

@yiyixuxu yiyixuxu merged commit 978dec9 into huggingface:main Dec 7, 2023
14 checks passed
@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Dec 7, 2023

@a-r-r-o-w
merged! 🥳

@a-r-r-o-w a-r-r-o-w deleted the animatediff-controlnet-combined branch December 7, 2023 07:39
@a-r-r-o-w
Copy link
Member Author

a-r-r-o-w commented Dec 7, 2023

@a-r-r-o-w merged! 🥳

wow, awesome ❤️ this is probably the first PR I consider as actual good work from my end haha.

Also big thanks to @EdoardoBotta. He had something working as well on his fork which helped with the multicontrolnet support that I couldn't get working initially.

How can I make the controlnet only affect the first frame or certain frames?
I want animatediff to generate the animation based on the frames affected by controlnet
I want to use a single image canny ,but currently it affects all frames, animatediff can't do much since controlnet canny affects all frames

@loboere I definitely think this is possible. Let me try to experiment a bit and I'll add to this pipeline if I'm able to get it to work.

sayakpaul pushed a commit that referenced this pull request Dec 7, 2023
* begin work on animatediff + controlnet pipeline

* complete todos, uncomment multicontrolnet, input checks

Co-Authored-By: EdoardoBotta <[email protected]>

* update

Co-Authored-By: EdoardoBotta <[email protected]>

* add example

* update community README

* Update examples/community/README.md

---------

Co-authored-by: EdoardoBotta <[email protected]>
Co-authored-by: Patrick von Platen <[email protected]>
sayakpaul added a commit that referenced this pull request Dec 7, 2023
@charchit7
Copy link
Contributor

@a-r-r-o-w, @EdoardoBotta nicely done!

@rmasiso
Copy link

rmasiso commented Dec 10, 2023

This is incredible work! Well done!!! This is very exciting. Thank you for setting this up for all of us. I was wondering if you guys knew of a strategy to have consistent animations past the 16 frame limit? Say for example, a video of 32 frames, I run this for the first 16, then I would run this again for the next 16 frames, but when I stitch it together, it's obvious when the first 16 frames end. I've tried setting the seed manually, but that doesn't seem to work. The weirdest part is that the same seed works to generate the same 16 frames whether its the first half or the second half. I've tried including the first frame and the last 16 frames to see if it had to do with the interpolation that included the first frame, but that doesn't seem to work. This is for the pose or canny controlnets. I'm on a m2 macbook pro, so I can't really run things in a single python script before I run out of memory. My strategy so far has been running python animatediff.py 0 16 and then python aniamtediff.py 16 32 -- any ideas? Thank you!

Edit: I just really have to emphasize, how amazing it is that this was set up by all of you. Thanks again!
Edit 2: My guess is that this is a torch seed issue? It's hard to be deterministic with torch when I'm running the script twice, but separately, correct? In a perfect world, I would have a for loop and just do 16 frames at a time within the same script, but as I mentioned (memory issues).
Edit 3: seems like doing a rolling window works-ish -- with color artifacts (discoloration). will continue to test.

@a-r-r-o-w
Copy link
Member Author

Thanks for the kind words @rmasiso! This is indeed possible and I'm experimenting on adding support for arbitrary number of frames to both animatediff and this community pipeline. I have a non-functional notebook at the moment but I'm getting there slowly by reversing this comfy-ui code that does support longer generations.

sayakpaul added a commit that referenced this pull request Dec 12, 2023
…5839)

* add poc for benchmarking workflow.

* import

* fix argument

* fix: argument

* fix: path

* fix

* fix

* path

* output csv files.

* workflow cleanup

* append token

* add utility to push to hf dataset

* fix: kw arg

* better reporting

* fix: headers

* better formatting of the numbers.

* better type annotation

* fix: formatting

* moentarily disable check

* push results.

* remove disable check

* introduce base classes.

* img2img class

* add inpainting pipeline

* intoduce base benchmark class.

* add img2img and inpainting

* feat: utility to compare changes

* fix

* fix import

* add args

* basepath

* better exception handling

* better path handling

* fix

* fix

* remove

* ifx

* fix

* add: support for controlnet.

* image_url -> url

* move images to huggingface hub

* correct urls.

* root_ckpt

* flush before benchmarking

* don't install accelerate from source

* add runner

* simplify Diffusers Benchmarking step

* change runner

* fix: subprocess call.

* filter percentage values

* fix controlnet benchmark

* add t2i adapters.

* fix filter columns

* fix t2i adapter benchmark

* fix init.

* fix

* remove safetensors flag

* fix args print

* fix

* feat: run_command

* add adapter resolution mapping

* benchmark t2i adapter fix.

* fix adapter input

* fix

* convert to L.

* add flush() add appropriate places

* better filtering

* okay

* get env for torch

* convert to float

* fix

* filter out nans.

* better coment

* sdxl

* sdxl for other benchmarks.

* fix: condition

* fix: condition for inpainting

* fix: mapping for resolution

* fix

* include kandinsky and wuerstchen

* fix: Wuerstchen

* Empty-Commit

* [Community] AnimateDiff + Controlnet Pipeline (#5928)

* begin work on animatediff + controlnet pipeline

* complete todos, uncomment multicontrolnet, input checks

Co-Authored-By: EdoardoBotta <[email protected]>

* update

Co-Authored-By: EdoardoBotta <[email protected]>

* add example

* update community README

* Update examples/community/README.md

---------

Co-authored-by: EdoardoBotta <[email protected]>
Co-authored-by: Patrick von Platen <[email protected]>

* EulerDiscreteScheduler add `rescale_betas_zero_snr` (#6024)

* EulerDiscreteScheduler add `rescale_betas_zero_snr`

* Revert "[Community] AnimateDiff + Controlnet Pipeline (#5928)"

This reverts commit 821726d.

* Revert "EulerDiscreteScheduler add `rescale_betas_zero_snr` (#6024)"

This reverts commit 3dc2362.

* add SDXL turbo

* add lcm lora to the mix as well.

* fix

* increase steps to 2 when running turbo i2i

* debug

* debug

* debug

* fix for good

* fix and isolate better

* fuse lora so that torch compile works with peft

* fix: LCMLoRA

* better identification for LCM

* change to cron job

---------

Co-authored-by: Patrick von Platen <[email protected]>
Co-authored-by: Dhruv Nair <[email protected]>
Co-authored-by: Aryan V S <[email protected]>
Co-authored-by: EdoardoBotta <[email protected]>
Co-authored-by: Beinsezii <[email protected]>
@madriss
Copy link

madriss commented Dec 12, 2023

Amazing work @a-r-r-o-w ! I was wondering if the current animatediff pipeline would work with SDXL and its related controlnets and motion module ?

Best

@a-r-r-o-w
Copy link
Member Author

a-r-r-o-w commented Dec 12, 2023

Amazing work @a-r-r-o-w ! I was wondering if the current animatediff pipeline would work with SDXL and its related controlnets and motion module ?

Best

Thanks! It is indeed possible. See here: https://github.com/guoyww/AnimateDiff/blob/sdxl/. I'll try to make a notebook and share it here soon.

@yiyixuxu @patrickvonplaten @sayakpaul AnimateDiff with SDXL seems like a great addition as the quality looks really cool. Would you be open to PRs adding support for it? I'm not sure if the current diffusers implementation will work since I see a few implementation differences in the AnimateDiff repo and here. Will test more and get back.

@a-r-r-o-w
Copy link
Member Author

Just a quick notebook update before I go sleep: Colab. I'm yet to replicate the results of the sdxl branch as demonstrated in the repo. This notebook is able to get the inference process up and running.

Current Results
1.mp4
2.mp4
f.mp4

Also, it probably makes sense to create a new issue asking for support of these features at this point :)

@rmasiso
Copy link

rmasiso commented Dec 13, 2023

Thanks for the kind words @rmasiso! This is indeed possible and I'm experimenting on adding support for arbitrary number of frames to both animatediff and this community pipeline. I have a non-functional notebook at the moment but I'm getting there slowly by reversing this comfy-ui code that does support longer generations.

This is exciting! Is the hack they did in comfy-ui, the idea that one converts the entire video into latents first, and then sends them through animate-diff for the 16 frame interpolation in a sort of rolling context window? Similar to my hack, but it would end up more consistent, because it's in latent space from the get-go?

@a-r-r-o-w a-r-r-o-w mentioned this pull request Dec 16, 2023
6 tasks
donhardman pushed a commit to donhardman/diffusers that referenced this pull request Dec 18, 2023
* begin work on animatediff + controlnet pipeline

* complete todos, uncomment multicontrolnet, input checks

Co-Authored-By: EdoardoBotta <[email protected]>

* update

Co-Authored-By: EdoardoBotta <[email protected]>

* add example

* update community README

* Update examples/community/README.md

---------

Co-authored-by: EdoardoBotta <[email protected]>
Co-authored-by: Patrick von Platen <[email protected]>
donhardman pushed a commit to donhardman/diffusers that referenced this pull request Dec 18, 2023
…uggingface#5839)

* add poc for benchmarking workflow.

* import

* fix argument

* fix: argument

* fix: path

* fix

* fix

* path

* output csv files.

* workflow cleanup

* append token

* add utility to push to hf dataset

* fix: kw arg

* better reporting

* fix: headers

* better formatting of the numbers.

* better type annotation

* fix: formatting

* moentarily disable check

* push results.

* remove disable check

* introduce base classes.

* img2img class

* add inpainting pipeline

* intoduce base benchmark class.

* add img2img and inpainting

* feat: utility to compare changes

* fix

* fix import

* add args

* basepath

* better exception handling

* better path handling

* fix

* fix

* remove

* ifx

* fix

* add: support for controlnet.

* image_url -> url

* move images to huggingface hub

* correct urls.

* root_ckpt

* flush before benchmarking

* don't install accelerate from source

* add runner

* simplify Diffusers Benchmarking step

* change runner

* fix: subprocess call.

* filter percentage values

* fix controlnet benchmark

* add t2i adapters.

* fix filter columns

* fix t2i adapter benchmark

* fix init.

* fix

* remove safetensors flag

* fix args print

* fix

* feat: run_command

* add adapter resolution mapping

* benchmark t2i adapter fix.

* fix adapter input

* fix

* convert to L.

* add flush() add appropriate places

* better filtering

* okay

* get env for torch

* convert to float

* fix

* filter out nans.

* better coment

* sdxl

* sdxl for other benchmarks.

* fix: condition

* fix: condition for inpainting

* fix: mapping for resolution

* fix

* include kandinsky and wuerstchen

* fix: Wuerstchen

* Empty-Commit

* [Community] AnimateDiff + Controlnet Pipeline (huggingface#5928)

* begin work on animatediff + controlnet pipeline

* complete todos, uncomment multicontrolnet, input checks

Co-Authored-By: EdoardoBotta <[email protected]>

* update

Co-Authored-By: EdoardoBotta <[email protected]>

* add example

* update community README

* Update examples/community/README.md

---------

Co-authored-by: EdoardoBotta <[email protected]>
Co-authored-by: Patrick von Platen <[email protected]>

* EulerDiscreteScheduler add `rescale_betas_zero_snr` (huggingface#6024)

* EulerDiscreteScheduler add `rescale_betas_zero_snr`

* Revert "[Community] AnimateDiff + Controlnet Pipeline (huggingface#5928)"

This reverts commit 821726d.

* Revert "EulerDiscreteScheduler add `rescale_betas_zero_snr` (huggingface#6024)"

This reverts commit 3dc2362.

* add SDXL turbo

* add lcm lora to the mix as well.

* fix

* increase steps to 2 when running turbo i2i

* debug

* debug

* debug

* fix for good

* fix and isolate better

* fuse lora so that torch compile works with peft

* fix: LCMLoRA

* better identification for LCM

* change to cron job

---------

Co-authored-by: Patrick von Platen <[email protected]>
Co-authored-by: Dhruv Nair <[email protected]>
Co-authored-by: Aryan V S <[email protected]>
Co-authored-by: EdoardoBotta <[email protected]>
Co-authored-by: Beinsezii <[email protected]>
@fkjkey
Copy link

fkjkey commented Jan 12, 2024

Thank you for the pipe.Can't this pipe use multiple ControlNets like other pipes?

@a-r-r-o-w
Copy link
Member Author

Thank you for the pipe.Can't this pipe use multiple ControlNets like other pipes?

It does support multiple controlnets. Does it error out when you use it with multiple? If so, I'll look into fixing it quickly.

@fkjkey
Copy link

fkjkey commented Jan 12, 2024

when I do this:

    self.tile = ControlNetModel.from_pretrained(
        "/home/img2video/models/control/control_v11f1e_sd15_tile", torch_dtype=torch.float16
    )
    self.pose = ControlNetModel.from_pretrained(
        "/home/lora_test/model/controlnet_pose", torch_dtype=torch.float16
    )
    self.pose_processor = OpenposeDetector.from_pretrained('/home/lora_test/model/pose_dete').to('cuda')

    self.adapter = MotionAdapter.from_pretrained("/home/AnimateDiff-main/models/Motion_Module",
                                            torch_dtype=torch.float16)
    self.pipe = AnimateDiffControlNetPipeline.from_pretrained(
        "/home/lora_test/model/AWPainting_v1.2",
        motion_adapter=self.adapter,
        controlnet=[self.pose, self.tile],
        torch_dtype=torch.float16)

I get :

Traceback (most recent call last):
File "/home/re_sd/dance_test.py", line 163, in
M = Dance()
File "/home/re_sd/dance_test.py", line 51, in init
self.pipe = AnimateDiffControlNetPipeline.from_pretrained(
File "/root/anaconda3/envs/stable_fast/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
return fn(*args, **kwargs)
File "/root/anaconda3/envs/stable_fast/lib/python3.10/site-packages/diffusers/pipelines/pipeline_utils.py", line 1363, in from_pretrained
model = pipeline_class(**init_kwargs)
File "/home/re_sd/pipeline_animatediff_controlnet.py", line 170, in init
self.register_modules(
File "/root/anaconda3/envs/stable_fast/lib/python3.10/site-packages/diffusers/pipelines/pipeline_utils.py", line 571, in register_modules
library = not_compiled_module.module.split(".")[0]
AttributeError: 'list' object has no attribute 'module'. Did you mean: 'mul'?

@a-r-r-o-w
Copy link
Member Author

a-r-r-o-w commented Jan 12, 2024

Okay, I see the issue. Not sure why/how I removed the line to handle multicontrolnet. In the __init__ function, the following line seems to be missing:

        if isinstance(controlnet, (list, tuple)):
            controlnet = MultiControlNetModel(controlnet)

There might be other things I've missed. I'll test and open a PR fixing it in a bit. Thanks for reporting this!

@a-r-r-o-w a-r-r-o-w mentioned this pull request Jan 26, 2024
6 tasks
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* begin work on animatediff + controlnet pipeline

* complete todos, uncomment multicontrolnet, input checks

Co-Authored-By: EdoardoBotta <[email protected]>

* update

Co-Authored-By: EdoardoBotta <[email protected]>

* add example

* update community README

* Update examples/community/README.md

---------

Co-authored-by: EdoardoBotta <[email protected]>
Co-authored-by: Patrick von Platen <[email protected]>
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
…uggingface#5839)

* add poc for benchmarking workflow.

* import

* fix argument

* fix: argument

* fix: path

* fix

* fix

* path

* output csv files.

* workflow cleanup

* append token

* add utility to push to hf dataset

* fix: kw arg

* better reporting

* fix: headers

* better formatting of the numbers.

* better type annotation

* fix: formatting

* moentarily disable check

* push results.

* remove disable check

* introduce base classes.

* img2img class

* add inpainting pipeline

* intoduce base benchmark class.

* add img2img and inpainting

* feat: utility to compare changes

* fix

* fix import

* add args

* basepath

* better exception handling

* better path handling

* fix

* fix

* remove

* ifx

* fix

* add: support for controlnet.

* image_url -> url

* move images to huggingface hub

* correct urls.

* root_ckpt

* flush before benchmarking

* don't install accelerate from source

* add runner

* simplify Diffusers Benchmarking step

* change runner

* fix: subprocess call.

* filter percentage values

* fix controlnet benchmark

* add t2i adapters.

* fix filter columns

* fix t2i adapter benchmark

* fix init.

* fix

* remove safetensors flag

* fix args print

* fix

* feat: run_command

* add adapter resolution mapping

* benchmark t2i adapter fix.

* fix adapter input

* fix

* convert to L.

* add flush() add appropriate places

* better filtering

* okay

* get env for torch

* convert to float

* fix

* filter out nans.

* better coment

* sdxl

* sdxl for other benchmarks.

* fix: condition

* fix: condition for inpainting

* fix: mapping for resolution

* fix

* include kandinsky and wuerstchen

* fix: Wuerstchen

* Empty-Commit

* [Community] AnimateDiff + Controlnet Pipeline (huggingface#5928)

* begin work on animatediff + controlnet pipeline

* complete todos, uncomment multicontrolnet, input checks

Co-Authored-By: EdoardoBotta <[email protected]>

* update

Co-Authored-By: EdoardoBotta <[email protected]>

* add example

* update community README

* Update examples/community/README.md

---------

Co-authored-by: EdoardoBotta <[email protected]>
Co-authored-by: Patrick von Platen <[email protected]>

* EulerDiscreteScheduler add `rescale_betas_zero_snr` (huggingface#6024)

* EulerDiscreteScheduler add `rescale_betas_zero_snr`

* Revert "[Community] AnimateDiff + Controlnet Pipeline (huggingface#5928)"

This reverts commit 821726d.

* Revert "EulerDiscreteScheduler add `rescale_betas_zero_snr` (huggingface#6024)"

This reverts commit 3dc2362.

* add SDXL turbo

* add lcm lora to the mix as well.

* fix

* increase steps to 2 when running turbo i2i

* debug

* debug

* debug

* fix for good

* fix and isolate better

* fuse lora so that torch compile works with peft

* fix: LCMLoRA

* better identification for LCM

* change to cron job

---------

Co-authored-by: Patrick von Platen <[email protected]>
Co-authored-by: Dhruv Nair <[email protected]>
Co-authored-by: Aryan V S <[email protected]>
Co-authored-by: EdoardoBotta <[email protected]>
Co-authored-by: Beinsezii <[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.

10 participants