Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EulerDiscreteScheduler.set_timesteps() torch.from_numpy misuse error. #6054

Open
Teriks opened this issue Dec 5, 2023 · 11 comments
Open

EulerDiscreteScheduler.set_timesteps() torch.from_numpy misuse error. #6054

Teriks opened this issue Dec 5, 2023 · 11 comments
Labels
bug Something isn't working contributions-welcome good first issue Good for newcomers

Comments

@Teriks
Copy link

Teriks commented Dec 5, 2023

Describe the bug

In version 0.24.0, on line 283 of schedulers\scheduling_euler_discrete.py

sigmas = torch.from_numpy(sigmas).to(dtype=torch.float32, device=device)

An exception occurs when sigmas is a Tensor object and not a numpy array, when self.config.interpolation_type == "log_linear"

from this setup code directly above

if self.config.interpolation_type == "linear":
    sigmas = np.interp(timesteps, np.arange(0, len(sigmas)), sigmas)
elif self.config.interpolation_type == "log_linear":
    sigmas = torch.linspace(np.log(sigmas[-1]), np.log(sigmas[0]), num_inference_steps + 1).exp()
else:
    raise ValueError(
        f"{self.config.interpolation_type} is not implemented. Please specify interpolation_type to either"
        " 'linear' or 'log_linear'"
    )

Reproduction

import diffusers
import requests
import PIL.Image
import io

pipeline = diffusers.StableDiffusionLatentUpscalePipeline.from_pretrained('stabilityai/sd-x2-latent-upscaler')

url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-upscale/low_res_cat.png"
response = requests.get(url)
low_res_img = PIL.Image.open(io.BytesIO(response.content)).convert("RGB")
low_res_img = low_res_img.resize((128, 128))
prompt = "a white cat"

upscaled_image = pipeline(prompt=prompt, image=low_res_img).images[0]
upscaled_image.save("upsampled_cat.png")

Logs

Loading pipeline components...: 100%|██████████| 5/5 [00:00<00:00,  5.13it/s]
Traceback (most recent call last):
  File "test.py", line 15, in <module>
    upscaled_image = pipeline(prompt=prompt, image=low_res_img).images[0]
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\venv\Lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "...\venv\Lib\site-packages\diffusers\pipelines\stable_diffusion\pipeline_stable_diffusion_latent_upscale.py", line 413, in __call__
    self.scheduler.set_timesteps(num_inference_steps, device=device)
  File "...\venv\Lib\site-packages\diffusers\schedulers\scheduling_euler_discrete.py", line 283, in set_timesteps
    sigmas = torch.from_numpy(sigmas).to(dtype=torch.float32, device=device)
             ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected np.ndarray (got Tensor)

Process finished with exit code 1

System Info

diffusers 0.24.0
torch 2.0.1

Windows

Who can help?

No response

@Teriks Teriks added the bug Something isn't working label Dec 5, 2023
@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Dec 5, 2023

@Teriks
thanks! do you want to open a PR to fix it? just have to change it to np array

@Senume
Copy link

Senume commented Dec 5, 2023

Hi @yiyixuxu,
Let me look into the issue.

@Senume
Copy link

Senume commented Dec 5, 2023

Raised a pull request.

@nileshkokane01
Copy link
Contributor

@yiyixuxu ,

Shouldn't a simple check below suffice ?

sigmas = torch.from_numpy(sigmas).to(dtype=torch.float32, device=device) if not isinstance(sigmas, torch.Tensor) else sigmas

I just did the changes and it is working. I also do not see a PR for this, if so , can I send one?

@Teriks
Copy link
Author

Teriks commented Dec 5, 2023

@yiyixuxu ,

Shouldn't a simple check below suffice ?

sigmas = torch.from_numpy(sigmas).to(dtype=torch.float32, device=device) if not isinstance(sigmas, torch.Tensor) else sigmas

I just did the changes and it is working. I also do not see a PR for this, if so , can I send one?

This is pretty much what I had edited it to locally to see if it would work, but I ran out of free time :)

@SlZeroth
Copy link
Contributor

SlZeroth commented Jan 2, 2024

same issue

@bamps53
Copy link
Contributor

bamps53 commented Jan 31, 2024

@yiyixuxu Is this issue still open? It seems to have been fixed by #6056, and I've confirmed that there is no problem with version 0.25.1.

@SahilCarterr
Copy link

Hi @sayakpaul .It's my first issues on diffuser Library guide me

@sayakpaul
Copy link
Member

Cc: @yiyixuxu

@tolgacangoz
Copy link
Contributor

I recommended @SahilCarterr to study Diffusion Models comprehensively. After studying, it would be more appropriate to examine previously merged good first issue PRs and try to solve unsolved ones, IMHO.

@Teriks
Copy link
Author

Teriks commented Jun 23, 2024

I believe this issue is resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working contributions-welcome good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants