Skip to main content
Free AI Prompt Maker
Back to Blog
stable-diffusion

Stable Diffusion Low VRAM Guide: Flags & Settings That Work

Eren KorayJune 6, 20268 min
stable diffusion low vrammedvramlowvramsdxl low vramstable diffusion out of memorystable diffusion optimization
Editorial status
Verified
Last verified
2026-10-15
Sources
5 listed

Key takeaways

  • Quick fixes before any flags
  • AUTOMATIC1111 flags
  • ComfyUI
  • Diffusers (Python)

Advantages and limitations

Quick tradeoff check

Advantages

  • Most out-of-memory errors can be fixed with one or two flags
  • The fixes cost speed, not image quality

Limitations

  • The strongest memory savers (--lowvram, sequential offload) are very slow
  • Flags and defaults change between versions; check your tool's docs after updating

"CUDA out of memory" usually has a short list of causes: the model is too big for your card, the image is too large, or you are generating several images at once. This guide starts with the quick fixes, then the flags for AUTOMATIC1111, ComfyUI and Diffusers.

Quick fixes before any flags

FixWhy it helps
Batch size 1Every extra image in a batch needs its own memory
Generate at the model's native sizeSD 1.5 was fine-tuned at 512×512, SDXL works around 1024×1024; larger first passes need far more memory
Upscale in a second stepHires fix or tiled upscaling uses less memory than generating big directly
Turn off extras you don't needEach ControlNet, refiner or extra model takes VRAM
Close other GPU appsBrowsers, games and video players hold VRAM too
Turn off live previewsThe AUTOMATIC1111 wiki notes they cost speed when memory flags are on

AUTOMATIC1111 flags

Add flags to COMMANDLINE_ARGS in webui-user.bat on Windows:

 COMMANDLINE_ARGS=--medvram-sdxl --xformers

On Linux, edit webui-user.sh instead:

 COMMANDLINE_ARGS=

The examples below use the Windows form.

FlagWhat it doesCost
--xformersMemory-efficient attention through the xFormers library (NVIDIA only)Usually faster, not slower
--opt-sdp-attentionPyTorch 2 scaled dot product attentionMay be faster than xFormers on some systems, uses more VRAM
--opt-sub-quad-attentionMemory-efficient attention for when xFormers doesn't work, including macOSSometimes slightly slower
--medvram-sdxlTurns on --medvram for SDXL models onlySmall speed loss on SDXL
--medvramSplits the model into three parts and keeps only one in VRAM at a time"Only by a bit," per the wiki, unless live previews are on
--lowvramSplits the UNet into many modules for very low VRAMThe wiki calls the performance impact "devastating"
--upcast-samplingFor cards forced to run with --no-half: similar results with better speed and less memory—

Which flags to try first

 COMMANDLINE_ARGS=--xformers

Start here on NVIDIA cards. In the wiki's benchmark on an RTX 3060, xFormers reached about 7.5 it/s against 4.6 it/s with no optimization, while also using less memory.

 COMMANDLINE_ARGS=--xformers --medvram-sdxl

Add this if SD 1.5 runs fine but SDXL runs out of memory.

 COMMANDLINE_ARGS=--xformers --medvram

Use this if every model runs out of memory.

 COMMANDLINE_ARGS=--lowvram

This is the last resort. It works on very small cards but is much slower.

If xFormers will not install or your GPU is not NVIDIA, try --opt-sub-quad-attention instead.

ComfyUI

ComfyUI manages memory automatically: its README describes smart VRAM and RAM management and model offloading, and says it can run the biggest open models on as little as 4 GB of VRAM with 8 GB of system RAM. In practice that means:

  • Start ComfyUI normally first; it offloads on its own when memory runs short.
  • If you still run out of memory, run python main.py --help to see the memory flags for your version (such as low-VRAM and CPU modes).
  • Use tiled VAE decode nodes for large images.
  • Load fewer models into one workflow; every checkpoint, ControlNet and upscaler adds up.

Diffusers (Python)

The Diffusers memory guide lists these options, from cheapest to most drastic:

 torch
 diffusers  StableDiffusionXLPipeline

pipe = StableDiffusionXLPipeline.from_pretrained(
    ,
    dtype=torch.float16,  
)
pipe.enable_model_cpu_offload()   
pipe.vae.enable_slicing()         
pipe.vae.enable_tiling()          
MethodEffect
dtype=torch.float16 (or bfloat16)Half-precision weights; roughly halves model memory
enable_model_cpu_offload()Moves whole models (text encoder, UNet, VAE) to the GPU only when needed; much faster than sequential offload, saves less
vae.enable_slicing()Saves memory when generating several images at once
vae.enable_tiling()Saves memory on large images; may cause slight tone variation between tiles
enable_group_offload(...)Offloads groups of layers; less memory than model offload, faster than sequential offload
enable_sequential_cpu_offload()Lowest memory, but the docs call it "extremely slow"

Do not move the pipeline to CUDA with .to("cuda") before calling enable_sequential_cpu_offload(); the Diffusers docs warn that the savings are then minimal.

SDXL on a small card

SDXL is the most common reason people hit memory limits. In order:

  1. Generate at SDXL's native sizes (1024×1024 or the other native aspect ratios), batch size 1.
  2. Skip the refiner, or run it as a separate step.
  3. AUTOMATIC1111: --xformers --medvram-sdxl. Diffusers: fp16 plus enable_model_cpu_offload().
  4. Use tiled VAE decoding for large outputs.

The SDXL prompt guide lists the native resolutions and settings.

Common errors

Message or symptomWhat to try
CUDA out of memory during generationBatch size 1, smaller first pass, then --medvram / --medvram-sdxl
Out of memory at the very end (VAE decode)Tiled VAE decoding, or vae.enable_tiling() in Diffusers
VAE problems in half precision--no-half-vae keeps the VAE in 32-bit floats (uses more memory)
Very slow after adding flagsYou may be on --lowvram or sequential offload; step back to --medvram

Build your prompt

Short, clear prompts don't use less VRAM, but they waste fewer generations. The prompt generator builds one from your subject and style. It runs in your browser and does not generate images. For extensions that add tiled upscaling and other tools, see the Stable Diffusion extensions guide.

Primary sources

Share this article

Ready to create your own prompts?

Try our visual prompt generator - no memorization needed!

Try Prompt Generator

Related Articles

Optional analytics

Allow privacy-safe traffic measurement to help us improve the tools. The site works without analytics cookies.

Learn more about analytics cookies