lkwq007/stablediffusion-infinity

Documented issues from troubleshooting on Windows

Kim2091 opened this issue ยท 16 comments

I helped 4 separate people in the last 5 hours set this software up on Windows, here's what issues I've run into and the solutions. I apologize for this being condensed into a single issue, but I'm low on time:

Problem 1: Tokens
Many people have been having issues using huggingface cli login to register their token for usage with this software. The workaround to this is to use use_auth_token='tokenvalue' (where tokenvalue is the token) rather than use_auth_token=True. This shouldn't be the default, but it should be documented as a potential workaround.

Problem 2: AttributeError: module 'PIL.Image' has no attribute 'Resampling'
This issue only occurred for one person. No amount of re-running existing cells fixes it, and all dependencies are installed.

Problem 3: OSError: Windows requires Developer Mode to be activated, or to run Python as an administrator, in order to create symlinks.
This doesn't seem to be an issue with this software as much as it is with permissions in general, but it's still an issue that's odd. It didn't occur for 3 out of the 4 people I was helping. The person who ran into this issue had an administrator account, and was running it under the same conditions as the other users. Developer mode did fix it.

Problem 4: OpenCV
Installing opencv with conda seems to prevent errors with patch_match. This is the command I've been recommending and it has successfully prevented it: conda install -c conda-forge opencv.

Concerns:
No such comm target registered: jupyter.widget.control
Full error:

[IPKernelApp] ERROR | No such comm target registered: jupyter.widget.control
[IPKernelApp] WARNING | No such comm: a5f38cb6-3d6d-46b5-8493-fea3b4bc45fb

There's no clear reason as to why this appears, but it shows up in the log. Functionality does not appear to be inhibited.

If it helps anyone else, I was able to successfully install and run on Windows 11 using an Anaconda Powershell Prompt terminal. My workflow was:

Environment Windows 11, Anaconda, RTX 3060

conda create -n sd-inf python=3.10
conda activate sd-inf
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
conda install scipy
conda install -c conda-forge jupyterlab
conda install -c conda-forge ipywidgets==7.7.1 # Note use of double equal signs
conda install -c conda-forge ipycanvas
conda install -c conda-forge diffusers transformers ftfy
pip install opencv-contrib-python # I used this version of opencv
pip install markupsafe==2.0.1 # this was response to ImportError: cannot import name 'soft_unicode' from 'markupsafe'

you must enable developer mode on Windows https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development

3/4 people I helped did not require developer mode, which is quite odd. (I didn't require it either). I'm unsure why this is so inconsistent, which is why I left it in my original post.

After following all of the instructions, I still get the error:


 ---------------------------------------------------------------------------
 ImportError                               Traceback (most recent call last)
 Cell In [1], line 6
       3 from ipycanvas import Canvas, hold_canvas, MultiCanvas
       4 import ipywidgets as widgets
 ----> 6 from utils import *
       7 from canvas import InfCanvas
 
 File ~\stablediffusion-infinity\utils.py:3
       1 from PIL import Image
       2 from PIL import ImageFilter
 ----> 3 import cv2
       4 import numpy as np
       5 import scipy
 
 ImportError: DLL load failed while importing cv2: The specified module could not be found.

That also results in the error in the next cell:

ImportError                               Traceback (most recent call last)
Cell In [6], line 4
      2 import torch
      3 from torch import autocast
----> 4 from diffusers import StableDiffusionPipeline, StableDiffusionInpaintPipeline

File ~\Anaconda3\envs\sd-inf\lib\site-packages\diffusers\__init__.py:12
      1 from .utils import (
      2     is_inflect_available,
      3     is_onnx_available,
   (...)
      6     is_unidecode_available,
      7 )
     10 __version__ = "0.3.0"
---> 12 from .configuration_utils import ConfigMixin
     13 from .modeling_utils import ModelMixin
     14 from .models import AutoencoderKL, UNet2DConditionModel, UNet2DModel, VQModel

File ~\Anaconda3\envs\sd-inf\lib\site-packages\diffusers\configuration_utils.py:25
     22 from collections import OrderedDict
     23 from typing import Any, Dict, Tuple, Union
---> 25 from huggingface_hub import hf_hub_download
     26 from huggingface_hub.utils import EntryNotFoundError, RepositoryNotFoundError, RevisionNotFoundError
     27 from requests import HTTPError

ImportError: cannot import name 'hf_hub_download' from 'huggingface_hub' (C:\Users\vaspu\Anaconda3\envs\sd-inf\lib\site-packages\huggingface_hub\__init__.py)

For windows even after reinstalling using only the conda command for opencv I'm still getting patch_match compiling failed
image

Sadly I'm not sure what's causing your guys' issues here. I had a fairly small sample set of users and I myself didn't run into these (that weren't fixed by my solutions posted above).

Well luckily it worked despite the error message...

workaround to this is to use use_auth_token='tokenvalue'

where do i put use_auth_token='tokenvalue'?

i put it in huggingface-cli launch parameter and it says incorrect parameter

EDIT:
found it. insert it in the IPNYB

got this error on windows. ive tried pip install infcanvas and theres no infcanvas

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In [1], line 7
      4 import ipywidgets as widgets
      6 from utils import *
----> 7 from canvas import InfCanvas

ImportError: cannot import name 'InfCanvas' from 'canvas' (B:\tools\anaconda3\envs\sd-inf\lib\site-packages\canvas\__init__.py)

I have a hunch that the patch_match issue and it only affecting some users is due to some using WSL and others running directly off of windows.
I believe the library needs to be compiled on linux/WSL

I have a hunch that the patch_match issue and it only affecting some users is due to some using WSL and others running directly off of windows.
I believe the library needs to be compiled on linux/WSL

That's possible. It's worth noting that of myself and the 4 others, none were running WSL.

First I get the:
patch_match compiling failed

Then I get the:
OSError: You specified use_auth_token=True, but a Hugging Face token was not found.

I have tried False, that didn't work. Obviously

I have tried True, that didn't work. I only get this then:
OSError: You specified use_auth_token=True, but a Hugging Face token was not found.

I have tried with my generated token from Huggingface, that didn't work. I only get this then:
NameError: name 'MY_HUGGINGFACE_TOKEN_HERE' is not defined

I have tried Huggingface-cli login, but I get no visible(?) keyboard input where I should type the token and can't paste it.

I'm out of ideas :(

This is the complete container:

OSError Traceback (most recent call last)
Cell In [3], line 1
----> 1 text2img = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", revision="fp16", torch_dtype=torch.float16, use_auth_token=True).to("cuda")
2 inpaint=StableDiffusionInpaintPipeline(
3 vae=text2img.vae,
4 text_encoder=text2img.text_encoder,
(...)
9 feature_extractor=text2img.feature_extractor
10 ).to("cuda")

File ~\anaconda3\envs\sd-inf\lib\site-packages\diffusers\pipeline_utils.py:288, in DiffusionPipeline.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
285 # 1. Download the checkpoints and configs
286 # use snapshot download here to get it working from from_pretrained
287 if not os.path.isdir(pretrained_model_name_or_path):
--> 288 cached_folder = snapshot_download(
289 pretrained_model_name_or_path,
290 cache_dir=cache_dir,
291 resume_download=resume_download,
292 proxies=proxies,
293 local_files_only=local_files_only,
294 use_auth_token=use_auth_token,
295 revision=revision,
296 )
297 else:
298 cached_folder = pretrained_model_name_or_path

File ~\anaconda3\envs\sd-inf\lib\site-packages\huggingface_hub\utils_deprecation.py:93, in _deprecate_arguments.._inner_deprecate_positional_args..inner_f(*args, **kwargs)
91 message += "\n\n" + custom_message
92 warnings.warn(message, FutureWarning)
---> 93 return f(*args, **kwargs)

File ~\anaconda3\envs\sd-inf\lib\site-packages\huggingface_hub_snapshot_download.py:115, in snapshot_download(repo_id, revision, repo_type, cache_dir, library_name, library_version, user_agent, proxies, etag_timeout, resume_download, use_auth_token, local_files_only, allow_regex, ignore_regex, allow_patterns, ignore_patterns)
113 token = HfFolder.get_token()
114 if token is None:
--> 115 raise EnvironmentError(
116 "You specified use_auth_token=True, but a Hugging Face token was not"
117 " found."
118 )
119 else:
120 token = None

OSError: You specified use_auth_token=True, but a Hugging Face token was not found.

Problem 1: Tokens
Many people have been having issues using huggingface cli login to register their token for usage with this software. The workaround to this is to use use_auth_token='tokenvalue' (where tokenvalue is the token) rather than use_auth_token=True. This shouldn't be the default, but it should be documented as a potential workaround.

The solution for me was to not use CTRL+V to paste the token. If using VScode, use CTRL+SHIFT+V, if using cmd/powershell outside of VScode, just right-click in the terminal to paste.

i keep running into this issue when uploading a photo not sure what it means

AttributeError Traceback (most recent call last)
Cell In [21], line 14, in start_func(btn)
12 uploader_output.clear_output()
13 if len(uploader.value)>0:
---> 14 keys=list(uploader.value.keys())
15 val=uploader.value[keys[-1]]["content"]
16 pil=Image.open(io.BytesIO(val))

AttributeError: 'tuple' object has no attribute 'keys'

I ran everything but when trying to run
python app.py
y get
python: can't open file 'C:\Windows\system32\app.py': [Errno 2] No such file or directory

Anyone can help me understand what im missing? thanks!

My installation experience on Windows had some bumps along the way:

  • The infinity repo needs to be cloned - that is presumably so obvious that it isn't mentioned in the setup instructions. So remember to git clone git@github.com:lkwq007/stablediffusion-infinity.git.
  • Pytorch ran off CPU only not GPU (cuda) so I changed the pytorch installation line to conda install pytorch torchvision torchaudio cudatoolkit -c pytorch -c nvidia -c conda-forge which fixed it. See #123 (comment)
  • When I hit the setup button in the UI, models wern't downloading from HuggingFace so I generated a token from https://huggingface.co/settings/tokens but didn't know where to put it. Turns out you can paste it into UI into the huggingface area I think, though I put it into a file called .token in the root of the project.
  • run python app.py --debug to run on port 0.0.0.0 thus allowing other computers on your network to access the UI e.g. via http://192.168.0.188:7860/.

Some of this information should potentially be in the setup instructions, to help others.

Unresolved:

  • The setup button appears and models seem to re-download every time - many gigs of downloads. I think there is a cache (see #130) in C:\Users\USERNAME\.cache\huggingface perhaps, but its not working for me. If I start this app, the same parameters, each time I still get the setup button and the need to download gigs of models again.
  • You can apparetntly specify a local model with e.g. python app.py --local_model "C:\blah\sd-v1-5-inpainting.ckpt" but this also isn't working for me - I still get the big setup button each time. As there are so many models (regular, inpainting etc) this needs to be documented better for newbies to all this like me, despite the https://github.com/lkwq007/stablediffusion-infinity/blob/master/docs/usage.md document.

Startup command:

It would be nice to provide a startup command batch file so that an alias to that batch file can be placed on the desktop and a single double click would launch the infinity app. Here is my attempt:

set "PATH=%PATH%C:\Users\YOURPATHTO\Anaconda3\condabin;C:\Users\YOURPATHTO\Anaconda3\Library\bin;"
call conda activate sd-inf
python app.py --debug --local_model "C:\stable-diffusion-webui\models\Stable-diffusion\sd-v1-5-inpainting.ckpt"
echo view at http://192.168.0.188/7860
pause

I agree that it would be helpful to point out the need to git clone the repository - I was about to give up on getting this working until I found this thread.