stable-diffusion icon indicating copy to clipboard operation
stable-diffusion copied to clipboard

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

Open zesameri opened this issue 3 years ago • 10 comments

(my code) samples = sampler.decode(z_enc, c, t_enc, unconditional_guidance_scale=opt.scale) stack trace w/o pytorch forward and grad calls File "/home/model-server/stable-diffusion/ldm/models/diffusion/ddim.py", line 238, in decode x_dec, _ = self.p_sample_ddim(x_dec, cond, ts, index=index, use_original_steps=use_original_steps) File "/home/model-server/stable-diffusion/ldm/models/diffusion/ddim.py", line 177, in p_sample_ddim e_t_uncond, e_t = self.model.apply_model(x_in, t_in, c_in).chunk(2) File "/home/model-server/stable-diffusion/ldm/models/diffusion/ddpm.py", line 987, in apply_model x_recon = self.model(x_noisy, t, **cond) File "/home/model-server/stable-diffusion/ldm/models/diffusion/ddpm.py", line 1410, in forward out = self.diffusion_model(x, t, context=cc) File "/home/model-server/stable-diffusion/ldm/modules/diffusionmodules/openaimodel.py", line 736, in forward h = th.cat([h, hs.pop()], dim=1) RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 16 but got size 15 for tensor number 1 in the list.

zesameri avatar Sep 19 '22 18:09 zesameri

Make sure the size if the width/height is a 64 step (512, 576, 640...)

smoran avatar Sep 19 '22 22:09 smoran

Why should the size / aspect ratio of the image be compromised...?

ThisNekoGuy avatar Dec 07 '22 11:12 ThisNekoGuy

not sure if still relevant but I was also getting a similar error: Sizes of tensors must match except in dimension 1. Expected size 12 but got size 2 for tensor number 1 in the list

and it was due to prompt being passed to my pipe call() being an array of strings instead of a single string. Eg:

images = pipe(
    prompt=prompt, # needs to be a single string
    num_images_per_prompt=args.number,  # create multiple images with this arg
    image=image_person,
    mask_image=image_mask,
    guidance_scale=7.5,
    generator=generator,
).images

acharb avatar Dec 17 '22 12:12 acharb

Make sure the size if the width/height is a 64 step (512, 576, 640...)

you are really wise man

sunyuhan19981208 avatar Mar 19 '24 11:03 sunyuhan19981208

Make sure the size if the width/height is a 64 step (512, 576, 640...)

how do i do that?

slashyyy46543 avatar Mar 26 '24 17:03 slashyyy46543

Make sure the size if the width/height is a 64 step (512, 576, 640...)

how do i do that?

In the pipe, pass width=XXX and height=YYY

smoran avatar Apr 01 '24 11:04 smoran

Make sure the size if the width/height is a 64 step (512, 576, 640...)

your comment should be the actual error message lol

lucas-zimerman avatar May 25 '24 18:05 lucas-zimerman

Does it have to be 64? I tried 32 and it worked. What's the reason for this number?

sivannavis avatar Jun 16 '24 18:06 sivannavis

Multiplications of 8 usually work, but i would stick to 64/128 etc. it is also advised to keep the total size close to the original resolution, so don't use 1024 by 512 on a 512 by 512 model for example as it might introduce artifacts.

On Sun, Jun 16, 2024, 9:28 PM Sivan Ding @.***> wrote:

Does it have to be 64? I tried 32 and it worked. What's the reason for this number?

— Reply to this email directly, view it on GitHub https://github.com/CompVis/stable-diffusion/issues/301#issuecomment-2171800223, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABITHJHLVFSLJHD2OTV4GYDZHXKLBAVCNFSM6AAAAAAQQK46VGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZRHAYDAMRSGM . You are receiving this because you commented.Message ID: @.***>

smoran avatar Jun 16 '24 19:06 smoran

In my case the issue was caused by another reason. I was using SD 1.5 as for model but SDXL as for controlnet model. So I change my base model to SDXL as well and all worked like a charm.

ProgrammingLife avatar Oct 22 '24 15:10 ProgrammingLife