hohonu-vicml/DirectedDiffusion

RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)

Closed this issue · 4 comments

Hello, I'm really inspired by your outstanding work of Directed Diffusion. However, when I tried to run DDCmd.py, I got the following error:

Traceback (most recent call last):
  File "./bin/DDCmd.py", line 440, in <module>
    main()
  File "./bin/DDCmd.py", line 382, in main
    img = DirectedDiffusion.Diffusion.stablediffusion(
  File "/home/****/miniconda3/envs/nullptp/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/home/****/DirectedDiffusion/source/DirectedDiffusion/Diffusion.py", line 91, in stablediffusion
    latent = scheduler.add_noise(
  File "/home/****/.local/lib/python3.8/site-packages/diffusers/schedulers/scheduling_lms_discrete.py", line 187, in add_noise
    sigmas = self.match_shape(self.sigmas[timesteps], noise)
RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)

When I tried to fix it by changing File "/home/****/DirectedDiffusion/source/DirectedDiffusion/Diffusion.py", line 91:

torch.tensor([scheduler.timesteps[t_start]], device=device, dtype=torch.float16)
->
torch.tensor([scheduler.timesteps[t_start]], device=device, dtype=torch.int)

I got:

Traceback (most recent call last):
  File "./bin/DDCmd.py", line 440, in <module>
    main()
  File "./bin/DDCmd.py", line 382, in main
    img = DirectedDiffusion.Diffusion.stablediffusion(
  File "/home/****/miniconda3/envs/nullptp/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/home/****/DirectedDiffusion/source/DirectedDiffusion/Diffusion.py", line 91, in stablediffusion
    latent = scheduler.add_noise(
  File "/home/****/.local/lib/python3.8/site-packages/diffusers/schedulers/scheduling_lms_discrete.py", line 187, in add_noise
    sigmas = self.match_shape(self.sigmas[timesteps], noise)
IndexError: tensors used as indices must be long, byte or bool tensors

Looking forward to your answer! Thanks a lot!

I was running this on NVIDIA A40, CUDA 11.7, Pytorch 1.13.1

Hey @XuGW-Kevin,
Thanks for running the code. Just a quick question: what diffusers version causes the error line 187 (scheduling_lms_discrete.py)? I can't find such line the the file on the diffusers github (e.g., v0.5.1/src/diffusers/schedulers/scheduling_lms_discrete.py and sorry please use v0.5.1 for now to run the DD. We will upgrade our code to the latest diffusers version (v0.14.0)

Thanks a lot! I was using v0.3.0, and when I update it to v0.5.1, it works~

Hi @XuGW-Kevin,

That's the good news. We also just push the new work on the Gradio Web UI app. Please feel free let us know if you run any issues or have any thoughts.

Best,
Kurt