NansException: A tensor with all NaNs was produced in Unet.
The message
NansException: A tensor with all NaNs was produced in Unet.What it means
The image model's output came back as NaN (not a number, a value that means the math broke), and the WebUI stopped instead of handing you a black square. Running in 16-bit half precision is the usual cause.
What to do
Turn on Settings > Stable Diffusion > Upcast cross attention layer to float32, or add --upcast-sampling to COMMANDLINE_ARGS. If that fails, use --no-half (and --no-half-vae for the VAE version).
Generation runs, the progress bar may even finish, and then AUTOMATIC1111's Stable Diffusion WebUI throws this instead of an image:
NansException: A tensor with all NaNs was produced in Unet. This could be either because there's not enough precision to represent the picture, or because your video card does not support half type. Try setting the "Upcast cross attention layer to float32" option in Settings > Stable Diffusion or using the --no-half commandline argument to fix this. Use --disable-nan-check commandline argument to disable this check.
In a console traceback the first word is modules.devices.NansException. The line most people search is the start of it: NansException: A tensor with all NaNs was produced in Unet. There's a VAE version too, and both are covered here.
What the WebUI is checking
We read modules/devices.py at v1.10.1, the latest release as of October 1, 2026. After sampling, the WebUI looks at the Unet's output (the Unet is the part of the model that denoises the picture step by step). If it holds NaN values, short for "not a number", the arithmetic broke somewhere and the picture would decode to solid black. Rather than show you that, it raises NansException. The same check runs on the VAE, the part that turns the result into pixels.
The text also changes with your flags. The hint about half type only appears if you aren't already running --no-half, and the VAE hint disappears once you run --no-half-vae.
A collaborator summed it up in issue #6923 (283 comments, January 2023): "what we see in the error message is just a symptom." Another, catboxanon, wrote in August 2023 that the cause "is there usually being lack of precision somewhere," and added that extensions can cause it too.
Flags and settings that fix it
Half precision (16-bit floats) is the WebUI's default because it's faster and uses half the VRAM, but some cards and some models can't hold the numbers in it. These are the fixes the code and the wiki name, roughly in the order people try them:
- Settings > Stable Diffusion > "Upcast cross attention layer to float32", which is what the message itself suggests.
- The
--upcast-samplingflag. The wiki's troubleshooting page recommends--upcast-samplingwith--xformersfor Nvidia 16XX and 10XX cards. --no-half-vaeif the message says VAE.--no-half, or--precision full --no-half, which runs everything in 32-bit and uses the most VRAM (you may need--medvramwith it).
Flags go on the set COMMANDLINE_ARGS= line in webui-user.bat on Windows, or the export COMMANDLINE_ARGS="" line in webui-user.sh on Linux and macOS.
--disable-nan-check only switches the check off. You'll get black images instead of an error, which is useful in a batch where one picture fails and you want the rest.
On AMD cards
The WebUI wiki's AMD guide says that for many AMD GPUs "you must add --precision full --no-half or --upcast-sampling arguments to avoid NaN errors or crashing." Issue #10296, from an RX 6800 XT owner on a fresh install, is a typical report. If --upcast-sampling works on your card, the wiki says it's about twice as fast as full precision.
The VAE version and the "all" that went away
For the VAE, recent versions don't stop at all by default. The setting "Automatically revert VAE to 32-bit floats" is on, so the WebUI prints "A tensor with all NaNs was produced in VAE", converts the VAE and retries. Some VAEs are fragile in half precision anyway; catboxanon wrote in #7633 that the NovelAI VAE "is very flaky in fp16, but that is due to the VAE itself, not the webui."
In June 2024 the check was made cheaper, and from v1.10.0 the message reads "A tensor with NaNs was produced in Unet." without "all". It's the same error. Forge, the fork by lllyasviel, has the function but it does nothing, so Forge users won't see this exception.
Other lines the same feature prints
Match yours against these if the one at the top of the page is not quite it. They come from the same code and mean related things.
A tensor with all NaNs was produced in Unet.modules.devices.NansException: A tensor with all NaNs was produced in Unet. Use --disable-nan-check commandline argument to disable this check.NansException: A tensor with all NaNs was produced in VAE.A tensor with NaNs was produced in Unet.A tensor with NaNs was produced in VAE.