intel / intel-extension-for-pytorch

A Python package for extending the official PyTorch that can easily obtain performance on Intel platform
Apache License 2.0
1.63k stars 249 forks source link

OSError: [WinError 126] The specified module could not be found. Error loading "C:\path\to\venv\lib\site-packages\torch\lib\backend_with_compiler.dll" or one of its dependencies #485

Closed scouzi1966 closed 6 months ago

scouzi1966 commented 11 months ago

Describe the bug

import torch

Versions

2.1.10+xpu - but also on recent releases too Arc 770 Windows 11 - very recent build AMD 5900x (sorry Intel ...) Python 3.10 but I have the same problems with 3.11

OSError: [WinError 126] The specified module could not be found. Error loading "C:\Users\sylva\AIC\ipex2\venv\lib\site-packages\torch\lib\backend_with_compiler.dll" or one of its dependencies

The above happens on import torch step in Python

I constantly get these errors on most installs from Intel repo on 'import torch'. The installs work but I get runtime errors. the error is not really related to backend_with_compiler.dll. It fails there because it's the first in the list to get loaded. There is something wrong with the contents of the torch/lib folder. Perhaps the dll are 64 bits vs expected 32?

The only packages I can install and run are the pre-built wheel packages from https://github.com/Nuullll/intel-extension-for-pytorch

scouzi1966 commented 11 months ago

I forgot to add the full context

Do wee need to set DYLD_LIBRARY_PATH to point to some OneAPI DLLs installed locally on our Windows? The error is related to Windows system calls to load the torch librairies which may themselves be linked to OneAPI. In other words, does patched pytorch use DYLD_LIBRARY_PATH to link with OneAPI librairies?

import torch Traceback (most recent call last): File "", line 1, in File "C:\path\to\venv\lib\site-packages\torch__init__.py", line 139, in raise err OSError: [WinError 126] The specified module could not be found. Error loading "C:\path\to\venv\lib\site-packages\torch\lib\backend_with_compiler.dll" or one of its dependencies.

Jacoby1218 commented 11 months ago

even these prebuilt packages don't work for me, getting the same error. (driver version is 5074)

scouzi1966 commented 11 months ago

@jacob1218

These worked for me as a workaround. https://github.com/Nuullll/intel-extension-for-pytorch/releases . It'a a fork

Download them and install from the filesystem pip install ./package-name

There are 3.10 and 3.11 packages. Download the ones according to your version of Python. I have used Win 11 with Python 3.10. I didn't try with 3.11 as they were added only yesterday

kns1966 commented 11 months ago

I tend to work with the official Python installation and install libraries as needed. In this case, I experienced the same error. The quick fix was to switch to Miniconda3, then update with conda install pkg-config libuv as per the Ipex installation page.

At the moment, I assume the failure is due to missing packages/dependencies related to pkg-config and libuv.

jingxu10 commented 10 months ago

@ashokei @min-jean-cho FYI.

CnF-Gris commented 9 months ago

I have the same error when working on a jupyter notebook or executing the file from the default button. While executing the same file on a PowerShell in VSCode, everything goes smooth.

My workaround for this has been putitng a .bat file in {your_conda_env}/etc/conda/activate.d with this line: call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat"

blionberger commented 9 months ago

I have run into this same issue using either the pip or source build and install. I have uninstalled and attempted reinstall multiple times now over the past few days trying everything I could find on the internet. I think the install instructions are missing a few steps or need to be reattempted internally from a clean install.

I am so far disappointed in setting up GPU support on Intel products for pytorch. This process worked the first time with fewer steps on a competitors product. I am to frustrated to continue and will wait for something to change or improve before attempting again.

doucej commented 9 months ago

@jacob1218

These worked for me as a workaround. https://github.com/Nuullll/intel-extension-for-pytorch/releases . It'a a fork

Download them and install from the filesystem pip install ./package-name

There are 3.10 and 3.11 packages. Download the ones according to your version of Python. I have used Win 11 with Python 3.10. I didn't try with 3.11 as they were added only yesterday

This fork is great -- easy, functional install, no issues trying to source environment setup or set library paths to get it going.

blionberger commented 9 months ago

@doucej I'll give it a go and report back. Thanks!

blionberger commented 9 months ago

Sorry for the slow reply, these did work out of the box. Thank you for the suggestion @doucej !

Kaszanas commented 9 months ago

I have the same issue, I surely hope that the installation steps will be made easier in the future.

@jacob1218 These worked for me as a workaround. https://github.com/Nuullll/intel-extension-for-pytorch/releases . It'a a fork Download them and install from the filesystem pip install ./package-name There are 3.10 and 3.11 packages. Download the ones according to your version of Python. I have used Win 11 with Python 3.10. I didn't try with 3.11 as they were added only yesterday

This fork is great -- easy, functional install, no issues trying to source environment setup or set library paths to get it going.

This has worked for me. I would urge the developers to try and make it easier to install this software.

akjamie commented 7 months ago

@jacob1218

These worked for me as a workaround. https://github.com/Nuullll/intel-extension-for-pytorch/releases . It'a a fork

Download them and install from the filesystem pip install ./package-name

There are 3.10 and 3.11 packages. Download the ones according to your version of Python. I have used Win 11 with Python 3.10. I didn't try with 3.11 as they were added only yesterday

Tried the 3.11 package, seems the .whl fiels are not compatible with python 3.11.

pip install https://github.com/Nuullll/intel-extension-for-pytorch/releases/download/v2.1.10%2Bxpu/torchvision-0.16.0a0+cxx11.abi-cp311-cp311-win_amd64.whl ERROR: torchvision-0.16.0a0+cxx11.abi-cp311-cp311-win_amd64.whl is not a supported wheel on this platform.

Windows 11 + python 3.11.9 + 13th Gen Intel(R) Core(TM) i5-13500H

OvaltineSamuel commented 7 months ago

I ran into the same issue when following the official IPEX installation guide. However, the error disappeared when I initialized oneAPI environment in Anaconda Prompt instead of Anaconda Powershell Prompt.

My environment: IPEX version: v2.1.20+xpu Installation Package: pip Windows 11 + Python 3.10.4 + 4th Gen Xeon + Arc A770

Running in Anaconda Powershell Prompt (with error):

Running in Anaconda Prompt (no error):

I don't know the reason why there are different results when running in the same conda environment but in different terminals. And I still have the torchvision warning when running the sanity test script. Please lmk if you guys have solved the warning problem before.

(left: Anaconda Prompt, right: Anaconda Powershell Prompt) Screenshot 2024-04-11 142737

yinghu5 commented 6 months ago

@OvaltineSamuel thank you very much for the report and sharing. You are exactly right: Neither “windows powershell” or “anaconda powershell prompt” does not work, if using conda prompt, we need to use "anaconda prompt".

yinghu5 commented 6 months ago

Dear @akjamie @Kaszanas @scouzi1966 @OvaltineSamuel and all,

I saw several similar issues during Windows installation in IPEX Git Hub. Like: https://github.com/intel/intel-extension-for-pytorch/issues/485 https://github.com/intel/intel-extension-for-pytorch/issues/429 [Import intel_extension_for_pytorch fails on windows11

As we analyzed, the main root cause may still be in the installation environment, please note:

Neither “windows powershell” or “anaconda powershell prompt” does not work, if using conda prompt, we need to use "anaconda prompt". please use the anaconda prompt itself, not in PS (powershell) environment. https://github.com/intel/intel-extension-for-pytorch/issues/485

Install step missing like missing install oneAPI or missing activate oneAPI, or missing other package: conda install pkg-config libuv etc.

Other dependencies missing, like MSVC redistribution files. so in summary, please create a new conda environment and follow the install guide: https://intel.github.io/intel-extension-for-pytorch/index.html#installation?platform=gpu&version=v2.1.30%2bxpu&os=windows&package=pip

Pre-requisites installation in order : 3.1) GPU driver 3.2) MSVC environment or Install Microsoft Visual C++ Redistributable Install Microsoft Visual C++ Redistributable from Microsoft website. 3.3) Install oneAPI: 2024.1 {as no download link is available for 2023.2 anymore} @SoldierWz if you haven't oneAPI install, you will run into the problem. please install oneAPI: 2024.1.0 3.4) open Python environment, like miconda3(latest) Python: 3.10

In anaconda prompt (please notes some VS code, call power shell by default)

3.5) Steps to reproduce: conda create --name llmenv python=3.10 conda activate llm call "C:\Program Files (x86)\Intel\oneAPI\compiler\latest\env\vars.bat" -> DPCPPROOT call "C:\Program Files (x86)\Intel\oneAPI\compiler\mkl\env\vars.bat" -> MKLROOT

conda install pkg-config libuv python -m pip install torch==2.1.0.post2 torchvision==0.16.0.post2 torchaudio==2.1.0.post2 intel-extension-for-pytorch==2.1.30 --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/ Sanity test: python -c "import torch; import intel_extension_for_pytorch as ipex; print(torch.version); print(ipex.version); [print(f'[{i}]: {torch.xpu.get_device_properties(i)}') for i in range(torch.xpu.device_count())];"

If you followed those and still run into the problem, please let us know the installation steps you are using. and collect your envs by this collect_env.py

Thanks

CarlGao4 commented 6 months ago

Maybe you can try CarlGao4/ipex-wheel I've even packed AOT for all devices along with it

doucej commented 6 months ago

Confirmed on my end a chunk of the problem was command vs powershell prompt. At least at the time, the instructions weren't so clear there. https://ipex-llm.readthedocs.io/en/latest/doc/LLM/Quickstart/ollama_quickstart.html Did get me up and running quickly with Ollama, that's been a good setup.

han-minhee commented 3 months ago

I also confirmed the same issue still happeing with torch==2.1.0.post3 torchvision==0.16.0.post3 torchaudio==2.1.0.post3 intel-extension-for-pytorch==2.1.40+xp (the sanity check works for cmd, but not the powershell.) Will it be fixed, or will it be left as it is?