lshqqytiger / stable-diffusion-webui-amdgpu

Stable Diffusion web UI
GNU Affero General Public License v3.0
1.8k stars 186 forks source link

[Bug]: text_encoder_2 error when converting SDXL checkpoint with olive #274

Closed TheFatBastid closed 7 months ago

TheFatBastid commented 1 year ago

Is there an existing issue for this?

What happened?

I get the following when trying to convert an sdxl model using olive, regardless of what options are checked:

nloaded weights 0.0s. Error completing request Arguments: ('sd_xl_base_1.0.safetensors', '', 'vae', 'stable-diffusion-xl', 'stable-diffusion-xl', False, True, True, True, True, True, 'euler', True, 512, False, '', '', '') {} Traceback (most recent call last): File "C:\stable-diffusion-webui-directml\modules\call_queue.py", line 57, in f res = list(func(*args, *kwargs)) File "C:\stable-diffusion-webui-directml\modules\call_queue.py", line 36, in f res = func(args, **kwargs) File "C:\stable-diffusion-webui-directml\modules\sd_olive_ui.py", line 29, in optimize_from_ckpt pipeline = StableDiffusionPipeline.from_single_file(os.path.join(models_path, "Stable-diffusion", checkpoint), torch_dtype=torch.float32, requires_safety_checker=False, scheduler_type=scheduler_type) File "C:\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\loaders.py", line 1922, in from_single_file pipe = download_from_original_stable_diffusion_ckpt( File "C:\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\pipelines\stable_diffusion\convert_from_ckpt.py", line 1591, in download_from_original_stable_diffusion_ckpt pipe = pipeline_class( TypeError: StableDiffusionPipeline.init() got an unexpected keyword argument 'text_encoder_2'

image

Steps to reproduce the problem

  1. Start with set COMMANDLINE_ARGS= --onnx --backend directml
  2. Go to olive tab
  3. Name any sdxl checkpoint
  4. click convert

What should have happened?

Convert the model

Sysinfo

sysinfo-2023-09-14-03-00.txt

What browsers do you use to access the UI ?

Brave

Console logs

Creating venv in directory C:\stable-diffusion-webui-directml\venv using python "C:\Users\<username>\AppData\Local\Programs\Python\Python310\python.exe"
venv "C:\stable-diffusion-webui-directml\venv\Scripts\Python.exe"
fatal: No names found, cannot describe anything.
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Version: 1.6.0
Commit hash: e9afd9aed55da48dfc917753e2daa114a515a85b
Installing torch and torchvision
Collecting torch==2.0.0
  Using cached torch-2.0.0-cp310-cp310-win_amd64.whl (172.3 MB)
Collecting torchvision==0.15.1
  Using cached torchvision-0.15.1-cp310-cp310-win_amd64.whl (1.2 MB)
Collecting torch-directml
  Using cached torch_directml-0.2.0.dev230426-cp310-cp310-win_amd64.whl (8.2 MB)
Collecting sympy
  Using cached sympy-1.12-py3-none-any.whl (5.7 MB)
Collecting filelock
  Using cached filelock-3.12.4-py3-none-any.whl (11 kB)
Collecting networkx
  Using cached networkx-3.1-py3-none-any.whl (2.1 MB)
Collecting jinja2
  Using cached Jinja2-3.1.2-py3-none-any.whl (133 kB)
Collecting typing-extensions
  Using cached typing_extensions-4.7.1-py3-none-any.whl (33 kB)
Collecting requests
  Using cached requests-2.31.0-py3-none-any.whl (62 kB)
Collecting numpy
  Using cached numpy-1.25.2-cp310-cp310-win_amd64.whl (15.6 MB)
Collecting pillow!=8.3.*,>=5.3.0
  Using cached Pillow-10.0.0-cp310-cp310-win_amd64.whl (2.5 MB)
Collecting MarkupSafe>=2.0
  Using cached MarkupSafe-2.1.3-cp310-cp310-win_amd64.whl (17 kB)
Collecting urllib3<3,>=1.21.1
  Using cached urllib3-2.0.4-py3-none-any.whl (123 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2023.7.22-py3-none-any.whl (158 kB)
Collecting charset-normalizer<4,>=2
  Using cached charset_normalizer-3.2.0-cp310-cp310-win_amd64.whl (96 kB)
Collecting idna<4,>=2.5
  Using cached idna-3.4-py3-none-any.whl (61 kB)
Collecting mpmath>=0.19
  Using cached mpmath-1.3.0-py3-none-any.whl (536 kB)
Installing collected packages: mpmath, urllib3, typing-extensions, sympy, pillow, numpy, networkx, MarkupSafe, idna, filelock, charset-normalizer, certifi, requests, jinja2, torch, torchvision, torch-directml
Successfully installed MarkupSafe-2.1.3 certifi-2023.7.22 charset-normalizer-3.2.0 filelock-3.12.4 idna-3.4 jinja2-3.1.2 mpmath-1.3.0 networkx-3.1 numpy-1.25.2 pillow-10.0.0 requests-2.31.0 sympy-1.12 torch-2.0.0 torch-directml-0.2.0.dev230426 torchvision-0.15.1 typing-extensions-4.7.1 urllib3-2.0.4

[notice] A new release of pip available: 22.2.1 -> 23.2.1
[notice] To update, run: C:\stable-diffusion-webui-directml\venv\Scripts\python.exe -m pip install --upgrade pip
Installing clip
Installing open_clip
Cloning Stable Diffusion into C:\stable-diffusion-webui-directml\repositories\stable-diffusion-stability-ai...
Cloning into 'C:\stable-diffusion-webui-directml\repositories\stable-diffusion-stability-ai'...
remote: Enumerating objects: 574, done.
remote: Counting objects: 100% (328/328), done.
remote: Compressing objects: 100% (105/105), done.
Receiving objects: 100% (574/574), 73.44 MiB | 6.41 MiB/s, done.
remote: Total 574 (delta 252), reused 223 (delta 223), pack-reused 246
Resolving deltas: 100% (273/273), done.
Cloning Stable Diffusion XL into C:\stable-diffusion-webui-directml\repositories\generative-models...
Cloning into 'C:\stable-diffusion-webui-directml\repositories\generative-models'...
remote: Enumerating objects: 740, done.
remote: Counting objects: 100% (563/563), done.
remote: Compressing objects: 100% (284/284), done.
remote: Total 740 (delta 338), reused 426 (delta 265), pack-reused 177Receiving objects: 100% (740/740), 22.32 MiB | 7.08 MiB/s, done.

Resolving deltas: 100% (376/376), done.
Cloning K-diffusion into C:\stable-diffusion-webui-directml\repositories\k-diffusion...
Cloning into 'C:\stable-diffusion-webui-directml\repositories\k-diffusion'...
remote: Enumerating objects: 1036, done.
remote: Counting objects: 100% (1036/1036), done.
remote: Compressing objects: 100% (410/410), done.
remote: Total 1036 (delta 710), reused 928 (delta 619), pack-reused 0
Receiving objects: 100% (1036/1036), 200.26 KiB | 7.42 MiB/s, done.
Resolving deltas: 100% (710/710), done.
Cloning CodeFormer into C:\stable-diffusion-webui-directml\repositories\CodeFormer...
Cloning into 'C:\stable-diffusion-webui-directml\repositories\CodeFormer'...
remote: Enumerating objects: 594, done.
remote: Counting objects: 100% (245/245), done.
remote: Compressing objects: 100% (97/97), done.
remote: Total 594 (delta 175), reused 170 (delta 148), pack-reused 349
Receiving objects: 100% (594/594), 17.31 MiB | 10.73 MiB/s, done.
Resolving deltas: 100% (286/286), done.
Cloning BLIP into C:\stable-diffusion-webui-directml\repositories\BLIP...
Cloning into 'C:\stable-diffusion-webui-directml\repositories\BLIP'...
remote: Enumerating objects: 277, done.
remote: Counting objects: 100% (165/165), done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 277 (delta 137), reused 136 (delta 135), pack-reused 112Receiving objects: 100% (277/277), 5.29 MiB | 10.5Receiving objects: 100% (277/277), 7.03 MiB | 10.66 MiB/s, done.

Resolving deltas: 100% (152/152), done.
Installing requirements for CodeFormer
Installing requirements
Installing onnxruntime
Installing onnxruntime-directml
WARNING! Because Olive optimization does not support torch 2.0, some packages will be downgraded and it can occur version mismatches between packages. (Strongly recommend to create another virtual environment to run Olive)
Installing Olive
Launching Web UI with arguments: --onnx --backend directml
no module 'xformers'. Processing without...
No SDP backend available, likely because you are running in pytorch versions < 2.0. In fact, you are using PyTorch 1.13.1+cpu. You might want to consider upgrading.
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
==============================================================================
You are running torch 1.13.1+cpu.
The program is tested to work with torch 2.0.0.
To reinstall the desired version, run with commandline flag --reinstall-torch.
Beware that this will cause a lot of large files to be downloaded, as well as
there are reports of issues with training tab on the latest version.

Use --skip-version-check commandline argument to disable this check.
==============================================================================
loading stable diffusion model: FileNotFoundError
Traceback (most recent call last):
  File "C:\Users\<username>\AppData\Local\Programs\Python\Python310\lib\threading.py", line 973, in _bootstrap
    self._bootstrap_inner()
  File "C:\Users\<username>\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "C:\Users\<username>\AppData\Local\Programs\Python\Python310\lib\threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "C:\stable-diffusion-webui-directml\modules\initialize.py", line 147, in load_model
    shared.sd_model  # noqa: B018
  File "C:\stable-diffusion-webui-directml\modules\shared_items.py", line 110, in sd_model
    return modules.sd_models.model_data.get_sd_model()
  File "C:\stable-diffusion-webui-directml\modules\sd_models.py", line 523, in get_sd_model
    load_model()
  File "C:\stable-diffusion-webui-directml\modules\sd_models.py", line 614, in load_model
    checkpoint_info = checkpoint_info or select_checkpoint()
  File "C:\stable-diffusion-webui-directml\modules\sd_models.py", line 244, in select_checkpoint
    raise FileNotFoundError(error_message)
FileNotFoundError: No checkpoints found. When searching for checkpoints, looked at:
 - file C:\stable-diffusion-webui-directml\model.ckpt
 - directory C:\stable-diffusion-webui-directml\models\Stable-diffusionCan't run without a checkpoint. Find and place a .ckpt or .safetensors file into any of those locations.

Stable diffusion model failed to load
Applying attention optimization: InvokeAI... done.
C:\stable-diffusion-webui-directml\modules\ui.py:929: GradioDeprecationWarning: The `style` method is deprecated. Please set these arguments in the constructor instead.
  with gr.Row().style(equal_height=False):
C:\stable-diffusion-webui-directml\modules\ui.py:980: GradioDeprecationWarning: The `style` method is deprecated. Please set these arguments in the constructor instead.
  with gr.Row().style(equal_height=False):
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 153.1s (prepare environment: 149.1s, import torch: 2.4s, import gradio: 1.5s, setup paths: 1.5s, initialize shared: 1.7s, other imports: 0.5s, setup codeformer: 0.1s, load scripts: 0.7s, create ui: 0.3s, gradio launch: 0.3s).
loading stable diffusion model: FileNotFoundError
Traceback (most recent call last):
  File "C:\Users\<username>\AppData\Local\Programs\Python\Python310\lib\threading.py", line 973, in _bootstrap
    self._bootstrap_inner()
  File "C:\Users\<username>\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "C:\stable-diffusion-webui-directml\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "C:\stable-diffusion-webui-directml\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "C:\stable-diffusion-webui-directml\modules\ui.py", line 1460, in <lambda>
    update_image_cfg_scale_visibility = lambda: gr.update(visible=shared.sd_model and shared.sd_model.cond_stage_key == "edit")
  File "C:\stable-diffusion-webui-directml\modules\shared_items.py", line 110, in sd_model
    return modules.sd_models.model_data.get_sd_model()
  File "C:\stable-diffusion-webui-directml\modules\sd_models.py", line 523, in get_sd_model
    load_model()
  File "C:\stable-diffusion-webui-directml\modules\sd_models.py", line 614, in load_model
    checkpoint_info = checkpoint_info or select_checkpoint()
  File "C:\stable-diffusion-webui-directml\modules\sd_models.py", line 244, in select_checkpoint
    raise FileNotFoundError(error_message)
FileNotFoundError: No checkpoints found. When searching for checkpoints, looked at:
 - file C:\stable-diffusion-webui-directml\model.ckpt
 - directory C:\stable-diffusion-webui-directml\models\Stable-diffusionCan't run without a checkpoint. Find and place a .ckpt or .safetensors file into any of those locations.

Stable diffusion model failed to load
Unloaded weights 0.0s.
*** Error completing request
*** Arguments: ('sd_xl_base_1.0.safetensors', '', 'vae', 'stable-diffusion-v1-5', 'stable-diffusion-v1-5', False, True, True, True, True, True, 'euler', True, 1024, False, '', '', '') {}
    Traceback (most recent call last):
      File "C:\stable-diffusion-webui-directml\modules\call_queue.py", line 57, in f
        res = list(func(*args, **kwargs))
      File "C:\stable-diffusion-webui-directml\modules\call_queue.py", line 36, in f
        res = func(*args, **kwargs)
      File "C:\stable-diffusion-webui-directml\modules\sd_olive_ui.py", line 29, in optimize_from_ckpt
        pipeline = StableDiffusionPipeline.from_single_file(os.path.join(models_path, "Stable-diffusion", checkpoint), torch_dtype=torch.float32, requires_safety_checker=False, scheduler_type=scheduler_type)
      File "C:\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\loaders.py", line 1922, in from_single_file
        pipe = download_from_original_stable_diffusion_ckpt(
      File "C:\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\pipelines\stable_diffusion\convert_from_ckpt.py", line 1591, in download_from_original_stable_diffusion_ckpt
        pipe = pipeline_class(
    TypeError: StableDiffusionPipeline.__init__() got an unexpected keyword argument 'text_encoder_2'

---

Additional information

My windows username does have a space in it. Never know when that will cause problems.

hisham-hchowdhu commented 1 year ago

we need SDXL OLive script to convert SDXL models; standard SD Olive scripts will not work with SDXL https://github.com/microsoft/Olive/tree/main/examples/directml/stable_diffusion_xl Automatic has to trigger this script when SDXL is used, may be we need a checkmark box saying we are trying to convert SDXL

pw405 commented 1 year ago

we need SDXL OLive script to convert SDXL models; standard SD Olive scripts will not work with SDXL https://github.com/microsoft/Olive/tree/main/examples/directml/stable_diffusion_xl Automatic has to trigger this script when SDXL is used, may be we need a checkmark box saying we are trying to convert SDXL

Oh, nice find! I'm having same issue as OP as well. I believe @lshqqytiger is aware from the other Olive Support thread.

lshqqytiger commented 1 year ago

Please check if this issue persists after commit 953706bacf986eb573c7c44b40d8ff67a23e794c.

TheFatBastid commented 1 year ago

Unloaded weights 0.0s.

Optimizing text_encoder [2023-09-24 12:24:42,126] [INFO] [engine.py:939:_run_pass] Running pass OnnxConversion [2023-09-24 12:24:42,129] [INFO] [engine.py:939:_run_pass] Running pass OrtTransformersOptimization [2023-09-24 12:24:42,131] [INFO] [footprint.py:166:get_pareto_frontier] pareto frontier points: 1_OrtTransformersOptimization-0-039a5ccebc3e6aa42e8049eb12c97898 {'latency-avg': 7.93922} [2023-09-24 12:24:42,132] [INFO] [engine.py:609:get_pareto_frontier_footprints] Output all 1 models [2023-09-24 12:24:42,133] [INFO] [engine.py:392:run] No packaging config provided, skip packaging artifacts Optimized text_encoder

Optimizing text_encoder_2 [2023-09-24 12:24:42,149] [INFO] [engine.py:939:_run_pass] Running pass OnnxConversion [2023-09-24 12:24:42,151] [INFO] [engine.py:939:_run_pass] Running pass OrtTransformersOptimization [2023-09-24 12:24:42,154] [INFO] [footprint.py:166:get_pareto_frontier] pareto frontier points: 3_OrtTransformersOptimization-2-039a5ccebc3e6aa42e8049eb12c97898 {'latency-avg': 33.09119} [2023-09-24 12:24:42,154] [INFO] [engine.py:609:get_pareto_frontier_footprints] Output all 1 models [2023-09-24 12:24:42,155] [INFO] [engine.py:392:run] No packaging config provided, skip packaging artifacts Optimized text_encoder_2

Optimizing unet [2023-09-24 12:24:42,172] [INFO] [engine.py:939:_run_pass] Running pass OnnxConversion [2023-09-24 12:24:42,173] [WARNING] [engine.py:920:_run_passes] Skipping evaluation as model was pruned [2023-09-24 12:24:42,174] [INFO] [engine.py:609:get_pareto_frontier_footprints] Output all 0 models [2023-09-24 12:24:42,174] [INFO] [engine.py:392:run] No packaging config provided, skip packaging artifacts Error completing request Arguments: ('sd_xl_base_1.0.safetensors', '', 'vae', 'sdxl', 'sdxl', 'runwayml/stable-diffusion-v1-5', '', 'vae', 'stable-diffusion-v1-5', 'stable-diffusion-v1-5', True, True, True, True, True, True, True, True, True, True, 'euler', True, 1024, False, '', '', '') {} Traceback (most recent call last): File "C:\stable-diffusion-webui-directml\modules\call_queue.py", line 57, in f res = list(func(*args, *kwargs)) File "C:\stable-diffusion-webui-directml\modules\call_queue.py", line 36, in f res = func(args, **kwargs) File "C:\stable-diffusion-webui-directml\modules\ui.py", line 2081, in optimize return optimize_sdxl_from_ckpt( File "C:\stable-diffusion-webui-directml\modules\sd_olive_ui.py", line 149, in optimize_sdxl_from_ckpt optimize( File "C:\stable-diffusion-webui-directml\modules\sd_olive_ui.py", line 352, in optimize assert conversion_footprint and optimizer_footprint AssertionError


Screenshot 2023-09-24 122532

pw405 commented 1 year ago

After running an update, the error I get now is as follows:

Unloaded weights 0.0s.

Optimizing text_encoder
[2023-09-28 18:48:00,973] [INFO] [footprint.py:168:get_pareto_frontier] pareto frontier points: 3_OrtTransformersOptimization-2-b57fe3a5dca0ab4244f22df067339eea-gpu-dml {'latency-avg': 7.15187}
[2023-09-28 18:48:00,973] [INFO] [engine.py:475:run_search] Output all 1 models
[2023-09-28 18:48:00,974] [INFO] [engine.py:318:run] No packaging config provided, skip packaging artifacts
Optimized text_encoder

Optimizing unet
[2023-09-28 18:48:00,995] [INFO] [footprint.py:168:get_pareto_frontier] pareto frontier points: 5_OrtTransformersOptimization-4-686c2f21a746dbcaaa43ee99073900e6-gpu-dml {'latency-avg': 52.05949}
[2023-09-28 18:48:00,995] [INFO] [engine.py:475:run_search] Output all 1 models
[2023-09-28 18:48:00,996] [INFO] [engine.py:318:run] No packaging config provided, skip packaging artifacts
Optimized unet

Optimizing vae_decoder
[2023-09-28 18:48:01,017] [INFO] [footprint.py:168:get_pareto_frontier] pareto frontier points: 7_OrtTransformersOptimization-6-b1a42f24996a64c47333128369a9eb21-gpu-dml {'latency-avg': 65.37038}
[2023-09-28 18:48:01,018] [INFO] [engine.py:475:run_search] Output all 1 models
[2023-09-28 18:48:01,018] [INFO] [engine.py:318:run] No packaging config provided, skip packaging artifacts
Optimized vae_decoder

Optimizing vae_encoder
[2023-09-28 18:48:01,041] [INFO] [footprint.py:168:get_pareto_frontier] pareto frontier points: 9_OrtTransformersOptimization-8-b1a42f24996a64c47333128369a9eb21-gpu-dml {'latency-avg': 35.96865}
[2023-09-28 18:48:01,042] [INFO] [engine.py:475:run_search] Output all 1 models
[2023-09-28 18:48:01,042] [INFO] [engine.py:318:run] No packaging config provided, skip packaging artifacts
Optimized vae_encoder

Creating ONNX pipeline...
*** Error completing request
*** Arguments: ('sd_xl_base_1.0_0.9vae.safetensors', '', 'vae', 'ONNX-SDXL', 'OUTPUT-SDXL', 'runwayml/stable-diffusion-v1-5', '', 'vae', 'stable-diffusion-v1-5', 'stable-diffusion-v1-5', True, False, True, True, True, True, True, True, True, True, 'euler', True, 1024, False, '', '', '') {}
    Traceback (most recent call last):
      File "G:\OLIVESD\stable-diffusion-webui-directml\modules\call_queue.py", line 57, in f
        res = list(func(*args, **kwargs))
      File "G:\OLIVESD\stable-diffusion-webui-directml\modules\call_queue.py", line 36, in f
        res = func(*args, **kwargs)
      File "G:\OLIVESD\stable-diffusion-webui-directml\modules\ui.py", line 2081, in optimize
        return optimize_sdxl_from_ckpt(
      File "G:\OLIVESD\stable-diffusion-webui-directml\modules\sd_olive_ui.py", line 149, in optimize_sdxl_from_ckpt
        optimize(
      File "G:\OLIVESD\stable-diffusion-webui-directml\modules\sd_olive_ui.py", line 405, in optimize
        feature_extractor=pipeline.feature_extractor,
      File "G:\OLIVESD\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\configuration_utils.py", line 137, in __getattr__
        raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
    AttributeError: 'StableDiffusionXLPipeline' object has no attribute 'feature_extractor'

Settings I used Olive tab: image

ycodryn commented 11 months ago

Getting AssertionError too. Tried optimize checkpoint and optimize onnx model , same error.

jhodak commented 11 months ago

same here. I get 2 errors often. If I go and for instance download the ckpt file for SD 2-1 download, then try to optimize checkpoint under Olive Tab

image

image

Yes I turned safety checker off to try it, it did not work with it on or off.

Then if I try to get SDXL models to run, I go to ONNX tab - put in the SD model I want such as stabilityai/stable-diffusion-xl-base-1.0 click download model, that works ok. Then move over to the olive tab using Optimize ONNX Model

image

It always fails optimizing UNet for me. If I deselect Unet it optimizes, but the model will not work without Unet.

image

I get this same assert error conversion_footprint and optimizer_footprint a lot.

It also seems, the options from the optimize checkpoint and optimize ONNX models are both taken into account when you click optimize model using olive, so if you put anything into the one, even though you are on another tab, they definitely get pulled in which if you are trying to optimize models and trying to find one which works, you can easily end up with weird things happening because it is using the values of both tabs when you hit optimize. As a user, I would not expect a tab I am not on to be influencing what I am doing on a different tab, but maybe that is just me and I don't understand it very well.