Skip to content

Stable Diffusion v2.1 #23

@yuanxion

Description

@yuanxion

MemoryError: CUDA out of memory

  • demo
import torch
from memory_profiler import profile
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler

@profile
def demo_stable_diffusion_2_1(prompt: str) -> None:
    model_id = "stabilityai/stable-diffusion-2-1"
    
    # Use the DPMSolverMultistepScheduler (DPM-Solver++) scheduler here instead
    pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
    pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
    pipe = pipe.to("cuda")
    
    image = pipe(prompt).images[0]    
    image.save("astronaut_rides_horse.png")

prompt = "a photo of an astronaut riding a horse on mars"
demo_stable_diffusion_2_1(prompt)
  • error
$ python demo-stable-diffusion-2.1.py 
...
OutOfMemoryError: CUDA out of memory. Tried to allocate 3.16 GiB (GPU 0; 9.78 GiB total capacity; 5.71 GiB already allocated; 2.16 GiB free; 5.77 GiB reserved in total by PyTorch) If reserved memory is >> 
allocated memory try setting max_split_size_mb to avoid fragmentation.  See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF
image

Log file: mylog901-sd-2.1-cuda-out-of-memory.txt

+   #image = pipe(prompt).images[0]
+   image = pipe(prompt, height=512, width=512, num_inference_steps=20, num_images_per_prompt=2, callback=None,).images[0]
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions