ComfyUI icon indicating copy to clipboard operation
ComfyUI copied to clipboard

Latent upscale causes black image on some resolutions

Open saltacc opened this issue 3 years ago • 18 comments

Using a base resolution of 576x960, going with ~1.5x latent upscale (to 896x1472) is possible image However, trying to do ~2x latent upscale (1152x1920) just causes a black image to be output by the upscaler image Here is my pip freeze https://pastebin.com/kZvQpFYH I'm using a 4090 wth a Ryzen 7 5800x with 40gb of ram. I'm not running out of vram or ram either.

saltacc avatar Apr 04 '23 18:04 saltacc

Is this a one off bug or something you are constantly able to reproduce even after restarting the backend?

comfyanonymous avatar Apr 04 '23 19:04 comfyanonymous

It is consistent, I haven't been able to do certain resolutions since I installed it. It seems to be about image area rather than any specific resolution (maybe somehow related to a pillow decompression bomb protection?)

saltacc avatar Apr 04 '23 21:04 saltacc

I can confirm that I'm getting this issue as well with a 4090. At first I thought it was specific VAE causing it, but after seeing this it's actually changing resolutions that is producing this issue, similar to what sALTaccount said.

erikmackinnon avatar Apr 04 '23 22:04 erikmackinnon

Can you test if the VAEDecodeTiled node in the _for_testing also gives you black images so that I can know if the problem is because of the VAE decoding or because of something else.

comfyanonymous avatar Apr 04 '23 22:04 comfyanonymous

image yup it does appear to be VAE related, tiled VAE works just fine image no vram spikes or anything though and no error messages

saltacc avatar Apr 05 '23 00:04 saltacc

Black images from decoding is usually actually because VRAM hit a limit and the tensor zeroed out. This is a problem with diffusers, a1111, etc,

WASasquatch avatar Apr 05 '23 00:04 WASasquatch

This is a problem related to xformers 0.0.18, downgrading to 0.0.17 will fix it. I have filed an issue with xformers so they can fix it: https://github.com/facebookresearch/xformers/issues/719

comfyanonymous avatar Apr 05 '23 01:04 comfyanonymous

Damn, was trying to avoid having to compile xformers for the 5483th time 😢 thanks for looking into this. I'll close the issue as its upstream

saltacc avatar Apr 05 '23 01:04 saltacc

Although maybe a warning should be added if xformers 0.0.18 is detected 🤔 . I also think I remember seeing something like this before with auto and it was solved by upcasting attention to fp32 (i think?), when I'm home i'll experiment with it

saltacc avatar Apr 05 '23 01:04 saltacc

ComfyUI runs the VAE in full precision. I just disabled xformers in the VAE for 0.0.18 so it will use the split optimization instead which is slower but will actually work. https://github.com/comfyanonymous/ComfyUI/commit/e46b1c3034a23eeb048e279d0d285737d39a4b1a

comfyanonymous avatar Apr 05 '23 03:04 comfyanonymous

FYI, I don't use xformers in WebUI, or Diffusers, and it still happens if VRAM hits the ceiling. I do use xformers in comfyui though as I try to keep settings absolutely vanilla while developing.

WASasquatch avatar Apr 05 '23 03:04 WASasquatch

I'm getting this issue on the latest commit, which is f84f250

image

oakif avatar Apr 06 '23 21:04 oakif

How did you install comfyUI and which xformers version do you have exactly?

comfyanonymous avatar Apr 06 '23 21:04 comfyanonymous

I used git clone on the repo in WSL, installed the requirements using pip install -r requirements, and am running it using python main.py. According to A1111 WebUI, I'm using xformers 0.0.14.dev

oakif avatar Apr 06 '23 21:04 oakif

I used git clone on the repo in WSL, installed the requirements using pip install -r requirements, and am running it using python main.py. According to A1111 WebUI, I'm using xformers 0.0.14.dev

Are you running within WebUI? WebUI holds on to models and other stuff into VRAM which leaves very little for ComfyUI. I actually haven't used A1111 except to train, cause I can make significantly larger images in ComfyUI due to much better memory management.

WASasquatch avatar Apr 06 '23 23:04 WASasquatch

I used git clone on the repo in WSL, installed the requirements using pip install -r requirements, and am running it using python main.py. According to A1111 WebUI, I'm using xformers 0.0.14.dev

Are you running within WebUI? WebUI holds on to models and other stuff into VRAM which leaves very little for ComfyUI. I actually haven't used A1111 except to train, cause I can make significantly larger images in ComfyUI due to much better memory management.

I'm not exactly sure, but I'm running ComfyUI separately from WebUI

oakif avatar Apr 09 '23 05:04 oakif

Installing xformers 0.0.17 solved black images issue for me.

ComfyUI and A1111 probably use different Python environment, so the version info from A1111 is unreliable.

To know which version of xformers you have, go to where you deployed ComfyUI and look into the folder python_embeded\Lib\site-packages\. If there's a folder named xformers-0.0.18.dist-info, then you have xformers 0.0.18 installed.

To downgrade to xformers 0.0.17, open a command prompt where you deploy ComfyUI and run this

python_embeded\python.exe -s -m pip install xformers==0.0.17

This should uninstall whichever xformers you have and install 0.0.17.

Obviously this is for Windows, but if you're using Linux, chances are you already know what to do already.

justanothernguyen avatar Apr 09 '23 10:04 justanothernguyen

The latest ComfyUI prints your xformers version on startup along with a warning if it's 0.0.18

comfyanonymous avatar Apr 09 '23 15:04 comfyanonymous