Stability-AI / stablediffusion

High-Resolution Image Synthesis with Latent Diffusion Models
MIT License
38.33k stars 4.95k forks source link

[WINDOWS10/CUDA] torch.cuda.OutOfMemoryError: CUDA out of memory #187

Open s20290 opened 1 year ago

s20290 commented 1 year ago

I am using the following command:

python39 ./scripts/txt2img.py --prompt "a professional photograph of an astronaut riding a horse"
 --ckpt .\768-v-ema.ckpt --config  .\configs\stable-diffusion\v2-inference-v.yaml --H 20 --W 20 
 --precision full --device cuda --bf16 --n_samples 1 --f 1

I get such an error.

torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 30.00 MiB (GPU 0; 6.00 GiB total capacity; 
5.30 GiB already allocated; 0 bytes free; 5.37 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

I thought I could simply edit PYTORCH_CUDA_ALLOC_CONF to set a limit on memories, not sure if that is how things work but it would be weird if the only way to avoid this is to "update your gpu", anyhow I cannot find such a variable or text file yet.

I know that there is an optimized stable diffusion but I believe it is using the previous version? I would like to use SD 2.0.

What grinds my gears is that the UI version works just fine and I can even generate a bigger image, here I am using W:20 H:20 just for the sake of debugging and it will not work. I wonder what exactly is the problem.

Bohndiggin commented 1 year ago

I've done some testing and it seems that the 768-v-ema.ckpt will be loaded into GPU memory regardless of the size of the image being made.

Have you tried the 512 model? here

Also of note, the dimensions should be divisible by 8.

Hope this helps!

ZeyadWaell commented 1 year ago

did it work with u ?>