huggingface / diffusers

🤗 Diffusers: State-of-the-art diffusion models for image and audio generation in PyTorch and FLAX.
https://huggingface.co/docs/diffusers
Apache License 2.0
25.03k stars 5.17k forks source link

RuntimeError: torch.cat(): expected a non-empty list of Tensors #8826

Open byrkbrk opened 1 month ago

byrkbrk commented 1 month ago

Describe the bug

Problem: When the "officially provided" example (see https://github.com/huggingface/diffusers/blob/a785992c1d6fcb1ff66f8a0d68d09a0a81b909e8/src/diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion.py#L34) is executed, the error occurs.

Expected behaviour: The example should work without any error.

Reproduction

The Code:

import torch
from diffusers import LEditsPPPipelineStableDiffusion
from diffusers.utils import load_image

if __name__ == "__main__":
    pipe = LEditsPPPipelineStableDiffusion.from_pretrained(
        "runwayml/stable-diffusion-v1-5",
        torch_dtype=torch.float16)
    pipe = pipe.to("mps")
    img_url = "https://www.aiml.informatik.tu-darmstadt.de/people/mbrack/cherry_blossom.png"
    image = load_image(img_url).convert("RGB")

    _ = pipe.invert(image=image, num_inversion_steps=50, skip=0.1)
    edited_image = pipe(
        editing_prompt=["cherry blossom"], 
        edit_guidance_scale=10.0, 
        edit_threshold=0.75).images[0]

The Error:

Traceback (most recent call last):
  File "/Users/burakbayrak/folder-to-del/leditsplusplus_example.py", line 16, in <module>
    edited_image = pipe(
                   ^^^^^
  File "/Users/burakbayrak/anaconda3/envs/ledits-plus-plus/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/burakbayrak/anaconda3/envs/ledits-plus-plus/lib/python3.11/site-packages/diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion.py", line 1010, in __call__
    out = self.attention_store.aggregate_attention(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/burakbayrak/anaconda3/envs/ledits-plus-plus/lib/python3.11/site-packages/diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion.py", line 128, in aggregate_attention
    out = torch.stack([torch.cat(x, dim=0) for x in out])
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/burakbayrak/anaconda3/envs/ledits-plus-plus/lib/python3.11/site-packages/diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion.py", line 128, in <listcomp>
    out = torch.stack([torch.cat(x, dim=0) for x in out])
                       ^^^^^^^^^^^^^^^^^^^
RuntimeError: torch.cat(): expected a non-empty list of Tensors

Logs

No response

System Info

Who can help?

@yiyixuxu

a-r-r-o-w commented 1 month ago

Probably relevant: https://github.com/huggingface/diffusers/pull/6074#issuecomment-1997507552

cc @manuelbrack @kathath