Closed vict0rsch closed 2 years ago
Running the Stable Diffusion in-painting example, I got an inheritance error
RuntimeError: @register_for_config was applied to UNet2DConditionModel init method, but this class does not inherit from ConfigMixin.
@register_for_config
ConfigMixin
Code
import PIL import requests import torch from io import BytesIO from pathlib import Path from diffusers import StableDiffusionInpaintPipeline def download_image(url): response = requests.get(url) return PIL.Image.open(BytesIO(response.content)).convert("RGB") token = Path("~/.huggingface/token").expanduser().read_text().strip() img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png" mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png" init_image = download_image(img_url).resize((512, 512)) mask_image = download_image(mask_url).resize((512, 512)) pipe = StableDiffusionInpaintPipeline.from_pretrained( "runwayml/stable-diffusion-inpainting", revision="fp16", torch_dtype=torch.float16, use_auth_token=token, ) pipe = pipe.to("cuda") prompt = "Face of a yellow cat, high resolution, sitting on a park bench" image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[0] image.save("out.png")
Env:
$ pip freeze addict==2.4.0 aiohttp==3.8.3 aiosignal==1.2.0 anyio==3.6.2 appnope==0.1.3 APScheduler==3.7.0 asttokens==2.0.8 async-timeout==4.0.2 attrs==21.2.0 backcall==0.2.0 bcrypt==4.0.1 black==22.10.0 Brotli==1.0.9 certifi==2021.5.30 cffi==1.15.1 charset-normalizer==2.0.4 click==8.0.1 codecarbon==1.2.0 comet-ml==3.15.3 commonmark==0.9.1 configobj==5.0.6 contourpy==1.0.5 cryptography==38.0.1 cycler==0.10.0 dash==2.0.0 dash-bootstrap-components==0.13.0 dash-core-components==2.0.0 dash-html-components==2.0.0 dash-table==5.0.0 dataclasses==0.6 decorator==5.0.9 diffusers==0.6.0 dulwich==0.20.25 everett==2.0.1 executing==1.1.1 fastapi==0.85.1 ffmpy==0.3.0 filelock==3.0.12 fire==0.4.0 flake8==5.0.4 Flask==2.0.1 Flask-Compress==1.10.1 fonttools==4.38.0 frozenlist==1.3.1 fsspec==2022.10.0 future==0.18.2 gdown==3.13.0 googlemaps==4.6.0 gradio==3.6 h11==0.12.0 httpcore==0.15.0 httpx==0.23.0 huggingface-hub==0.10.1 hydra-core==0.11.3 idna==3.2 imageio==2.9.0 importlib-metadata==5.0.0 ipython==7.27.0 itsdangerous==2.0.1 jedi==0.18.0 Jinja2==3.0.1 joblib==1.0.1 jsonschema==3.2.0 kiwisolver==1.3.2 kornia==0.5.10 linkify-it-py==1.0.3 markdown-it-py==2.1.0 MarkupSafe==2.0.1 matplotlib==3.4.3 matplotlib-inline==0.1.2 mccabe==0.7.0 mdit-py-plugins==0.3.1 mdurl==0.1.2 minydra==0.1.6 multidict==6.0.2 mypy-extensions==0.4.3 networkx==2.6.2 numpy==1.21.2 nvidia-ml-py3==7.352.0 omegaconf==1.4.1 opencv-python==4.5.3.56 orjson==3.8.0 packaging==21.0 pandas==1.3.2 paramiko==2.11.0 parso==0.8.2 pathspec==0.10.1 pexpect==4.8.0 pickleshare==0.7.5 Pillow==8.3.2 platformdirs==2.5.2 plotly==5.3.1 prompt-toolkit==3.0.20 ptyprocess==0.7.0 pure-eval==0.2.2 py-cpuinfo==8.0.0 pycodestyle==2.9.1 pycparser==2.21 pycryptodome==3.15.0 pydantic==1.10.2 pydub==0.25.1 pyflakes==2.5.0 Pygments==2.10.0 PyNaCl==1.5.0 pynvml==11.0.0 pyparsing==2.4.7 pyrsistent==0.18.0 PySocks==1.7.1 python-dateutil==2.8.2 python-multipart==0.0.5 pytorch-ranger==0.1.1 pytz==2021.1 PyWavelets==1.1.1 PyYAML==5.4.1 regex==2022.9.13 requests==2.26.0 requests-toolbelt==0.9.1 rfc3986==1.5.0 rich==12.6.0 scikit-image==0.18.3 scikit-learn==0.24.2 scipy==1.7.1 seaborn==0.11.2 semantic-version==2.8.5 six==1.16.0 sniffio==1.3.0 stack-data==0.5.1 starlette==0.20.4 tenacity==8.0.1 termcolor==1.1.0 threadpoolctl==2.2.0 tifffile==2021.8.30 tokenizers==0.13.1 tomli==2.0.1 torch==1.7.1 torch-optimizer==0.1.0 torchvision==0.8.2 tqdm==4.62.2 traitlets==5.1.0 transformers==4.23.1 typing_extensions==4.4.0 tzlocal==2.1 uc-micro-py==1.0.1 urllib3==1.26.6 uvicorn==0.19.0 wcwidth==0.2.5 websocket-client==1.2.1 websockets==10.3 Werkzeug==2.0.1 wrapt==1.12.1 wurlitzer==3.0.2 yarl==1.8.1 zipp==3.10.0
In [6]: run diffuse.py Downloading: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 550/550 [00:00<00:00, 555kB/s] Downloading: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 342/342 [00:00<00:00, 591kB/s] Downloading: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 4.75k/4.75k [00:00<00:00, 4.50MB/s] Downloading: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 608M/608M [00:12<00:00, 48.9MB/s] Downloading: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 287/287 [00:00<00:00, 302kB/s] Downloading: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 635/635 [00:00<00:00, 652kB/s] Downloading: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 246M/246M [00:03<00:00, 79.0MB/s] Downloading: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 525k/525k [00:00<00:00, 2.53MB/s] Downloading: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 472/472 [00:00<00:00, 486kB/s] Downloading: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 821/821 [00:00<00:00, 1.14MB/s] Downloading: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 1.06M/1.06M [00:00<00:00, 3.39MB/s] Downloading: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 810/810 [00:00<00:00, 1.29MB/s] Downloading: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 1.72G/1.72G [00:22<00:00, 75.5MB/s] Downloading: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 613/613 [00:00<00:00, 542kB/s] Downloading: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 167M/167M [00:04<00:00, 39.2MB/s] Fetching 15 files: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 15/15 [00:53<00:00, 3.60s/it] --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) ~/ccai/github/hf-spaces-climategan/diffuse.py in <module> 20 mask_image = download_image(mask_url).resize((512, 512)) 21 ---> 22 pipe = StableDiffusionInpaintPipeline.from_pretrained( 23 "runwayml/stable-diffusion-inpainting", 24 revision="fp16", /network/scratch/s/conda/climateganenv/lib/python3.9/site-packages/diffusers/pipeline_utils.py in from_pretrained(cls, pretrained_model_name_or_path, **kwargs) 540 # check if the module is in a subdirectory 541 if os.path.isdir(os.path.join(cached_folder, name)): --> 542 loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwargs) 543 else: 544 # else load from the root directory /network/scratch/s/conda/climateganenv/lib/python3.9/site-packages/diffusers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, **kwargs) 410 } 411 else: --> 412 model, unused_kwargs = cls.from_config( 413 config_path, 414 cache_dir=cache_dir, /network/scratch/s/conda/climateganenv/lib/python3.9/site-packages/diffusers/configuration_utils.py in from_config(cls, pretrained_model_name_or_path, return_unused_kwargs, **kwargs) 167 168 # Return model and optionally state and/or unused_kwargs --> 169 model = cls(**init_dict) 170 return_tuple = (model,) 171 /network/scratch/s/conda/climateganenv/lib/python3.9/site-packages/diffusers/configuration_utils.py in inner_init(self, *args, **kwargs) 407 if not isinstance(self, ConfigMixin): 408 raise RuntimeError( --> 409 f"`@register_for_config` was applied to {self.__class__.__name__} init method, but this class does " 410 "not inherit from `ConfigMixin`." 411 ) RuntimeError: `@register_for_config` was applied to UNet2DConditionModel init method, but this class does not inherit from `ConfigMixin`.
diffusers
Re-running the exact same code actually yields no error...
Hmm weird, I sadly couldn't reproduce it either
Describe the bug
Running the Stable Diffusion in-painting example, I got an inheritance error
Reproduction
Code
Env:
Logs
System Info
diffusers
version: 0.6.0