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

RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 4 but got size 1 for tensor number 1 in the list. #9

Closed
alexisrolland opened this issue Mar 15, 2023 · 2 comments

Comments

@alexisrolland
Copy link

I am trying to use compel with batches of long prompts / negative prompts. Here is the code:

import torch
from diffusers import StableDiffusionPipeline
from compel import Compel

pipeline = StableDiffusionPipeline.from_pretrained("/model/path")
compel = Compel(tokenizer=pipeline.tokenizer, text_encoder=pipeline.text_encoder, truncate_long_prompts=False)

prompts = [
    "best quality, masterpiece, highres, 1girl,china dress,Beautiful face,upon_body, tyndall effect,photorealistic, dark studio, rim lighting, two tone lighting,(high detailed skin:1.2), 8k uhd, dslr, soft lighting, high quality, volumetric lighting, candid, Photograph, high resolution, 4k, 8k, Bokeh",
    "best quality, masterpiece, highres, 1girl,china dress,Beautiful face,upon_body, tyndall effect,photorealistic, dark studio, rim lighting, two tone lighting,(high detailed skin:1.2), 8k uhd, dslr, soft lighting, high quality, volumetric lighting, candid, Photograph, high resolution, 4k, 8k, Bokeh",
    "best quality, masterpiece, highres, 1girl,china dress,Beautiful face,upon_body, tyndall effect,photorealistic, dark studio, rim lighting, two tone lighting,(high detailed skin:1.2), 8k uhd, dslr, soft lighting, high quality, volumetric lighting, candid, Photograph, high resolution, 4k, 8k, Bokeh",
    "best quality, masterpiece, highres, 1girl,china dress,Beautiful face,upon_body, tyndall effect,photorealistic, dark studio, rim lighting, two tone lighting,(high detailed skin:1.2), 8k uhd, dslr, soft lighting, high quality, volumetric lighting, candid, Photograph, high resolution, 4k, 8k, Bokeh"
]
negative_prompts = ["blur", "blur", "blur", "blur"]

prompt_embeds = compel(prompts)
negative_prompt_embeds = compel(negative_prompts)

[prompt_embeds, negative_prompt_embeds] = compel.pad_conditioning_tensors_to_same_length([prompt_embeds, negative_prompt_embeds])

The error returned by this last line is:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/compel/compel.py", line 111, in pad_conditioning_tensors_to_same_length
    c = torch.cat([c, empty_z], dim=1)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 4 but got size 1 for tensor number 1 in the list.
@damian0815
Copy link
Owner

ahh. seems like pad_conditioning_tensors_to_same_length doesn't support batching input like that. i'll take a look at fixing that for the next release. in the meantime you could manually unpack the 4x77x768 tensors returned by compel() to lists of 4 1x77x768 tensors ..?

@damian0815
Copy link
Owner

should be fixed with compel 1.0.2

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

No branches or pull requests

2 participants