Stable Diffusion Low VRAM Guide: Flags & Settings That Work
- Editorial status
- Verified
- Last verified
- 2026-10-15
- Sources
- 5 listed
On this page
Key takeaways
- Quick fixes before any flags
- AUTOMATIC1111 flags
- ComfyUI
- Diffusers (Python)
Advantages and limitations
Quick tradeoff checkAdvantages
- 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
| Fix | Why it helps |
|---|---|
| Batch size 1 | Every extra image in a batch needs its own memory |
| Generate at the model's native size | SD 1.5 was fine-tuned at 512×512, SDXL works around 1024×1024; larger first passes need far more memory |
| Upscale in a second step | Hires fix or tiled upscaling uses less memory than generating big directly |
| Turn off extras you don't need | Each ControlNet, refiner or extra model takes VRAM |
| Close other GPU apps | Browsers, games and video players hold VRAM too |
| Turn off live previews | The 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.
| Flag | What it does | Cost |
|---|---|---|
--xformers | Memory-efficient attention through the xFormers library (NVIDIA only) | Usually faster, not slower |
--opt-sdp-attention | PyTorch 2 scaled dot product attention | May be faster than xFormers on some systems, uses more VRAM |
--opt-sub-quad-attention | Memory-efficient attention for when xFormers doesn't work, including macOS | Sometimes slightly slower |
--medvram-sdxl | Turns on --medvram for SDXL models only | Small speed loss on SDXL |
--medvram | Splits 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 |
--lowvram | Splits the UNet into many modules for very low VRAM | The wiki calls the performance impact "devastating" |
--upcast-sampling | For 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 --helpto 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()
| Method | Effect |
|---|---|
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:
- Generate at SDXL's native sizes (1024×1024 or the other native aspect ratios), batch size 1.
- Skip the refiner, or run it as a separate step.
- AUTOMATIC1111:
--xformers --medvram-sdxl. Diffusers: fp16 plusenable_model_cpu_offload(). - Use tiled VAE decoding for large outputs.
The SDXL prompt guide lists the native resolutions and settings.
Common errors
| Message or symptom | What to try |
|---|---|
CUDA out of memory during generation | Batch 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 flags | You 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
Try the Visual Prompt Generator
Build Midjourney, DALL-E, and Stable Diffusion prompts without memorizing parameters.
Go →See more AI prompt guides
Explore more AI art prompt tutorials and walkthroughs.
Go →Ready to create your own prompts?
Try our visual prompt generator - no memorization needed!
Try Prompt Generator