Here is how to run the Stable Diffusion Automatic1111 WebUI locally on a system with under 4GB of GPU memory, or even when having only 2 GB of VRAM on board. It’s actually quite simple, and I’ll show you all the setting tweaks you can use to make Stable Diffusion run and generate images even on a low VRAM graphics card. Here is exactly how to go about it.
The short version: with 4 to 6 GB of VRAM, add –medvram to your webui-user.bat file (or –medvram-sdxl if you mostly use SDXL models). With 2 to 4 GB, use –lowvram instead. Then keep your resolution and batch size modest. If you don’t have the WebUI installed yet, here is how to install Automatic1111 on Windows.
Using SDXL on a card with 4-6GB of VRAM? There are easier options than A1111 for that, covered in the SDXL section below.
VRAM vs. System RAM

VRAM, or GPU memory is the amount of memory your graphics card has on board – it’s simply short for “video RAM”. On your GPU you have a fixed amount of VRAM that is different for different graphics cards models on the market. It can’t be changed or upgraded, as the internal memory chips on graphics cards are by design permanently soldered to the GPU mainboard.
The more VRAM a GPU has, the more data it can generally hold/quickly process at the same time. GPU memory grants the video card a quick access to the data stored within it, allowing for quick calculations that don’t have to rely on reading data off the hard drive or main system memory (RAM).
Remember, all types of data transfer between different pieces of hardware inside your computer take time, so being able to hold a substantial amount of data inside the GPU memory during its operation gives you a huge advantage.
When dealing with most types of modern AI software, using LLMs (large language models), training statistical models, and attempting to do any kind of efficient large-scale data manipulation you ideally want to have access to as much VRAM on your GPU as possible. Stable Diffusion is actually one of the least video card memory-hungry AI image generators out there, as by design it makes use of the latent diffusion for the image generation process.
Older graphics cards often came with 2, 4 or 6 GB of VRAM, while most current models have between 8 and 16 GB, and high-end ones even more. During the SD image generation process, all the processed image data is stored in VRAM.
For efficient image generation with Stable Diffusion I recommend having at least 8GB of VRAM, however as you will see in a short while, generating images is possible also with even less than 4GB of VRAM, provided you adhere to a few important rules and tweak your settings accordingly to avoid out-of-memory errors.
Stable Diffusion “CUDA out of memory” Error – How To Fix

When for one reason or another you run out of your GPU memory (VRAM) during the Stable Diffusion image generation process, you will be faced with an out-of-memory error. In case of newer NVIDIA GPUs, this error may look something like this:
torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 128.00 MiB (GPU 0; 3.00 GiB total capacity; 2.32 GiB already allocated; 0 bytes free; 2.45 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
What is the quick fix for the CUDA out of memory error in Stable Diffusion? Well, you need to somehow limit your runtime VRAM usage. There are quite a few ways to do that here, so let’s get to the best of the available optimizations for generating images on older GPUs with limited amounts of on-board VRAM using the Stable Diffusion WebUI.
The rest of this article contains all the tips and setting tweaks you’ll need to prevent this error from happening.
How To Run Stable Diffusion With Only 6, 4 or 2 GB Of VRAM – Quick Solution
Here is the official method of running the Automatic1111 Stable Diffusion WebUI with less than 4 GB of VRAM.
Running Stable Diffusion With 4-6 GB Of VRAM

To attempt to successfully use Stable Diffusion when having only between 4 and 6 gigabytes of memory in your GPU, is to run the Stable Diffusion WebUI in medvram mode.
The medvram mode is meant for GPUs with 4-6 GB of internal memory, while the lowvram mode which I’ll discuss next, was created to aid generating images on graphics cards that only have 2 GB of operational VRAM to spare.
You can enable each of these modes by editing the webui-user.bat file which is located in the main directory you’ve got Stable Diffusion installed in, and inputting appropriate flags into the line starting with “COMMANDLINE_ARGS=”. Here are the exact steps you need to take:
- Go to the directory you’ve got Stable Diffusion WebUI installed in. Close the WebUI console window if you had it open.
- Edit the webui-user.bat file using a plain text editor (On Windows you need to right click the file and select the Edit option to open it in your system notepad).
- Change the line containing commandline arguments to look like this: COMMANDLINE_ARGS= –medvram
- Save and close the webui-user.bat file and run it. Stable Diffusion WebUI should now start with the medvram optimizations enabled.
The –medvram flag reduces your GPU VRAM usage by splitting the image generation process into 3 basic modules. Each of these modules is loaded into the graphics card’s memory one at the time and processed separately. Once one module resides in VRAM during runtime, other modules are being held in the main system RAM.
This greatly reduces the overall VRAM usage, at the cost of performance. As each of the modules has to do its work separately, the image generation time will naturally get a little bit more lengthy. This is the only tradeoff connected with using the –medvram flag, which has otherwise no impact on the final output image quality.
Note: Don’t use the Live Previews option together with either the –medvram or the –lowvram settings turned on. If you do, you will notice a further large negative impact on the performance.
You can read more about the low VRAM optimizations in the official Stable Diffusion Automatic1111 WebUI documentation over on GitHub.
If you’re still facing any out-of-memory errors after this, try the generation setting tweaks covered a bit further down, or move on to the –lowvram flag. One flag to avoid here is –always-batch-cond-uncond, which you’ll find recommended in some older guides. According to the WebUI documentation, it actually turns off the memory-saving prompt batching that medvram and lowvram enable, so it raises your VRAM usage instead of lowering it.
For less than 2 GB of VRAM in your GPU, skip ahead to the lowvram section!
Running SDXL Models With 6-8 GB Of VRAM
SDXL models are much larger than the SD 1.5 ones, so cards that handle SD 1.5 just fine can run out of memory with them. Automatic1111 has a separate –medvram-sdxl flag for that. It turns on the medvram optimizations only when an SDXL model is loaded, so your SD 1.5 generations keep their full speed.
There are also two other WebUIs that deal with low VRAM much better on their own. Stable Diffusion WebUI Forge looks and works almost exactly like A1111, but it manages GPU memory automatically, so you don’t need any of the flags from this article. And Fooocus can run SDXL models on as little as 4-6GB of VRAM with almost no setup, although it only gets bug fixes these days.
Running Stable Diffusion With 2 GB Of VRAM
The steps are almost the exact same here. Edit the webui-user.bat file in the same way as you did in the paragraph above, but this time use the –lowvram flag.
This way, the UNET will be split into even more modules that will be loaded into your graphics card memory separately as they enter the processing queue. Keep in mind though, that this can make the general image generation process take substantially more time to finish, and it will certainly be noticeably longer than when using the –medvram flag.
When using the –lowvram setting only one module is loaded into memory while others reside in your system RAM, similarly to the –medvram flag. This unfortunately means that while the final quality of your images won’t be affected in any way, the overall generation speed will suffer by a lot. This is a small price you have to pay for being able to successfully generate images using Stable Diffusion on older graphics cards equipped with only 2 GB of VRAM.
If you’re still getting out-of-memory errors after using the –lowvram flag, close all the programs you don’t need while generating images, as they can eat up a chunk of VRAM that Stable Diffusion could otherwise use. This includes browser windows with videos playing, streams open on a second monitor, image editing apps and so on. Some of the biggest VRAM users are not that obvious though, so take a look at my list of hidden VRAM hogs and how to free up your GPU memory.
If that didn’t help, and you still don’t have enough memory to generate your images, check out the next paragraph – there are some more vital generation settings in the SD WebUI itself that you can tweak to make most out of your limited GPU memory.
Stable Diffusion Low VRAM Generation Settings

Generating images locally using Stable Diffusion (through the Automatic1111 WebUI or other GUIs and forks of the original project) can be efficiently done with as little as 8 GB of GPU memory, and as you have seen, with some modifications it’s also possible on older GPUs featuring less than that, for example 6, 4, or 2 GB of VRAM only.
Here are some of the most important settings you need to keep an eye on when attempting to generate images on systems with low VRAM GPUs using the Stable Diffusion WebUI.
- The –medvram or –lowvram flags set accordingly – on systems with less than 6/4/2 GB of VRAM you might need to make use of the built-in WebUI optimizations for low VRAM systems. You can learn how to do that in about 30 seconds in the paragraphs above.
- The output image resolution – the larger the image you’re trying to generate, the more VRAM will the generation process require. If you’re planning to generate images with larger resolutions while being low on GPU memory, keep in mind that you can hit the max res limit pretty fast.
- Batch size setting – The more images you’ll try to generate in one go upping the batch size setting, the more operational VRAM you’ll need during the generation process. On low VRAM systems be sure that you don’t try to set the batch size too high. Learn more about batch size and count settings in this short guide. There is much more to be said here!
- Use Xformers on NVIDIA GPUs for faster image generation – Xformers is a library that the Stable Diffusion WebUI makes use of to speed up the image generation. Keep in mind that it will only work on NVIDIA graphics cards. You can activate it with the –xformers flag in the webui-user.bat file, and in many cases it can help you counter the longer image generation times caused by activating numerous low VRAM fixes.
Keeping an eye on these parameters and setting their values accordingly can ensure that you will be able to generate great quality images even with as little as 2GB of VRAM.
Solid Black/Green Image Instead of Meaningful Output?
If after the image generation process finished you’re left with green or black image instead of your desired picture, there is a quick fix for that too!
In low VRAM situations, this issue is in most cases caused by a GPU that doesn’t have built-in support for half-precision floating point numbers. This is an issue on many older graphics cards, so there is a high chance that you can run into it at some point.
Luckily, I have a short guide on how to fix this error. See here for the quick solution: Stable Diffusion Black/Green Images Quick Fix (WebUI Tensor NansException Errors)
What Does More VRAM Give You In Stable Diffusion?

After all this you might ask: what does having more GPU memory allow you to do in Stable Diffusion? Do you even need more than 8 GB for using Stable Diffusion efficiently? Here is my answer to that.
There are quite a few benefits awaiting for you when it comes to Stable Diffusion if you’re lucky to have more than 8 GB on VRAM in your GPU. Here are some of the most important ones:
- Ability to generate more images at the same time quicker, by allowing you to set higher batch sizes.
- Ability to generate larger images by giving you access to higher image resolutions without out-of-memory errors.
- Compared to generating images with lower amounts of VRAM (6 GB and below), having more GPU memory lets you generate your pictures much faster, as you don’t need to resort to any kind of fixes that could otherwise compromise performance in a tradeoff for lowered VRAM usage (like the ones mentioned in this article).
More VRAM also helps with games, video editing and 3D work, so it’s worth thinking about when you plan to upgrade your GPU. If you’re shopping for a card with Stable Diffusion in mind, here are my GPU picks for Stable Diffusion, SDXL and FLUX.
Check out also: How To Train Own Stable Diffusion LoRA Models – Full Tutorial!
Check out also: Stable Diffusion WebUI Running Slow? – 8 Simple Solutions
