0xbitches / sd-webui-lcm

Latent Consistency Model for AUTOMATIC1111 Stable Diffusion WebUI
MIT License
614 stars 43 forks source link

LCM img2img error | TypeError: slice indices must be integers or None or have an __index__ method #27

Open PladsElsker opened 11 months ago

PladsElsker commented 11 months ago

I re-installed diffusers twice, I keep running into this error (LCM txt2img works fine though, only img2img is broken):

Traceback (most recent call last):
  File "C:\Users\Plads\Documents\GitHub\stable diffusion\stable-diffusion-avidhjeren\venv\lib\site-packages\gradio\routes.py", line 488, in run_predict
    output = await app.get_blocks().process_api(
  File "C:\Users\Plads\Documents\GitHub\stable diffusion\stable-diffusion-avidhjeren\venv\lib\site-packages\gradio\blocks.py", line 1431, in process_api
    result = await self.call_function(
  File "C:\Users\Plads\Documents\GitHub\stable diffusion\stable-diffusion-avidhjeren\venv\lib\site-packages\gradio\blocks.py", line 1103, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "C:\Users\Plads\Documents\GitHub\stable diffusion\stable-diffusion-avidhjeren\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "C:\Users\Plads\Documents\GitHub\stable diffusion\stable-diffusion-avidhjeren\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "C:\Users\Plads\Documents\GitHub\stable diffusion\stable-diffusion-avidhjeren\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "C:\Users\Plads\Documents\GitHub\stable diffusion\stable-diffusion-avidhjeren\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "C:\Users\Plads\Documents\GitHub\stable diffusion\stable-diffusion-avidhjeren\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "C:\Users\Plads\Documents\GitHub\stable diffusion\stable-diffusion-avidhjeren\extensions\sd-webui-lcm\scripts\main.py", line 172, in generate_i2i
    result = pipe(
  File "C:\Users\Plads\Documents\GitHub\stable diffusion\stable-diffusion-avidhjeren\venv\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "C:\Users\Plads\Documents\GitHub\stable diffusion\stable-diffusion-avidhjeren\extensions\sd-webui-lcm\lcm\lcm_i2i_pipeline.py", line 347, in __call__
    latents, denoised = self.scheduler.step(model_pred, i, t, latents, return_dict=False)
  File "C:\Users\Plads\Documents\GitHub\stable diffusion\stable-diffusion-avidhjeren\venv\lib\site-packages\diffusers\schedulers\scheduling_lcm.py", line 425, in step
    self._init_step_index(timestep)
  File "C:\Users\Plads\Documents\GitHub\stable diffusion\stable-diffusion-avidhjeren\venv\lib\site-packages\diffusers\schedulers\scheduling_lcm.py", line 264, in _init_step_index
    step_index = index_candidates[0]
IndexError: index 0 is out of bounds for dimension 0 with size 0

This is where the code breaks:

# in scheduling_lcm.py
[...]

        index_candidates = (self.timesteps == timestep).nonzero()  # <- this returns a tensor with shape (1, 0) because timestep not in self.timesteps apparently? 

        # The sigma index that is taken for the **very** first `step`
        # is always the second index (or the last index if there is only 1)
        # This way we can ensure we don't accidentally skip a sigma in
        # case we start in the middle of the denoising schedule (e.g. for image-to-image)
        if len(index_candidates) > 1:
            step_index = index_candidates[1]
        else:
            step_index = index_candidates[0]  # <- breaks here

[...]

Any idea why this happens? Thanks.

codercv commented 11 months ago

Approve TXT2IMG - work, IMG2IMG - Not

Traceback (most recent call last):
  File "d:\AISD\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 488, in run_predict
    output = await app.get_blocks().process_api(
  File "d:\AISD\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1431, in process_api
    result = await self.call_function(
  File "d:\AISD\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1103, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "d:\AISD\stable-diffusion-webui\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "d:\AISD\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "d:\AISD\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "d:\AISD\stable-diffusion-webui\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "d:\AISD\stable-diffusion-webui\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "D:\AISD\stable-diffusion-webui\extensions\sd-webui-lcm\scripts\main.py", line 172, in generate_i2i
    result = pipe(
  File "d:\AISD\stable-diffusion-webui\venv\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "D:\AISD\stable-diffusion-webui\extensions\sd-webui-lcm\lcm\lcm_i2i_pipeline.py", line 305, in __call__
    self.scheduler.set_timesteps(strength, num_inference_steps, original_inference_steps)
  File "d:\AISD\stable-diffusion-webui\venv\lib\site-packages\diffusers\schedulers\scheduling_lcm.py", line 377, in set_timesteps
    timesteps = lcm_origin_timesteps[::-skipping_step][:num_inference_steps]
TypeError: slice indices must be integers or None or have an __index__ method
PladsElsker commented 11 months ago

Oh I forgot that I actually had your error first. Your error is the right one.

I fixed the stack trace that you had by manually re-ordering the parameters of a function call in the library files (don't do this). Then, mine came next.

When I tried to re-install diffusers, it did not bring your error back, so I forgot about it haha. I think it should have brought the error back, but it didn't for some reason.

Not sure if all that was super clear, so let me re-iterate: @codercv's error is the one I should have issued.

ricodp54 commented 11 months ago

I'm having this problem too, but I was able to use it fine until a week ago.

wandrzej commented 11 months ago

Same issue here TypeError: slice indices must be integers or None or have an __index__ method

lukecageit commented 11 months ago

Same issue here TypeError: slice indices must be integers or None or have an __index__ method

Same here, i don't know if it can be a new dependency version or something like that?

zenphyl commented 10 months ago

Same issue here TypeError: slice indices must be integers or None or have an __index__ method

same here

Nilok7 commented 10 months ago

Having the same issue here for img2img, while txt2img works fine. Seems to be related to gradio and anyio.

S:\StableDiffusion-Automatic1111\stable-diffusion-webui\venv\lib\site-packages\diffusers\pipelines\pipeline_utils.py:749: FutureWarning: `torch_dtype` is deprecated and will be removed in version 0.25.0.
  deprecate("torch_dtype", "0.25.0", "")
S:\StableDiffusion-Automatic1111\stable-diffusion-webui\venv\lib\site-packages\diffusers\pipelines\pipeline_utils.py:752: FutureWarning: `torch_device` is deprecated and will be removed in version 0.25.0.
  deprecate("torch_device", "0.25.0", "")
Traceback (most recent call last):
  File "S:\StableDiffusion-Automatic1111\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 488, in run_predict
    output = await app.get_blocks().process_api(
  File "S:\StableDiffusion-Automatic1111\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1431, in process_api
    result = await self.call_function(
  File "S:\StableDiffusion-Automatic1111\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1103, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "S:\StableDiffusion-Automatic1111\stable-diffusion-webui\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "S:\StableDiffusion-Automatic1111\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "S:\StableDiffusion-Automatic1111\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "S:\StableDiffusion-Automatic1111\stable-diffusion-webui\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "S:\StableDiffusion-Automatic1111\stable-diffusion-webui\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "S:\StableDiffusion-Automatic1111\stable-diffusion-webui\extensions\sd-webui-lcm\scripts\main.py", line 172, in generate_i2i
    result = pipe(
  File "S:\StableDiffusion-Automatic1111\stable-diffusion-webui\venv\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "S:\StableDiffusion-Automatic1111\stable-diffusion-webui\extensions\sd-webui-lcm\lcm\lcm_i2i_pipeline.py", line 305, in __call__
    self.scheduler.set_timesteps(strength, num_inference_steps, original_inference_steps)
  File "S:\StableDiffusion-Automatic1111\stable-diffusion-webui\venv\lib\site-packages\diffusers\schedulers\scheduling_lcm.py", line 382, in set_timesteps
    timesteps = lcm_origin_timesteps[::-skipping_step][:num_inference_steps]
TypeError: slice indices must be integers or None or have an __index__ method
CalladsEssence commented 10 months ago

Can also confirm this issue. Updated the diffusers conform the LCM README. (which fixed the error in LCM txt2img)

This is my version of AUTOMATIC1111 version: [v1.6.0-2-g4afaaf8a]  •  python: 3.10.6  •  torch: 2.0.1+cu118  •  xformers: N/A  •  gradio: 3.41.2

The line in 'scheduling_lcm.py' that seems to cause trouble is this one (382): timesteps = lcm_origin_timesteps[::-skipping_step][:num_inference_steps]

Since the error is TypeError: slice indices must be integers or None or have an index method

So 'timesteps' must be filled with an integer?

A few lines back (379) an 'int' is mentioned and it is used for 'lcm_origin_timesteps'. lcm_origin_timesteps = np.asarray(list(range(1, int(original_steps strength) + 1))) c - 1

So, is there a problem with either line 379 or line 382?

(no clue if this was useful mentioning, if not: plz forgive me -I'm totally blonde-)

lilyzlt commented 10 months ago

the same error, img2img and video2video all has this problems