forked from Picsart-AI-Research/Text2Video-Zero
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
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
Log file: mylog901-sd-2.1-cuda-out-of-memory.txt
- Solution: change resolution to 512*512
https://huggingface.co/docs/diffusers/v0.11.0/en/api/pipelines/stable_diffusion#diffusers.StableDiffusionPipeline.__call__
+ #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]

Metadata
Metadata
Assignees
Labels
No labels