## 事象 [[Stable Diffusion]]を実行すると以下のようなエラーになる。 ``` RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 4.00 GiB total capacity; 3.42 GiB already allocated; 0 bytes free; 3.48 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 ``` > [!note] > - 実行したマシンは[[New Precision 5470]] > - 実行コマンド `python scripts/txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms` ## 原因 [[CUDA]]に必要な[[VRAM]]の容量を確保できていないため。 ## 解決方法 軽量版の`basujindal/stable-diffusion`を使う。以下のコマンドで成功を確認。 ```console python optimizedSD/optimized_txt2img.py --prompt "Cyberpunk style image of a Telsa car reflection in rain" --H 512 --W 512 --seed 27 --n_iter 2 --n_samples 10 --ddim_steps 50 ``` ## 参考 - [話題のStable Diffusionがオープンソース化されたのでローカルで動かしてみる](https://zenn.dev/koyoarai_/articles/02f3ed864c6127bb2049)