continue-revolution / sd-webui-animatediff

AnimateDiff for AUTOMATIC1111 Stable Diffusion WebUI
Other
3.11k stars 258 forks source link

[Bug]: Sparse Control does not work #522

Closed NergiZed closed 5 months ago

NergiZed commented 5 months ago

Is there an existing issue for this?

Have you read FAQ on README?

What happened?

Trying to use SpareCtrl, but it seems to just fail and generates the indicated number of frames with animateDiff without the influence of SparseCtrl.

I read the documents as best as I could, read issues relating to SparseCtrl (there are only 4), and gathered what I believed to be the right files. AnimateDiff with Multi-ControelNets works fine, so it's just the SparseCtrl part. Here's the basics:

webui: Automatic1111 version 1.9.3

extensions: sd-webui-animatediff sd-webui-controlnet

files: The motion module and sparsectrl files I got from here: https://huggingface.co/conrevo/AnimateDiff-A1111/tree/main/control sparsectrl: file: mm_sd15_v3_sparsectrl_rgb.safetensors location: C:\AI\SD\stable-diffusion-webui-xl\models\ControlNet size: 947 MB (993,974,272 bytes) motion module: file: mm_sd15_v3 location: C:\AI\SD\stable-diffusion-webui-xl\extensions\sd-webui-animatediff\model size: 797 MB (836,618,008 bytes)

Parameters prompt and neg: image

generation settings: image

AnimateDiff settings: image

ControlNet settings: image

Spherically, for the input directory: D:_work\slipperygem\hentai\mouse in the house\scenes\tests\color diffuse test\SparseControlTest keyframe:0,6,12,18,24

The error I get has to do with the keyframe part of that. Here is the error image

That's pointing to this batch.py file here: C:\AI\SD\stable-diffusion-webui-xl\extensions\sd-webui-controlnet\scripts\animate_diff Specifically this chunk: for ad_cn_batch_parameter in batch_parameters[1:]: if ad_cn_batch_parameter.startswith("mask:"): unit.batch_mask_dir = ad_cn_batch_parameter[len("mask:") :].strip() logger.info(f"\tbatch control mask: {unit.batch_mask_dir}") elif ad_cn_batch_parameter.startswith("keyframe:"): unit.batch_keyframe_idx = ad_cn_batch_parameter[len("keyframe:") :].strip() unit.batch_keyframe_idx = [ int(b_i.strip()) for b_i in unit.batch_keyframe_idx.split(",") ] logger.info(f"\tbatch control keyframe index: {unit.batch_keyframe_idx}")

Its looking for the text 'keyframe:' in the 'batch_parameters', so I'm not sure what I'm doing wrong. I'm copying the format from the documentation: image

I'm using these 5 keyframes for the test: image

And the output is, unsurprisingly, not influenced by the keyframes at all. Clearly it just skipped it and gave a pure prompt AnimateDiff output: 00008-2789057374

The goal of the test was to use SpareCtrl to recreate the original gen as much as possible, which is a multi-ControlNet guided generation with animDiff. 00000-2789057374

I'm not sure what other information I can provide. Seems like it could be minor typo type thing, but I just don't know what's wrong. Know that I can not code well, and because of that I almost never write issues; I don't think I can do a good job of it. I would much prefer to either figure it out or wait it out. However, SpareCtrl is a feature that I desperately want to learn how to use, and there's just not a whole lot of information out there about it. Please help.

Anyhow, thanks for your time, apologies if it was some braindead issue on my part.

Great extension by the way. just got back into it, and the potential is incredible.

Steps to reproduce the problem

  1. Set things up the way I described above
  2. Hit generate

What should have happened?

It should interpolate the frames provided according to the assigned keyframes over the indicated frame length. I think.

Commit where the problem happens

webui: https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/1c0a0c4c26f78c32095ebc7f8af82f5c04fca8c0 sd-webui-animatediff: https://github.com/continue-revolution/sd-webui-animatediff/commit/67e6b96aacd5fb5d690f4f245bb34c26b8de64e9 sd-webui-controlnet: https://github.com/Mikubill/sd-webui-controlnet/commit/e338a861dc4b4087db001c7fee8e1b0f916e0c3b

What browsers do you use to access the UI ?

No response

Command Line Arguments

--precision full --no-half

Console logs

2024-05-20 10:47:21,629 - AnimateDiff - INFO - AnimateDiff process start.                | 1/8 [00:09<01:09,  9.87s/it]
2024-05-20 10:47:21,637 - AnimateDiff - INFO - Injecting motion module mm_sd15_v3.safetensors into SD1.5 UNet input blocks.
2024-05-20 10:47:21,637 - AnimateDiff - INFO - Injecting motion module mm_sd15_v3.safetensors into SD1.5 UNet output blocks.
2024-05-20 10:47:21,637 - AnimateDiff - INFO - Setting DDIM alpha.
2024-05-20 10:47:21,640 - AnimateDiff - INFO - Injection finished.
2024-05-20 10:47:21,640 - AnimateDiff - INFO - AnimateDiff + ControlNet will generate 25 frames.
INFO:sd_dynamic_prompts.dynamic_prompting:Prompt matrix will create 25 images in a total of 1 batches.
2024-05-20 10:47:23,422 - ControlNet - INFO - unit_separate = False, style_align = False
2024-05-20 10:47:23,422 - ControlNet - INFO - Loading model from cache: mm_sd15_v3_sparsectrl_rgb [9f17d62f]
2024-05-20 10:47:23,423 - ControlNet - INFO - AnimateDiff + ControlNet none receive the following parameters:
2024-05-20 10:47:23,423 - ControlNet - INFO -   batch control images: D:\_work\slipperygem\hentai\mouse in the house\scenes\tests\color diffuse test\SparseControlTest
*** Error running process: C:\AI\SD\stable-diffusion-webui-xl\extensions\sd-webui-controlnet\scripts\controlnet.py
    Traceback (most recent call last):
      File "C:\AI\SD\stable-diffusion-webui-xl\modules\scripts.py", line 825, in process
        script.process(p, *script_args)
      File "C:\AI\SD\stable-diffusion-webui-xl\extensions\sd-webui-controlnet\scripts\controlnet.py", line 1215, in process
        self.controlnet_hack(p)
      File "C:\AI\SD\stable-diffusion-webui-xl\extensions\sd-webui-controlnet\scripts\controlnet.py", line 1200, in controlnet_hack
        self.controlnet_main_entry(p)
      File "C:\AI\SD\stable-diffusion-webui-xl\extensions\sd-webui-controlnet\scripts\controlnet.py", line 934, in controlnet_main_entry
        controls, hr_controls, additional_maps = get_control(
      File "C:\AI\SD\stable-diffusion-webui-xl\extensions\sd-webui-controlnet\scripts\controlnet.py", line 202, in get_control
        unit = add_animate_diff_batch_input(p, unit)
      File "C:\AI\SD\stable-diffusion-webui-xl\extensions\sd-webui-controlnet\scripts\animate_diff\batch.py", line 24, in add_animate_diff_batch_input
        unit.batch_keyframe_idx = ad_cn_batch_parameter[len("keyframe:") :].strip()
      File "pydantic\main.py", line 357, in pydantic.main.BaseModel.__setattr__
    ValueError: "ControlNetUnit" object has no field "batch_keyframe_idx"

---
  0%|                                                                                            | 0/8 [00:00<?, ?it/s]2024-05-20 10:47:23,525 - AnimateDiff - INFO - inner model forward hooked
100%|████████████████████████████████████████████████████████████████████████████████████| 8/8 [03:26<00:00, 25.87s/it]
100%|████████████████████████████████████████████████████████████████████████████████████| 8/8 [03:37<00:00, 27.23s/it]
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 8/8 [04:39<00:00, 34.96s/it]
2024-05-20 10:59:15,001 - AnimateDiff - INFO - Restoring DDIM alpha.
2024-05-20 10:59:15,001 - AnimateDiff - INFO - Removing motion module from SD1.5 UNet input blocks.
2024-05-20 10:59:15,002 - AnimateDiff - INFO - Removing motion module from SD1.5 UNet output blocks.
2024-05-20 10:59:15,002 - AnimateDiff - INFO - Removal finished.
2024-05-20 10:59:15,003 - AnimateDiff - INFO - Saving output formats: GIF, PNG, TXT
2024-05-20 10:59:19,637 - AnimateDiff - INFO - AnimateDiff process end.
Total progress: 9it [11:34, 77.11s/it]
Total progress: 9it [11:34, 88.57s/it]

Additional information

I dunno. I guess I'm using LCM sampler as well. That works fine though. I'm using Opera to access the UI My G-card is a 4090 I'm using Windows 10 I live on the northern hemisphere I breath a mainly nitrogen oxygen atmosphere

zappityzap commented 5 months ago

Thanks for the detailed report. If I'm reading the controlnet code correctly, there should be additional lines of log output right after "batch control images:" that say "batch control keyframe index:". So something is going wrong with the keyframe parameter. I'll see if I can reproduce this, but if you want to try some coding... I would add logger.info lines like this:

    logger.info(f"\tbatch control images: {batch_image_dir}")
    logger.info(f"\tbatch parameters: {batch_parameters}")
    for ad_cn_batch_parameter in batch_parameters[1:]:
        logger.info(f"\t\tad_cn_batch_parameter: {ad_cn_batch_parameter}")
        if ad_cn_batch_parameter.startswith("mask:"):
zappityzap commented 5 months ago

Ok, the stupid pills wore off. The property "batch_keyframe_idx" doesn't exist in class ControlNetUnit from sd-webui-controlnet. There's a section of AnimateDiff properties that it can be added to. I submitted https://github.com/Mikubill/sd-webui-controlnet/pull/2926 so updating extensions after that is merged should fix it.

zappityzap commented 5 months ago

The PR has been merged and I'm getting results that resemble the SparseCtrl official examples.

Using the mm_sd15_v3_adapter as a LoRA seems to keep the motion more coherent but reduced amount, and the output is more saturated.

Motion seems to depend mostly on the seed, but the prompt can drastically change the output. I haven't been able to get reliable specific motion through prompting, and the v2 motion LoRAs don't seem to do anything with v3.

Remember to change the closed loop mode to N (none) or the result may be hard to interpret as it attempts to make a closed loop.

NergiZed commented 5 months ago

The PR has been merged and I'm getting results that resemble the SparseCtrl official examples.

Using the mm_sd15_v3_adapter as a LoRA seems to keep the motion more coherent but reduced amount, and the output is more saturated.

Motion seems to depend mostly on the seed, but the prompt can drastically change the output. I haven't been able to get reliable specific motion through prompting, and the v2 motion LoRAs don't seem to do anything with v3.

Remember to change the closed loop mode to N (none) or the result may be hard to interpret as it attempts to make a closed loop.

Thanks very much mate. I see the new commit in ControlNet. I will give it a try as soon as I can. Cheers.

If my test succeeds, I should close this issue, correct?

zappityzap commented 5 months ago

You're welcome. Yes, closing this when the issue is resolved would be appropriate.

NergiZed commented 5 months ago

Well, Sparse Control seems to work now. More or less the same setup as above with Sparse Control active now no longer yields an error.

00002-2789057374

Cheers and thanks mate! Now I must tinker ~