stable-diffusion-webui
stable-diffusion-webui copied to clipboard
Crash in DDIM for img2img with 110 steps – "IndexError: index 1000 is out of bounds for dimension 0 with size 1000"
While dealing with https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/1451#issuecomment-1272247467, I encountered another bug. Updated to lastest commit, but it still crashes.
To Reproduce
- img2img, load any image with any prompt (white 512*512 with prompt "any" is fine to trigger)
- set DDIM sampler, exactly 110 steps.
- make sure setting "With img2img, do exactly the amount of steps the slider specifies (normally you'd do less with less denoising)." is unchecked.
- Generate. It will crash, despite for 90 or 100 or 150 steps it doesn't. Only for 110?
Full console log
venv "C:\SD\stable-diffusion-webui\venv\Scripts\Python.exe"
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Commit hash: 616b7218f7c469d25c138634472017a7e18e742e
Installing requirements for Web UI
Launching Web UI with arguments:
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
making attention of type 'vanilla' with 512 in_channels
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
making attention of type 'vanilla' with 512 in_channels
Loading weights [a97cb925] from C:\SD\stable-diffusion-webui\models\Stable-diffusion\half-wd-v1-2.ckpt
Global Step: 487750
Model loaded.
Loaded a total of 0 textual inversion embeddings.
Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
Error completing request
Arguments: (0, 'any', '', 'None', 'None', <PIL.Image.Image image mode=RGB size=512x512 at 0x1D82D731D20>, None, None, None, 0, 110, 9, 4, 1, False, False, 1, 1, 7, 0.75, -1.0, -1.0, 0, 0, 0, False, 512, 512, 0, False, 32, 0, '', '', 0, '', '', 1, 50, 0, False, 4, 1, '<p style="margin-bottom:0.75em">Recommended settings: Sampling Steps: 80-100, Sampler: Euler a, Denoising strength: 0.8</p>', 128, 8, ['left', 'right', 'up', 'down'], 1, 0.05, 128, 4, 0, ['left', 'right', 'up', 'down'], False, False, None, '', '<p style="margin-bottom:0.75em">Will upscale the image to twice the dimensions; use width and height sliders to set tile size</p>', 64, 0, 1, '', 4, '', True, False, 1, '', 4, '', True, False) {}
Traceback (most recent call last):
File "C:\SD\stable-diffusion-webui\modules\sd_samplers.py", line 176, in sample_img2img
self.sampler.make_schedule(ddim_num_steps=steps, ddim_eta=self.eta, ddim_discretize=p.ddim_discretize, verbose=False)
File "C:\SD\stable-diffusion-webui\repositories\stable-diffusion\ldm\models\diffusion\ddim.py", line 44, in make_schedule
ddim_sigmas, ddim_alphas, ddim_alphas_prev = make_ddim_sampling_parameters(alphacums=alphas_cumprod.cpu(),
File "C:\SD\stable-diffusion-webui\repositories\stable-diffusion\ldm\modules\diffusionmodules\util.py", line 65, in make_ddim_sampling_parameters
alphas = alphacums[ddim_timesteps]
IndexError: index 1000 is out of bounds for dimension 0 with size 1000
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\SD\stable-diffusion-webui\modules\ui.py", line 158, in f
res = list(func(*args, **kwargs))
File "C:\SD\stable-diffusion-webui\webui.py", line 65, in f
res = func(*args, **kwargs)
File "C:\SD\stable-diffusion-webui\modules\img2img.py", line 124, in img2img
processed = process_images(p)
File "C:\SD\stable-diffusion-webui\modules\processing.py", line 376, in process_images
samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength)
File "C:\SD\stable-diffusion-webui\modules\processing.py", line 680, in sample
samples = self.sampler.sample_img2img(self, self.init_latent, x, conditioning, unconditional_conditioning)
File "C:\SD\stable-diffusion-webui\modules\sd_samplers.py", line 178, in sample_img2img
self.sampler.make_schedule(ddim_num_steps=steps+1, ddim_eta=self.eta, ddim_discretize=p.ddim_discretize, verbose=False)
File "C:\SD\stable-diffusion-webui\repositories\stable-diffusion\ldm\models\diffusion\ddim.py", line 44, in make_schedule
ddim_sigmas, ddim_alphas, ddim_alphas_prev = make_ddim_sampling_parameters(alphacums=alphas_cumprod.cpu(),
File "C:\SD\stable-diffusion-webui\repositories\stable-diffusion\ldm\modules\diffusionmodules\util.py", line 65, in make_ddim_sampling_parameters
alphas = alphacums[ddim_timesteps]
IndexError: index 1000 is out of bounds for dimension 0 with size 1000
That will be an error related to your denoising strength. It's probably too high with that number of steps. Although some error handling of such cases would probably avoid this and not let it run at all and return an error to the UI asking the user to change the parameters.
That will be an error related to your denoising strength.
No, it does not. For me, DDIM crashes on any number of steps in range 101 to 110, regardless of denoising strength.
It's probably too high with that number of steps.
It generates fine (at least without errors or crashes) for 100 steps or for 111 steps for any denoising level, or for any larger step count (I tried multiple times picking arbitrary values and it never failed).
My guess is that for some reason it cannot calculate the proper number of steps relative to denoising strength, when the required step count is 100<N<=110.
Perhaps related: I've also managed to get an index out of bounds error in sample_img2img but with denoising strength 0 + highres fix (without scale latent) on DPM2 a Karras. It gives a negative index out of bound equal to the number of steps. E.g. on 40 steps it is trying index -40, which is out of bounds.
Related: https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/1321, probably the exact same reason.
#2696
Fixed