question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[OOM] Memory blows out when trying to upscale images larger than 128x128 using StableDiffusionUpscalePipeline

See original GitHub issue

Describe the bug

When trying to upscale images larger than 128x128 the progress goes to 100% and then crashes with CUDA OOM.

With 512x512 images it’s trying to allocate 256.00 GiB!

Reproduction

import requests
from PIL import Image
from io import BytesIO
from diffusers import StableDiffusionUpscalePipeline
import torch

model_id = "stabilityai/stable-diffusion-x4-upscaler"
pipeline = StableDiffusionUpscalePipeline.from_pretrained(model_id, revision="fp16", torch_dtype=torch.float16)
pipeline = pipeline.to("cuda")

url = "https://www.freepnglogos.com/uploads/512x512-logo/512x512-transparent-circle-instagram-media-network-social-logo-new-16.png"
response = requests.get(url)
low_res_img = Image.open(BytesIO(response.content)).convert("RGB")
prompt=""
upscaled_image = pipeline(prompt=prompt, image=low_res_img).images[0]
display(upscaled_image)

Logs

RuntimeError: CUDA out of memory. Tried to allocate 256.00 GiB (GPU 0; 14.76 GiB total capacity; 4.77 GiB already allocated; 8.28 GiB free; 5.18 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

System Info

  • diffusers version: 0.9.0
  • Platform: Linux-5.10.133±x86_64-with-Ubuntu-18.04-bionic
  • Python version: 3.7.15
  • PyTorch version (GPU?): 1.12.1+cu113 (True)
  • Huggingface_hub version: 0.11.0
  • Transformers version: 4.24.0

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
blefaudeuxcommented, Dec 1, 2022

you can upscale a 512x image with a ~20GB GPU (I didn´t try with less), with the linked PR & using xformers in the attentions in the VAE (when properly picked up by the enablement, hence another PR). I’ve this running just fine on a private fork, it looks like all the missing pieces are arriving here (see this PR) else I can PR the required missing bits

1reaction
kashifcommented, Nov 30, 2022

I tried using it with xformers, i believe, and I think I got the same issue… i can re-run it… But the issue occurs in the creating of this empty tensor in the default attention block:

https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention.py#L331-L337

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add xformers attention to VAE #1507 - huggingface/diffusers
[OOM] Memory blows out when trying to upscale images larger than 128x128 using StableDiffusionUpscalePipeline #1434.
Read more >
r/StableDiffusion - Reddit
r/StableDiffusion - This community continues to blow me away. 8 days ago I ... use SD upscale (tiled upscale) and use the image...
Read more >
CodaLab Worksheets
An announcement must be commercial character Goods and services advancement through P.O.Box system is NOT ALLOWED Deliveries ( spam ) other improper ...
Read more >
Nelson-ComputerLibDreamMachines1975.pdf
The things people try to do with movies, TV and the more glamorous uses of the computer, whereby it makes pictures on screens--...
Read more >
https://huggingface.co/jeniya/BERTOverflow/commit/...
... +then +If +int +In +how +way +fo +##ated +res +me +inst +cre +##per +out ... +implement +##ates +link +direct +tried +des +An...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found