stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

[Bug]: NansException: A tensor with all NaNs was produced in VAE on some images in img2img

Open DenkingOfficial opened this issue 2 years ago • 75 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits

What happened?

For this input image in img2img it throws a error:

1654158956_1-phonoteka-org-p-lena-beskonechnoe-leto-oboi-krasivo-1

modules.devices.NansException: A tensor with all 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. Use --disable-nan-check commandline argument to disable this check.

I tried to use both of these flags and other models, but it just returns a black image

BUT

If I use the same settings with another picture it works perfectly fine

Input image:

alisa2

Output image:

20221015237114-1971815762-1girl, small camp house, forest, tie, hand on hip, looking at viewer, moon, nature, navel, night, night sky, orange eyes, orange

Steps to reproduce the problem

  1. Go to img2img
  2. Upload image proided above
  3. Set those settings:

image

  1. Press generate
  2. See an error:

image

What should have happened?

It should work with this picture

Commit where the problem happens

ea9bd9fc7409109adcd61b897abc2c8881161256

What platforms do you use to access the UI ?

Windows

What browsers do you use to access the UI ?

Google Chrome

Command Line Arguments

--listen --medvram --opt-split-attention

List of extensions

image

Console logs

`Traceback (most recent call last):
  File "C:\Software\Other Software\sdautomatic111\modules\call_queue.py", line 56, in f
    res = list(func(*args, **kwargs))
  File "C:\Software\Other Software\sdautomatic111\modules\call_queue.py", line 37, in f
    res = func(*args, **kwargs)
  File "C:\Software\Other Software\sdautomatic111\modules\img2img.py", line 169, in img2img
    processed = process_images(p)
  File "C:\Software\Other Software\sdautomatic111\modules\processing.py", line 486, in process_images
    res = process_images_inner(p)
  File "C:\Software\Other Software\sdautomatic111\modules\processing.py", line 632, in process_images_inner
    devices.test_for_nans(x, "vae")
  File "C:\Software\Other Software\sdautomatic111\modules\devices.py", line 152, in test_for_nans
    raise NansException(message)
modules.devices.NansException: A tensor with all 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. Use --disable-nan-check commandline argument to disable this check.`

Additional information

No response

DenkingOfficial avatar Feb 07 '23 23:02 DenkingOfficial

I live also same problem. :(

SirArcherAllone avatar Feb 08 '23 08:02 SirArcherAllone

Same issue Feelsbadman

Tybost avatar Feb 09 '23 08:02 Tybost

try —no-half-vae

Sanster avatar Feb 10 '23 00:02 Sanster

try —no-half-vae

I wrote that I already tried --disable-nan-check and --no-half-vae

DenkingOfficial avatar Feb 10 '23 06:02 DenkingOfficial

It was solved for me in the following way: 1- Edit with Notepad++ or notepad the webui-user.bat file 2- copy and paste the following: set PYTHON="here you must put the path of the python executable with the quotes" setGIT= set VENV_DIR= set COMMANDLINE_ARGS=--xformers git pull call webui.bat 3- save all

Gingoold avatar Feb 18 '23 19:02 Gingoold

It was solved for me in the following way: 1- Edit with Notepad++ or notepad the webui-user.bat file 2- copy and paste the following: set PYTHON="here you must put the path of the python executable with the quotes" setGIT= set VENV_DIR= set COMMANDLINE_ARGS=--xformers git pull call webui.bat 3- save all

Thank you ! its works for me !

NJCCJohnWatson avatar Feb 20 '23 13:02 NJCCJohnWatson

I have setted "--xformers" but when it start to tain it still raise this error. 6GB3060

ShakeWeLy avatar Feb 22 '23 09:02 ShakeWeLy

doesn't work for me

raptozia avatar Feb 24 '23 11:02 raptozia

right-click the webui-user.bat file, then click edit, find "set COMMANDLINE_ARGS="--no-half-vae" I don't know why this error appears, I had it too, this fixed it

dsantiagot01 avatar Feb 24 '23 22:02 dsantiagot01

right-click the webui-user.bat file, then click edit, find "set COMMANDLINE_ARGS="--no-half-vae"

I wrote that I tried to use both "--no-half-vae" and "--disable-nan-check"

Quote from issue description:

I tried to use both of these flags and other models, but it just returns a black image

DenkingOfficial avatar Feb 25 '23 13:02 DenkingOfficial

hello, I know it has nothing to do with anything but I would like to ask you something. What props or how to make it so that it doesn't modify the composition of the image? I want to achieve an anime effect like the one you achieved in the second picture. sorry for the question and I hope you can solve the problem soon.

wildeakira avatar Feb 27 '23 04:02 wildeakira

hello, I know it has nothing to do with anything but I would like to ask you something. What props or how to make it so that it doesn't modify the composition of the image? I want to achieve an anime effect like the one you achieved in the second picture. sorry for the question and I hope you can solve the problem soon.

I used img2img with low denoising strength (0.15-0.3)

DenkingOfficial avatar Feb 27 '23 15:02 DenkingOfficial

make sure ur size is 512 x 512 or Multiple of 512

nccncourage avatar Mar 09 '23 23:03 nccncourage

For me the error message told me to use "set COMMANDLINE_ARGS="--no-half"" and this worked.

S1lander avatar Mar 10 '23 21:03 S1lander

Anyone who has still this error? I've noticed it only gives me the error when using Anime VAEs, like Orangemix or anything vae, while it never gives me the error when I use the Stability AI one (MSE one). Tried using no half vae argument but then I have problems with CUDA Memory because I only have 8 gbs of Vram. The --disable-nan-check works but the error doesn't disappear, simply it gives me black images sometimes. If anyone has some solutions please help. Is there maybe a way to fix VAEs?

NathanSamurai avatar Mar 22 '23 13:03 NathanSamurai

What's the python executable?

here you must put the path of the python executable with the quotes"

JL17779 avatar Mar 23 '23 06:03 JL17779

See https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Troubleshooting Issue was solved for me by using the command line arguments --precision full --no-half

maxuglov169 avatar Mar 23 '23 09:03 maxuglov169

It was solved for me in the following way: 1- Edit with Notepad++ or notepad the webui-user.bat file 2- copy and paste the following: set PYTHON="here you must put the path of the python executable with the quotes" setGIT= set VENV_DIR= set COMMANDLINE_ARGS=--xformers git pull call webui.bat 3- save all

I have the exact same except no quotes (path has no spaces) This can't be the issue

Askelhardd avatar Mar 24 '23 03:03 Askelhardd

make sure ur size is 512 x 512 or Multiple of 512

I have this issue with a generated image of 768x768, but no issue with a 512x512. No other way ? this seems strange

Askelhardd avatar Mar 24 '23 03:03 Askelhardd

I started to have this problem with "revAnimated_v121.safetensors [f57b21e57b]" model with an especific image too. I change the model to finish my work to "dreamshaper_4BakedVae.safetensors". Today i tested my problematic image and no erros yet. So i tested the file from original author post (BTW my card is a 4GB ram so can set the tested resolution) But have no problems so far. Lots of uspscale and inpaints. The image below was maded with revAnimated_v121.safetensors [f57b21e57b]. test-00173-1254744345

MrDo1965 avatar Apr 15 '23 21:04 MrDo1965

seems to be an issue when i use RevAnimated v121. other chkpts seem ok.

vitalbuttering avatar Apr 19 '23 14:04 vitalbuttering

I am getting this on the dreamlike diffusion model.

darrenf666 avatar Apr 20 '23 17:04 darrenf666

right-click the webui-user.bat file, then click edit, find "set COMMANDLINE_ARGS="--no-half-vae"

I wrote that I tried to use both "--no-half-vae" and "--disable-nan-check"

Quote from issue description:

I tried to use both of these flags and other models, but it just returns a black image

Same here, did you figure it out?

lolpopkk avatar Apr 21 '23 05:04 lolpopkk

it happens to me in txt2img when using lora or locon without vae, except it looks good in preview until the last step then it it one colour

captainzero93 avatar Apr 26 '23 03:04 captainzero93

Settings - Stable Diffusion - SD VAE - Automatic

helped me

VoidTerror avatar Apr 26 '23 19:04 VoidTerror

What will --no-half-vae do to my image? Will I get lower quality images if I add it to COMMANDLINE_ARGS?

spc11400 avatar May 07 '23 05:05 spc11400

same issue to me, in img2img tab, with multi params xyz plots

XatMassacrE avatar May 09 '23 19:05 XatMassacrE

I suggest you try adding the command line argument --no-half (additional to --no-half-vae ) and remove --disable-nan-check

From the error I encountered I gathered this could relate to "your video card does not support half type" It might be the case that you originaly encountered: "A tensor with all NaNs was produced in VAE" When adding the commandline argument --no-half-vae you might have fixed your original issue. Ultimatly you then ran into the error I ran into: "A tensor with all NaNs was produced in Unet" --disable-nan-check discards the check if you get not a number errors. Therefore you no longer get any exceptions but a black image. I suspect, if you remove --disable-nan-check without adding --no-half, you encounter the error I ran into.

DavidJaeck avatar May 14 '23 22:05 DavidJaeck

What will --no-half-vae do to my image? Will I get lower quality images if I add it to COMMANDLINE_ARGS?

From what I was able to understand it shouldn't change a lot about the appearance of the images. The parameter appears to adjust the precision your graphics card does its computations with. Some cards appear to not support "half precision". Maybe this parameter impacts performance negatively tho

DavidJaeck avatar May 14 '23 22:05 DavidJaeck

What will --no-half-vae do to my image? Will I get lower quality images if I add it to COMMANDLINE_ARGS?

From what I was able to understand it shouldn't change a lot about the appearance of the images. The parameter appears to adjust the precision your graphics card does its computations with. Some cards appear to not support "half precision". Maybe this parameter impacts performance negatively tho

Based on my tests, it does impact performance. I added this to my command line arguments and it caused me to run out of vram much sooner when I started pushing up the parameters. Can't say if I noticed a clear speed difference or not. I'm definitely going to try and find another way around this error.

munkeyflying avatar May 18 '23 05:05 munkeyflying