Stable Diffusion is one of the AI tools that people have been employing to produce AI art because it is openly accessible and free to use. The program can be used locally on a computer with a dedicated GPU or remotely through a HuggingFace Demo.
In this article, we will assist you in resolving the Stable Diffusion Cuda Out of Memory issue and enabling Stable Diffusion if you have been attempting to use it on your machine but are encountering problems.
How to fix the Stable Diffusion Cuda Out of Memory issue?
There are various ways that you can try while attempting to fix the Stable Diffusion Cuda Out of Memory error. Below, you can see a list of these ways and see if they will be able to save you from the issue.
Restarting your system
If Stable Diffusion was previously functioning without any issues, it’s possible that a simple system restart will solve the issue for you as the Stable Diffusion software may have lost access to some GPU components. After a system restart, some users were able to swiftly resolve the Stable Diffusion Cuda Out of Memory error on their PC.
Installing Anaconda
Installing and using the Anaconda prompt is another workaround offered by users to run Stable Diffusion without issues. For those of you who don’t know, Anaconda is a free environment management tool that can install and run Python application packages. To use Stable Diffusion without problems, install Anaconda, get the NVIDIA CUDA Toolkit, and then follow the directions from the Python GitHub repo of your choosing.
Using a more optimized version of Stable Diffusion
If the Stable Diffusion Cuda Out of Memory problem persists, you can try using an optimized version of Stable Diffusion, for which you might need to check out how to install Stable Diffusion on Windows. To fix the issue, download the optimized version of Stable Diffusion and paste its contents into the stable-diffusion-main folder if the original version of Stable Diffusion is already installed on your computer.
Generating images with lower resolution
You can encounter the Stable Diffusion Cuda Out of Memory issue problem if you attempt to generate photos at a higher resolution. This is due to the fact that higher-quality photos demand a much bigger GPU memory.
Lowering the image resolution, which can be done by modifying the height and width values inside of Stable Diffusion, allowed users to fix the issue. If your GPU RAM is less than 4 GB, you can try selecting 512 x 512 or 256 x 256 as the required resolutions, or choose something lower.
Reducing sample size to one
Stable Diffusion by default produces many images concurrently, just like any other image generator. However, if you use a lot of images, your GPU may run out of memory and give you the “Cuda Out of Memory” error. Enter “-n_samples 1” in your input prompt to fix this by lowering the sample size to 1.
Checking your GPU memory
It is advised to use a GPU with at least 6 GB of RAM to run Stable Diffusion without any issues, however things can also be made to work with GPUs with 4 GB of RAM. Anything less will prevent the Stable Diffusion software from using your GPU’s memory, forcing you to run it directly on your CPU, which might increase your creation time to at least two minutes each image.
Your best option is to upgrade your graphics card to one with at least 6 GB of memory if you want to avoid getting the Stable Diffusion Cuda Out of Memory error.
Editing the webui-user.bat file
Stable Diffusion executes commands to create images on your machine through the webui-user.bat file. To test whether updating this file with optimized commands fixes your system’s Stable Diffusion Cuda Out of Memory error, try doing so.
- Find the webui-user.bat file inside the Stable Diffusion folder
- Right-click on it, and select Edit > Notepad to get started.
- Then, you can test out each command line optimization on this GitHub page to see which one works best for you.
Hopefully, one of these 7 methods will rid you of the frustrating issue. If you are in need of any other guidance, you may want to check out our article about Stable Diffusion prompts, examples, and how to run.