lshqqytiger / stable-diffusion-webui-amdgpu

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

[Bug]: DLL load failed while importing onnxruntime_pybind11_state - Build 2d06ac3 #430

Closed xzenocrimzie closed 6 months ago

xzenocrimzie commented 6 months ago

Checklist

What happened?

Performing a fresh install, perform fresh install process until you receive error: ImportError: DLL load failed while importing onnxruntime_pybind11_state: The specified module could not be found. Error is encountered after using --use-directml for the first time in the args.

NOTE: The same error throws while using either --use-directml or --use-zluda. Using no arguments launches the browser, however the model fails to load and cannot generate.

Steps to reproduce the problem

  1. Pull GIT build on commit 2d06ac3 to dir
  2. run webui-user.bat (Python 3.10.6) (launches to browser but fails to load model)
  3. add --use-directml to COMMANDLINE_ARGS
  4. run webui-user.bat again
  5. Encounter error ImportError: DLL load failed while importing onnxruntime_pybind11_state: The specified module could not be found.

What should have happened?

WebUI should have installed onnxruntime and launched to browser

What browsers do you use to access the UI ?

Brave

Sysinfo

sysinfo-2024-03-29-02-30.json

Console logs

venv "C:\Games\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.8.0-RC
Commit hash: 2d06ac3fa99721113ce085ec0675d1323b13ad00
Traceback (most recent call last):
  File "C:\Games\stable-diffusion-webui-directml\launch.py", line 48, in <module>
    main()
  File "C:\Games\stable-diffusion-webui-directml\launch.py", line 39, in main
    prepare_environment()
  File "C:\Games\stable-diffusion-webui-directml\modules\launch_utils.py", line 624, in prepare_environment
    from modules.onnx_impl import initialize_olive
  File "C:\Games\stable-diffusion-webui-directml\modules\onnx_impl\__init__.py", line 6, in <module>
    import onnxruntime as ort
  File "C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\onnxruntime\__init__.py", line 57, in <module>
    raise import_capi_exception
  File "C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\onnxruntime\__init__.py", line 23, in <module>
    from onnxruntime.capi._pybind_state import ExecutionMode  # noqa: F401
  File "C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\onnxruntime\capi\_pybind_state.py", line 32, in <module>
    from .onnxruntime_pybind11_state import *  # noqa
ImportError: DLL load failed while importing onnxruntime_pybind11_state: The specified module could not be found.
Press any key to continue . . .

Additional information

No response

lshqqytiger commented 6 months ago

Maybe fixed in ce3d044680100834e862bee6fefb413bfc835ece

xzenocrimzie commented 6 months ago

Maybe fixed in ce3d044

Did not work.

venv "C:\Games\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.8.0-RC
Commit hash: ce3d044680100834e862bee6fefb413bfc835ece
Installing onnxruntime-directml
Failed to initialize ONNX Runtime. Continue without it.
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\pytorch_lightning\utilities\distributed.py:258: LightningDeprecationWarning: `pytorch_lightning.utilities.distributed.rank_zero_only` has been deprecated in v1.8.1 and will be removed in v2.0.0. You can import it from `pytorch_lightning.utilities` instead.
  rank_zero_deprecation(
Launching Web UI with arguments: --use-directml
Traceback (most recent call last):
  File "C:\Games\stable-diffusion-webui-directml\launch.py", line 48, in <module>
    main()
  File "C:\Games\stable-diffusion-webui-directml\launch.py", line 44, in main
    start()
  File "C:\Games\stable-diffusion-webui-directml\modules\launch_utils.py", line 674, in start
    import webui
  File "C:\Games\stable-diffusion-webui-directml\webui.py", line 13, in <module>
    initialize.imports()
  File "C:\Games\stable-diffusion-webui-directml\modules\initialize.py", line 35, in imports
    from modules import shared_init
  File "C:\Games\stable-diffusion-webui-directml\modules\shared_init.py", line 8, in <module>
    from modules.onnx_impl import initialize as initialize_onnx
  File "C:\Games\stable-diffusion-webui-directml\modules\onnx_impl\__init__.py", line 6, in <module>
    import onnxruntime as ort
  File "C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\onnxruntime\__init__.py", line 57, in <module>
    raise import_capi_exception
  File "C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\onnxruntime\__init__.py", line 23, in <module>
    from onnxruntime.capi._pybind_state import ExecutionMode  # noqa: F401
  File "C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\onnxruntime\capi\_pybind_state.py", line 32, in <module>
    from .onnxruntime_pybind11_state import *  # noqa
ImportError: DLL load failed while importing onnxruntime_pybind11_state: The specified module could not be found.
Press any key to continue . . .

This is from new install, same process as the original report.

lshqqytiger commented 6 months ago

try 5a423d8a59fffc6d5cb2f50149ac6b09a1aaf482

PrincipalSkinner commented 6 months ago

I had this issue. After digging around I eventually had to find two solutions. One was downgrading onnxruntime (I'm currently showing 1.14.0). After that, I think I had to downgrade torch, which I'm currently showing as 2.0.0.

I'm fairly certain downgrading onnxruntime was definitely part of the resolution - I give it a 95% certainty. In fact, I remember specifically finding a comment on a bug report on onnxruntime that suggested downgrading. I'm not certain on torch - I'd say 65%. I definitely did have to downgrade two packages to get it to work, though.

Here are the other onnx packages, in case I'm misremembering that it's onnxruntime: onnx 1.15.0 onnxruntime-direcml 1.17.1

xzenocrimzie commented 6 months ago

try 5a423d8

The result is the following:

venv "C:\Games\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.8.0-RC
Commit hash: 5a423d8a59fffc6d5cb2f50149ac6b09a1aaf482
Installing onnxruntime-directml
Failed to initialize ONNX Runtime. Continue without it.
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\pytorch_lightning\utilities\distributed.py:258: LightningDeprecationWarning: `pytorch_lightning.utilities.distributed.rank_zero_only` has been deprecated in v1.8.1 and will be removed in v2.0.0. You can import it from `pytorch_lightning.utilities` instead.
  rank_zero_deprecation(
Launching Web UI with arguments: --use-directml
Traceback (most recent call last):
  File "C:\Games\stable-diffusion-webui-directml\launch.py", line 48, in <module>
    main()
  File "C:\Games\stable-diffusion-webui-directml\launch.py", line 44, in main
    start()
  File "C:\Games\stable-diffusion-webui-directml\modules\launch_utils.py", line 675, in start
    import webui
  File "C:\Games\stable-diffusion-webui-directml\webui.py", line 13, in <module>
    initialize.imports()
  File "C:\Games\stable-diffusion-webui-directml\modules\initialize.py", line 35, in imports
    from modules import shared_init
  File "C:\Games\stable-diffusion-webui-directml\modules\shared_init.py", line 8, in <module>
    from modules.onnx_impl import initialize as initialize_onnx
  File "C:\Games\stable-diffusion-webui-directml\modules\onnx_impl\__init__.py", line 6, in <module>
    import onnxruntime as ort
  File "C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\onnxruntime\__init__.py", line 57, in <module>
    raise import_capi_exception
  File "C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\onnxruntime\__init__.py", line 23, in <module>
    from onnxruntime.capi._pybind_state import ExecutionMode  # noqa: F401
  File "C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\onnxruntime\capi\_pybind_state.py", line 32, in <module>
    from .onnxruntime_pybind11_state import *  # noqa
ImportError: DLL load failed while importing onnxruntime_pybind11_state: The specified module could not be found.
Press any key to continue . . .

Let me try downgrading the packages as @PrincipalSkinner has recommended and see if that works

xzenocrimzie commented 6 months ago

After downgrading torch to 2.0.0 with pip install --force-reinstall -v torch==2.0.0 and onnxruntime to 1.14.0 with pip install --force-reinstall -v onnxruntime==1.14.0 , deleting venv and running with --use-directml the following is printed to the terminal:

venv "C:\Games\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.8.0-RC
Commit hash: 5a423d8a59fffc6d5cb2f50149ac6b09a1aaf482
Failed to initialize ONNX Runtime. Continue without it.
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\pytorch_lightning\utilities\distributed.py:258: LightningDeprecationWarning: `pytorch_lightning.utilities.distributed.rank_zero_only` has been deprecated in v1.8.1 and will be removed in v2.0.0. You can import it from `pytorch_lightning.utilities` instead.
  rank_zero_deprecation(
Launching Web UI with arguments: --use-directml
Traceback (most recent call last):
  File "C:\Games\stable-diffusion-webui-directml\launch.py", line 48, in <module>
    main()
  File "C:\Games\stable-diffusion-webui-directml\launch.py", line 44, in main
    start()
  File "C:\Games\stable-diffusion-webui-directml\modules\launch_utils.py", line 675, in start
    import webui
  File "C:\Games\stable-diffusion-webui-directml\webui.py", line 13, in <module>
    initialize.imports()
  File "C:\Games\stable-diffusion-webui-directml\modules\initialize.py", line 35, in imports
    from modules import shared_init
  File "C:\Games\stable-diffusion-webui-directml\modules\shared_init.py", line 8, in <module>
    from modules.onnx_impl import initialize as initialize_onnx
  File "C:\Games\stable-diffusion-webui-directml\modules\onnx_impl\__init__.py", line 6, in <module>
    import onnxruntime as ort
  File "C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\onnxruntime\__init__.py", line 57, in <module>
    raise import_capi_exception
  File "C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\onnxruntime\__init__.py", line 23, in <module>
    from onnxruntime.capi._pybind_state import ExecutionMode  # noqa: F401
  File "C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\onnxruntime\capi\_pybind_state.py", line 32, in <module>
    from .onnxruntime_pybind11_state import *  # noqa
ImportError: DLL load failed while importing onnxruntime_pybind11_state: The specified module could not be found.
Press any key to continue . . .

Running webui-user.bat with the argument --dump-sysinfo prints the following:

venv "C:\Games\stable-diffusion-webui-directml\venv\Scripts\Python.exe"
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
C:\Games\stable-diffusion-webui-directml\venv\lib\site-packages\pytorch_lightning\utilities\distributed.py:258: LightningDeprecationWarning: `pytorch_lightning.utilities.distributed.rank_zero_only` has been deprecated in v1.8.1 and will be removed in v2.0.0. You can import it from `pytorch_lightning.utilities` instead.
  rank_zero_deprecation(
fatal: No names found, cannot describe anything.
Sysinfo saved as sysinfo-2024-03-30-20-48.json. Exiting...
Press any key to continue . . .

Attached is the sysinfo dump sysinfo-2024-03-30-20-48.json

PrincipalSkinner commented 6 months ago

In your sysinfo file, it's showing onnxruntime==1.17.1 so you might try downgrading again. I just tested it, and downgrading is definitely what fixed it for me. The only difference I see is that I did it explicitly pip uninstall onnxruntime pip install onnxruntime==1.41.1

onnxruntimeagain

xzenocrimzie commented 6 months ago

@lshqqytiger

Solution- the source of this issue is in the OS used.

Windows 10 SP0 Build 17763 is incompatible with the packages that are required to run this in it's current configuration. Switching to Windows 11 Build 22631 does not encounter this particular error. It is unknown if there is a problem with more advanced builds of Windows 10.

TheVegeta commented 3 months ago

Hey, I'm facing the same issue on Windows 10 after a clean install. I managed to resolve it by installing the latest Microsoft Visual C++ Reissable package, as mentioned in this GitHub issue on the Microsoft ONNXRuntime repository: https://github.com/microsoft/onnxruntime/issues/16116#issuecomment-1768732885.

analogbliss commented 1 month ago

I had to use the same fix as above. Just a comment: some extensions will result in an error. removing them will solve this issue.