A1111/Forge: A tensor with NaNs was produced (black image)
When calculating in half precision (fp16), invalid numbers were created, and the image turns black or green or crashes.
The message
modules.devices.NansException: A tensor with NaNs was produced in VAE. This could be because there's not enough precision to represent the picture. Try adding --no-half-vae commandline argument to fix this.
Affects: AUTOMATIC1111 Stable Diffusion WebUI, Stable Diffusion WebUI Forge
Why is this happening?
To save memory, the WebUI computes in 16-bit precision. Some VAEs (often with SDXL) and older GTX 10 and 16 series cards cannot handle that, which creates NaN values. A faulty model or a bad merge can also be the cause.
How to fix it
- If the error comes from the VAE: Add the option
--no-half-vaeinwebui-user.batunderset COMMANDLINE_ARGS=and restart. - If the error comes from the Unet: Enable the option "Upcast cross attention layer to float32" under Settings > Stable Diffusion, or try the startup option
--upcast-sampling. - For GTX 10 and GTX 16 cards, the wiki recommends
--upcast-samplingtogether with--xformers, and if needed also--no-half-vae. - Only use
--no-halfas a last resort. It is the slowest and uses the most VRAM, possibly together with--medvram. - If the error only happens with a specific model, the model is the problem. Try a different model or a different VAE.
Better not: --disable-nan-check only hides the error message; the affected images stay black anyway.
Set up from scratch again
If it still doesn’t work after that, a fresh setup step by step often helps:
- VRAM explained: why it decides everything
How much VRAM does local AI need? Rule of thumb, quantization (Q4, Q8, fp8), context, image and video models, offloading, and which card si…
Terms for this
Similar errors
- A1111/Forge with RTX 50: sm_120 is not compatible
- A1111/Forge: Torch is not able to use GPU
- AMD Radeon is not being used, PyTorch is running on the CPU
- RuntimeError: CUDA error: an illegal memory access was encountered – the graphics card accessed invalid memory
- The NVIDIA driver on your system is too old
Sources
- https://raw.githubusercontent.com/wiki/AUTOMATIC1111/stable-diffusion-webui/Troubleshooting.md
- https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/modules/devices.py
Checked on Oct 21, 2026. Didn't help? Ask in the forum and name the graphics card, program, and the full message.