윈디하나의 누리사랑방. 이런 저런 얘기

글쓴시간
분류 기술,IT/스테이블 디퓨전
Stable Diffusion - NaN 오류

SD 를 사용하다보면, 아래와 유사한 오류가 발생하면서 더이상 진행안되는 현상이 발생하곤 한다. 데이터 중에 NaN(Not a Number) 값이 있어 처리할 수 없다는 메시지다.

Traceback (most recent call last):
File "/home/windy/stable-diffusion-webui/modules/call_queue.py", line 56, in f
res = list(func(*args, **kwargs))
File "/home/windy/stable-diffusion-webui/modules/call_queue.py", line 37, in f
res = func(*args, **kwargs)
File "/home/windy/stable-diffusion-webui/modules/txt2img.py", line 56, in txt2img
processed = process_images(p)
File "/home/windy/stable-diffusion-webui/modules/processing.py", line 503, in process_images
res = process_images_inner(p)
File "/home/windy/stable-diffusion-webui/modules/processing.py", line 657, in process_images_inner
devices.test_for_nans(x, "vae")
File "/home/windy/stable-diffusion-webui/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.
컴퓨터로 부동소수점 연산하다보면 NaN 이 생길 수 있기 때문에 이부분에 대해서는 대책을 세워야 한다. SD에서는 아래와 같이 해보라고 한다.

--no-half-vae 옵션 사용
--disable-nan-check 옵션 사용
--xformers 옵션 사용

필자는 3가지 옵션을 다 해봤지만 그래도 간혹 나기는 한다. --no-half-vae 옵션이 가장 발생 빈도를 낮추는것 같다. --disable-nan-check 옵션 주면 그냥 검은색 이미지 생성하고 다음으로 넘어간다. 이 오류는 VAE 를 처리할 때 발생한다.