Engineer-of-Stuff / stable-diffusion-paperspace

Jupyter notebooks for Paperspace.
The Unlicense
289 stars 110 forks source link

Enabling xformers will not create a hypernetwork #25

Closed tsukimiya closed 2 years ago

tsukimiya commented 2 years ago

Environment tested Free-A4000, Free-A5000, Free-A6000, Free-A100

Describe the bug Enabling xformers option. When I create a new hypernetwork and try to load it, I get an error.

Error loading hypernetwork /notebooks/stable-diffusion-webui/models/hypernetworks/hn_error.pt
Traceback (most recent call last):
  File "/notebooks/stable-diffusion-webui/modules/hypernetworks/hypernetwork.py", line 294, in load_hypernetwork
    shared.loaded_hypernetwork.load(path)
  File "/notebooks/stable-diffusion-webui/modules/hypernetworks/hypernetwork.py", line 231, in load
    self.layer_structure = state_dict.get('layer_structure', [1, 2, 1])
AttributeError: 'NoneType' object has no attribute 'get'

This problem seems to be caused by installing CUDA 11.3 and torch 1.13.0. It seems to work if I enable the disable_pickle_check option, is this the correct state?

Cyberes commented 2 years ago

The webui's pickle check is pretty pointless since it only checks for unexpected keys and folders. I always leave it disabled. I'd open a bug report with them or just don't worry about it if it works now.

tsukimiya commented 2 years ago

I see. I tried to create and learn hypernetwork with the disable_pickie_check option enabled, but I got the following error.

Traceback (most recent call last):
  File "/notebooks/stable-diffusion-webui/modules/ui.py", line 185, in f
    res = list(func(*args, **kwargs))
  File "/notebooks/stable-diffusion-webui/webui.py", line 56, in f
    res = func(*args, **kwargs)
  File "/notebooks/stable-diffusion-webui/modules/hypernetworks/ui.py", line 54, in train_hypernetwork
    hypernetwork, filename = modules.hypernetworks.hypernetwork.train_hypernetwork(*args)
  File "/notebooks/stable-diffusion-webui/modules/hypernetworks/hypernetwork.py", line 506, in train_hypernetwork
    loss = shared.sd_model(x, c)[0]
  File "/usr/local/lib/python3.9/dist-packages/torch/nn/modules/module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "/notebooks/stable-diffusion-webui/repositories/stable-diffusion/ldm/models/diffusion/ddpm.py", line 879, in forward
    return self.p_losses(x, c, t, *args, **kwargs)
  File "/notebooks/stable-diffusion-webui/repositories/stable-diffusion/ldm/models/diffusion/ddpm.py", line 1030, in p_losses
    logvar_t = self.logvar[t].to(self.device)
RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)

I still do not know where the cause is, but I am reporting it just in case.

Cyberes commented 2 years ago

Please update your notebook to the latest version. If the issue still remains try building xformers as per https://github.com/Engineer-of-Stuff/stable-diffusion-paperspace/issues/20#issuecomment-1303761574 and https://github.com/Cyberes/xformers-compiled/issues/5#issuecomment-1304850762

tsukimiya commented 2 years ago

notebook is the latest version. It didn't work.

Build xformers according to Cyberes/xformers-compiled#20(comment) and pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio --extra-index-url https://download.pytorch.org/whl/cu113 So far it appears to be working correctly.

Latest version notebook installs pytorch 1.13.0, so that may be the problem.

Cyberes commented 2 years ago

Thank @corytaitchison for that fix :)