How to run Stable Diffusion Web UI with little VRAM

Share

It's possible to run Stable Diffusion's Web UI on a graphics card with a little as 4 gigabytes of VRAM (that is, Video RAM, your dedicated graphics card memory). In this article I'll list a couple of tricks to squeeze the last bytes of VRAM while still having a browser interface, so you won't get out of memory (OOM) errors while trying to render something.

Close All Other Programs and Tabs

The first and most obvious solution: close everything else that is running. That should free some VRAM for Stable Diffusion to use. Background programs can also consume VRAM sometimes, so just close everything.

Use XFormers

In Stable Diffusion's folder, you can find webui-user.sh (for Linux) and webui-user.bat (for Windows). These are your user scripts, which are executed every time the Web UI script is run. In order to use XFormers, which should decrease your VRAM usage, you need to include a parameter in the command line arguments.

On Windows, you'll need to open the .bat file in Notepad (or Notepad++, not execute it) and write:

set COMMANDLINE_ARGS=--xformers

Then save it.

On Linux, for the .sh file, you'll need to write:

export COMMANDLINE_ARGS="--xformers"

Note that there shouldn't be spaces around the =. If you write COMMANDLINE_ARGS = --xformers with spaces it may not work.

You will have to stop Stable Diffusion and run webui.sh or webui.bat again for these changes to take effect. If it's configured correctly, the script will automatically download, install, and enable XFormers.

Use --medvram or --lowvram

Again in your user script, you can include --medvram or --lowvram to change Stable Diffusion's strategy. This is a bad idea if you have enough VRAM to render the size you want, because these options will make Stable Diffusion render much slower. Only use these if you keep getting OOM errors.

Combined with XFormers, the command should look like this on Windows:

set COMMANDLINE_ARGS=--xformers --medvram

On Linux:

export COMMANDLINE_ARGS="--xformers --medvram"

Disable the Browser's Hardware Acceleration

On Firefox, you can disable the browser's hardware acceleration in settings. Currently the setting is called "Use recommended performance settings." By unchecking that and restarting Firefox, Firefox will render the pages using RAM and your CPU instead of VRAM and your GPU, which means having the browser open won't take VRAM away from Stable Diffusion.

Use Another Web UI

Different front ends for Stable Diffusion may use VRAM differently. It seems Comfy UI uses less VRAM when rendering, while Kohya SS uses less VRAM for training.

Use Linux

The last and final drastic measure you can take is to install Linux. On Linux, you have extremely lightweight desktop environments that consume very little VRAM compared to Windows. For example, Lxqt (which comes with Lubuntu) consumes as little as 100 megabytes of VRAMs, while Windows will consume around 500 megabytes without any applications open. Thus, by using Lxqt instead of Windows, you have 400 extra megabytes for Stable Diffusion to use.

Use Python

The real last and final drastic measure is to give up on having a GUI, learn to program Python, write a script for Stable DIffusion that does what you want, then run it in Linux from a full black terminal screen without having a desktop environment running. If you don't have enough VRAM then, there is no choice but to buy a better graphics card.

Comments

Leave a Reply

Leave your thoughts! Required fields are marked *