rbbrdckybk / dream-factory

Multi-threaded GUI manager for mass creation of AI-generated art with support for multiple GPUs.
MIT License
487 stars 57 forks source link

Cuda out-of-memory error when using larger dimensions for output- or seed images #11

Closed botradingblog1 closed 1 year ago

botradingblog1 commented 1 year ago

Hello,

First of all thanks for coding the dream-factory - a really cool tool! I have a NVIDIA RTX 3070 with 8GB memory and am running into an issue when I use larger dimensions for the output format (e.g. 3000x4000) or seed images (2400x3000), I get the CUDA out-of-memory error below. I tried setting the PYTORCH_CUDA_ALLOC_CONF environment variable but it didn't solve the issue. On the forums they suggested to reduce the batch size but I checked the dream-factory source code and it is already set to 1. Do you have any suggestions to create larger images?

Thanks!

RuntimeError: CUDA out of memory. Tried to allocate 65.48 GiB (GPU 0; 8.00 GiB total capacity; 2.74 GiB already allocated; 2.88 GiB free; 2.81 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 [cuda:0] >>> finished job #1 in 22.55 seconds.

rbbrdckybk commented 1 year ago

3000x4000 is way beyond what you'll be able to do with 8GB of VRAM (you can see pytorch tried to allocate 65GB+ of memory for the operation!). With 8GB of VRAM and !SD_LOW_MEMORY = yes, you should be able to do roughly 1024x1024 (not exactly sure, I don't have an 8GB GPU to test). Start there and keep lowering until you don't get out-of-memory errors to find your max.

To generate higher resolution images, most people use upscaling. Real-ESRGAN is built into Dream Factory, so that'll probably be your most convenient option. Results can be very good even with upscale factors set to 3-4x, depending on your source image. You can set !USE_UPSCALE = yes and !UPSCALE_AMOUNT = 3.0 to get 2304x2304 output images if your generation size is 768x768, for example.

botradingblog1 commented 1 year ago

That makes sense. Thanks for the detailed explanation. :)