Skip to content

DPMSolverSinglestepScheduler with use_karras_sigmas=True triggers RuntimeError: a Tensor with 2 elements cannot be converted to Scalar  #4631

Closed
@alexisrolland

Description

@alexisrolland

Describe the bug

Hello @patrickvonplaten and @williamberman 🤗

Running StableDiffusionPipeline with DPMSolverSinglestepScheduler and use_karras_sigmas=True triggers the error RuntimeError: a Tensor with 2 elements cannot be converted to Scalar when generating images with a high num_inference_steps (~100). Note this issue does not happen with low num_inference_steps (~20).

Reproduction

import os
import torch
from diffusers import StableDiffusionPipeline, DPMSolverSinglestepScheduler

MODEL_PATH = os.getenv('MODEL_PATH')
pipeline = StableDiffusionPipeline.from_pretrained(MODEL_PATH, torch_dtype=torch.float16, variant='fp16')
pipeline.scheduler = DPMSolverSinglestepScheduler.from_pretrained(MODEL_PATH, subfolder='scheduler', use_karras_sigmas=True)
pipeline.enable_model_cpu_offload()

prompts = ["a cat playing with a ball in the forest"]
negative_prompts =["bad quality"]
seed = 123456
generators = torch.Generator(device='cuda').manual_seed(seed)

image = pipeline(
    prompt=prompts,
    negative_prompt=negative_prompts,
    width=800,
    height=1200,
    num_inference_steps=100,
    guidance_scale=6,
    num_images_per_prompt=1,
    generator=generators
).images[0].save("image.png")

Logs

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py", line 688, in __call__
    latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs, return_dict=False)[0]
  File "/usr/local/lib/python3.10/site-packages/diffusers/schedulers/scheduling_dpmsolver_singlestep.py", line 670, in step
    step_index = step_index.item()
RuntimeError: a Tensor with 2 elements cannot be converted to Scalar

System Info

  • diffusers version: 0.19.3
  • Platform: Linux-5.4.72-microsoft-standard-WSL2-x86_64-with-glibc2.36
  • Python version: 3.10.12
  • PyTorch version (GPU?): 2.0.1+cu117 (True)
  • Huggingface_hub version: 0.16.4
  • Transformers version: 4.30.2
  • Accelerate version: 0.21.0
  • xFormers version: 0.0.20
  • Using GPU in script?: Yes
  • Using distributed or parallel set-up in script?: No

Who can help?

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions