vladmandic / automatic

SD.Next: Advanced Implementation Generative Image Models
https://github.com/vladmandic/automatic
GNU Affero General Public License v3.0
5.76k stars 431 forks source link

[Issue]: OSError: [WinError 126] Error loading intel-ext-pt-gpu.dll #1955

Closed citratecycle closed 1 year ago

citratecycle commented 1 year ago

Issue Description

Error

I deployed SD.Next on my Windows PC with the recently released oneAPI basekit for Windows. When I tried to start webui.bat with argument --use-ipex, it reports an error when trying to import intel_extension_for_pytorch as ipex. The specific problem is OSError: [WinError 126] Error loading intel-ext-pt-gpu.dll.

Work Tried

I tried to fix it and after some search, it seems that error code 126 happens when the DLL file doesn't exist or some dependencies of the DLL file don't exist.

Firstly, I checked the report path C:\Users\<my_usernmae>\Documents\SD_Local\automatic\venv\lib\site-packages\intel_extension_for_pytorch\bin\intel-ext-pt-gpu.dll and I'm sure the file exists.

Then, I used a dependency checker to check the dependencies of intel-ext-pt-gpu.dll. It shows that four dependencies are missing: torch_cpu.dll, c10.dll, mkl_core.2.dll, mkl_sycl.3.dll.

After some search, the first two belongs to torch and the latter two belongs to oneAPI. So, I found the latter two under C:\Program Files (x86)\Intel\oneAPI\mkl\latest\redist\intel64 and added this directory to the PATH.

For the first two, I think this is where SD.Next need to fix? Pytorch was installed in the venv so the intel extension cannot find dependencies? (I'm not familiar with Python venv so this is just my inference.)

I tried to add automatic\venv\Lib\site-packages\torch\lib to PATH (which is extremely inelegant in my view) and the dependency checker can find all the dependencies of intel-ext-pt-gpu.dll now, but it reports a error/waning that "torch_cpu.dll has missing imports" (indicatingtorch` version and intel extension version don't match?). Under such condition, SD.Next still reports 126 error.

Conclusion

I'm not sure whether the loading DLL error is related to missing dependencies. However, I did find missing dependencies. If the problem is caused by missing dependencies, I think those related to oneAPI can easily be fixed by modifying PATH, while those related to torch need some elegant solution. The problem persists after adding torch-related DLL files to PATH and now I have no idea how to fix it.

Version Platform Description

02:02:40-785720 INFO     Starting SD.Next
02:02:40-790086 INFO     Python 3.10.11 on Windows
02:02:40-885458 INFO     Version: 8aba6d82 Sat Aug 5 19:29:52 2023 +0300
02:02:41-464180 DEBUG    Setting environment tuning
02:02:41-468190 DEBUG    Torch overrides: cuda=False rocm=False ipex=True diml=False
02:02:41-471189 DEBUG    Torch allowed: cuda=False rocm=False ipex=True diml=False
02:02:41-473189 INFO     Intel OneAPI Toolkit detected
02:02:41-631135 DEBUG    Repository update time: Sun Aug  6 00:29:52 2023
02:02:41-631588 DEBUG    Previous setup time: Sun Aug  6 00:55:46 2023
02:02:41-632573 INFO     Disabled extensions: []
02:02:41-633578 INFO     Enabled extensions-builtin: ['a1111-sd-webui-lycoris', 'clip-interrogator-ext', 'LDSR', 'Lora',
                         'multidiffusion-upscaler-for-automatic1111', 'ScuNET', 'sd-dynamic-thresholding',
                         'sd-extension-system-info', 'sd-webui-agent-scheduler', 'sd-webui-controlnet',
                         'stable-diffusion-webui-images-browser', 'stable-diffusion-webui-rembg', 'SwinIR']
02:02:41-639085 INFO     Enabled extensions: []

Other information that may be helpful:

Relevant log output

Using VENV: C:\Users\<my_usernmae>\Documents\SD_Local\automatic\venv
01:14:59-041822 INFO     Starting SD.Next
01:14:59-053843 INFO     Python 3.10.11 on Windows
01:14:59-101783 INFO     Version: 8aba6d82 Sat Aug 5 19:29:52 2023 +0300
01:14:59-474266 DEBUG    Setting environment tuning
01:14:59-475275 DEBUG    Torch overrides: cuda=False rocm=False ipex=True diml=False
01:14:59-476273 DEBUG    Torch allowed: cuda=False rocm=False ipex=True diml=False
01:14:59-477272 INFO     Intel OneAPI Toolkit detected
01:14:59-566775 WARNING  Modified files: ['debug.py']
01:14:59-614070 DEBUG    Repository update time: Sun Aug  6 00:29:52 2023
01:14:59-615077 DEBUG    Previous setup time: Sun Aug  6 00:55:46 2023
01:14:59-616077 INFO     Disabled extensions: []
01:14:59-617080 INFO     Enabled extensions-builtin: ['a1111-sd-webui-lycoris', 'clip-interrogator-ext', 'LDSR', 'Lora',
                         'multidiffusion-upscaler-for-automatic1111', 'ScuNET', 'sd-dynamic-thresholding',
                         'sd-extension-system-info', 'sd-webui-agent-scheduler', 'sd-webui-controlnet',
                         'stable-diffusion-webui-images-browser', 'stable-diffusion-webui-rembg', 'SwinIR']
01:14:59-622077 INFO     Enabled extensions: []
01:14:59-623636 DEBUG    Latest extensions time: Sun Aug  6 00:45:28 2023
01:14:59-624590 DEBUG    Timestamps: version:1691252992 setup:1691254546 extension:1691253928
01:14:59-625593 INFO     No changes detected: Quick launch active
01:14:59-626592 INFO     Verifying requirements
01:14:59-637613 INFO     Disabled extensions: []
01:14:59-638613 INFO     Enabled extensions-builtin: ['a1111-sd-webui-lycoris', 'clip-interrogator-ext', 'LDSR', 'Lora',
                         'multidiffusion-upscaler-for-automatic1111', 'ScuNET', 'sd-dynamic-thresholding',
                         'sd-extension-system-info', 'sd-webui-agent-scheduler', 'sd-webui-controlnet',
                         'stable-diffusion-webui-images-browser', 'stable-diffusion-webui-rembg', 'SwinIR']
01:14:59-643618 INFO     Enabled extensions: []
01:14:59-650134 INFO     Extension preload: 0.0s C:\Users\<my_usernmae>\Documents\SD_Local\automatic\extensions-builtin
01:14:59-651133 INFO     Extension preload: 0.0s C:\Users\<my_usernmae>\Documents\SD_Local\automatic\extensions
01:14:59-697704 DEBUG    Memory used: 0.04 total: 15.86 Collected 0
01:14:59-698705 DEBUG    Starting module: <module 'webui' from
                         'C:\\Users\\<my_usernmae>\\Documents\\SD_Local\\automatic\\webui.py'>
01:14:59-699703 INFO     Server arguments: ['--use-ipex', '--debug']
01:14:59-718733 DEBUG    Loading Torch
01:15:13-767755 DEBUG    Loading Gradio
01:15:14-941106 DEBUG    Loading Modules
╭───────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────╮
│ C:\Users\<my_usernmae>\Documents\SD_Local\automatic\launch.py:192 in <module>                                              │
│                                                                                                                      │
│   191                                                                                                                │
│ ❱ 192     instance = start_server(immediate=True, server=None)                                                       │
│   193     while True:                                                                                                │
│                                                                                                                      │
│ C:\Users\<my_usernmae>\Documents\SD_Local\automatic\launch.py:136 in start_server                                          │
│                                                                                                                      │
│   135     installer.log.info(f"Server arguments: {sys.argv[1:]}")                                                    │
│ ❱ 136     module_spec.loader.exec_module(server)                                                                     │
│   137     if args.test:                                                                                              │
│ in exec_module:883                                                                                                   │
│ in _call_with_frames_removed:241                                                                                     │
│                                                                                                                      │
│ C:\Users\<my_usernmae>\Documents\SD_Local\automatic\webui.py:44 in <module>                                                │
│                                                                                                                      │
│    43 import ldm.modules.encoders.modules # pylint: disable=W0611,C0411,E0401                                        │
│ ❱  44 from modules.call_queue import queue_lock, wrap_queued_call, wrap_gradio_gpu_call # pyli                       │
│    45 from modules.paths import create_paths                                                                         │
│                                                                                                                      │
│ C:\Users\<my_usernmae>\Documents\SD_Local\automatic\modules\call_queue.py:8 in <module>                                    │
│                                                                                                                      │
│     7 from rich import print # pylint: disable=redefined-builtin                                                     │
│ ❱   8 from modules import shared, progress, errors                                                                   │
│     9                                                                                                                │
│                                                                                                                      │
│ C:\Users\<my_usernmae>\Documents\SD_Local\automatic\modules\shared.py:16 in <module>                                       │
│                                                                                                                      │
│     15 from modules.dml import memory_providers, default_memory_provider, directml_do_hijack                         │
│ ❱   16 import modules.interrogate                                                                                    │
│     17 import modules.memmon                                                                                         │
│                                                                                                                      │
│ C:\Users\<my_usernmae>\Documents\SD_Local\automatic\modules\interrogate.py:10 in <module>                                  │
│                                                                                                                      │
│     9 from torchvision.transforms.functional import InterpolationMode                                                │
│ ❱  10 from modules import devices, paths, shared, lowvram, modelloader, errors                                       │
│    11                                                                                                                │
│                                                                                                                      │
│ C:\Users\<my_usernmae>\Documents\SD_Local\automatic\modules\devices.py:170 in <module>                                     │
│                                                                                                                      │
│   169     backend = 'ipex'                                                                                           │
│ ❱ 170     from modules.ipex_specific import ipex_init                                                                │
│   171     ipex_init()                                                                                                │
│                                                                                                                      │
│ C:\Users\<my_usernmae>\Documents\SD_Local\automatic\modules\ipex_specific\__init__.py:4 in <module>                        │
│                                                                                                                      │
│     3 import torch                                                                                                   │
│ ❱   4 import intel_extension_for_pytorch as ipex                                                                     │
│     5 from modules import shared                                                                                     │
│                                                                                                                      │
│ C:\Users\<my_usernmae>\Documents\SD_Local\automatic\venv\lib\site-packages\intel_extension_for_pytorch\__init__.py:89 in   │
│ <module>                                                                                                             │
│                                                                                                                      │
│    88                 err.strerror += f' Error loading "{dll}" or one of its dependencies.'                          │
│ ❱  89                 raise err                                                                                      │
│    90                                                                                                                │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
OSError: [WinError 126] 找不到指定的模块。 Error loading
"C:\Users\<my_usernmae>\Documents\SD_Local\automatic\venv\lib\site-packages\intel_extension_for_pytorch\bin\intel-ext-pt-gpu.d
ll" or one of its dependencies.

Acknowledgements

Disty0 commented 1 year ago

Windows support for IPEX is really experimental and doesn't really work for now.

Check this issue: https://github.com/intel/intel-extension-for-pytorch/issues/398

Nuullll commented 1 year ago

Actually not a purely upstream problem. SD.Next tries to install the latest torchvision (0.15.2), which requires torch == 2.0.1, overriding the intel torch (2.0.0a0) because of incompatible version. Then intel_extension_for_pytorch bails out because of wrong dll version from torch 2.0.1.

I'll try to fix installer.py for IPEX windows.

Disty0 commented 1 year ago

You can give this a try: https://github.com/vladmandic/automatic/discussions/2023

karthika-ml commented 4 months ago

Hi, here is an amazing blog that I found to configure the intel-ipex to your pytorch on a windows: https://christianjmills.com/posts/intel-pytorch-extension-tutorial/native-windows/