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

[Bug]: txt2img produces RuntimeError about mismatched tensor sizes

Open aburgd opened this issue 2 years ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits

What happened?

After clicking Generate in the web UI, the script throws the below RuntimError:

Error completing request
Arguments: ('painting of a soulless man in the forest, impressionist', '', 'None', 'None', 20, 0, False, False, 1, 1, 7, -1.0, -1.0, 0, 0, 0, False, 786, 512, False, False, 0.7, 0, False, False, None, '', 1, '', 0, '', True, False) {}
Traceback (most recent call last):
  File "C:\Users\aebur\source\stable-diffusion-webui\modules\ui.py", line 182, in f
    res = list(func(*args, **kwargs))
  File "C:\Users\aebur\source\stable-diffusion-webui\webui.py", line 69, in f
    res = func(*args, **kwargs)
  File "C:\Users\aebur\source\stable-diffusion-webui\modules\txt2img.py", line 43, in txt2img
    processed = process_images(p)
  File "C:\Users\aebur\source\stable-diffusion-webui\modules\processing.py", line 404, in process_images
    samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength)
  File "C:\Users\aebur\source\stable-diffusion-webui\modules\processing.py", line 532, in sample
    samples = self.sampler.sample(self, x, conditioning, unconditional_conditioning)
  File "C:\Users\aebur\source\stable-diffusion-webui\modules\sd_samplers.py", line 409, in sample
    samples = self.func(self.model_wrap_cfg, x, extra_args={'cond': conditioning, 'uncond': unconditional_conditioning, 'cond_scale': p.cfg_scale}, disable=False, callback=self.callback_state, **extra_params_kwargs)
  File "C:\Users\aebur\source\stable-diffusion-webui\venv\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "C:\Users\aebur\source\stable-diffusion-webui\repositories\k-diffusion\k_diffusion\sampling.py", line 80, in sample_euler_ancestral
    denoised = model(x, sigmas[i] * s_in, **extra_args)
  File "C:\Users\aebur\source\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\Users\aebur\source\stable-diffusion-webui\modules\sd_samplers.py", line 239, in forward
    x_out = self.inner_model(x_in, sigma_in, cond=cond_in)
  File "C:\Users\aebur\source\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\Users\aebur\source\stable-diffusion-webui\repositories\k-diffusion\k_diffusion\external.py", line 112, in forward
    eps = self.get_eps(input * c_in, self.sigma_to_t(sigma), **kwargs)
  File "C:\Users\aebur\source\stable-diffusion-webui\repositories\k-diffusion\k_diffusion\external.py", line 138, in get_eps
    return self.inner_model.apply_model(*args, **kwargs)
  File "C:\Users\aebur\source\stable-diffusion-webui\repositories\stable-diffusion\ldm\models\diffusion\ddpm.py", line 987, in apply_model
    x_recon = self.model(x_noisy, t, **cond)
  File "C:\Users\aebur\source\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\Users\aebur\source\stable-diffusion-webui\repositories\stable-diffusion\ldm\models\diffusion\ddpm.py", line 1410, in forward
    out = self.diffusion_model(x, t, context=cc)
  File "C:\Users\aebur\source\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\Users\aebur\source\stable-diffusion-webui\repositories\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 26 but got size 25 for tensor number 1 in the list.

Steps to reproduce the problem

  1. Run the webui-user.bat file
  2. Wait for the web UI to be ready
  3. Enter a prompt (without changing any values from the default)
  4. Click Generate
  5. Receive RuntimeError

What should have happened?

One image generated from txt2img prompt, no errors.

Commit where the problem happens

6be32b31d181e42c639dad3451229aa7b9cfd1cf

What platforms do you use to access UI ?

Windows

What browsers do you use to access the UI ?

Google Chrome

Command Line Arguments

No response

Additional information, context and logs

Two days ago this was working fine, I believe using the same commit. Using sd-v1-4.ckpt.

aburgd avatar Oct 26 '22 01:10 aburgd

I know you'll run into this on some resolutions. Set it back to 512x512 and see if the issue persists then adjust from there. When doing 16:9's I do 1024x576, then upscale once I'm happy with the results.

Could be cool to have some sort of prompt about unsupported resolution.

SirDMZ avatar Oct 26 '22 02:10 SirDMZ

Strange - I wonder what's changed that cause this to happen. I was generating 512x786 images aplenty two-three days ago with no issues.

aburgd avatar Oct 26 '22 02:10 aburgd

Until I did a Git Pull just a few minutes ago I had never had this problem before (initially setup this software only 2 days ago). Could be complete chance, but I logged in to say thank you for suggesting changing the resolutions and trying again.

Hygaard avatar Oct 26 '22 04:10 Hygaard

512x786 images throw the tensor mismatch error, but 512x768 works - I think it was a matter of not using increments of 64. Closing this issue.

aburgd avatar Oct 30 '22 16:10 aburgd