intel-extension-for-pytorch icon indicating copy to clipboard operation
intel-extension-for-pytorch copied to clipboard

OSError When Importing Pytorch

Open MikyLanfra opened this issue 1 year ago • 5 comments

          Hello, it seems I am having the same problems as the previous user with the usage of the ipex library (I also have Intel iRISXe Graphics on Windows 11) . 

Other than a few basic changes (such as the change from 2024.0 to 2024.1 in the paths passed to the prompt), I get the same errors:

  • OSError: [WinError 126] The specified module could not be found. Error loading "C:\Users\test.conda\envs\ipex_test\lib\site-packages\torch\lib\backend_with_compiler.dll" or one of its dependencies.
  • OSError: [WinError 127] The specified module could not be found. Error loading "C:\Users\test.conda\envs\ipex_test\lib\site-packages\torch\lib\backend_with_compiler.dll" or one of its dependencies.

I have installed VS2022, Intel® oneAPI DPC++ Compiler and Intel® oneAPI Base Toolkit as asked in the installation page and haven't had any warnings or errors in those installations, I have restarted the PC as suggested by the installer and now I am trying to install pytorch, pytorchvision and ipex, but something is not working.

To make it easier for you to help me I have also attached a file txt containing all my prompts. Ipex_Problems_1.txt Ipex_Problems_2.txt Thank you in advance for the support.

Originally posted by @MikyLanfra in https://github.com/intel/intel-extension-for-pytorch/issues/560#issuecomment-2151561643

MikyLanfra avatar Jun 06 '24 07:06 MikyLanfra

@MikyLanfra We have seen users reporting similar issues " Error loading "C:\Users\test.conda\envs\ipex_test\lib\site-packages\torch\lib\backend_with_compiler.dll" when using Windows PowerShell. If you were using PowerShell, try switching to Windows Command prompt or Anaconda Command prompt

vishnumadhu365 avatar Jun 08 '24 11:06 vishnumadhu365

First of all thank you for the reply, unfortunately the prompts I have attached are those of the Anaconda Prompt, and I have actually tried with the Windows Command Prompt as well, obtaining the same results... Is there any other possible way to fix this problem? Maybe some specific versions of either the OneAPI Requirements or the packages?

MikyLanfra avatar Jun 08 '24 14:06 MikyLanfra

@MikyLanfra Sure, lets debug a bit further. Lets try the following sequence of steps (share terminal output of steps 2-5) :

  1. Open Windows Device Manager, under Display, check if its listing the Intel ARC xxx GPU. If the gpu drivers are not installed correctly it will not list the gpu name correctly. Share a screen shot of what you see there
  2. Open a new Anaconda Command prompt and source oneAPI by running call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat It should load all oneapi components successfully.
  3. Run sycl-ls. This should list an item as oneapi_level_zero:gpu, with the same name as in step 1.
  4. Activate your previously prepared conda env conda activate ipex_test
  5. Run the ipex sanity check command and share its output 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())];"

vishnumadhu365 avatar Jun 08 '24 19:06 vishnumadhu365

I have done all the suggested steps, and the screenshots of the results are attached below. As stated before though, I have an Iris Xe Graphics GPU, not an intel Arc Graphics GPU... I thought that could be the main problem, but since the issue I referenced above managed to find a solution with this same GPU, maybe the problem may lie somewhere else. To sum up, the main difference with the expected output is that I find an Iris Xe Graphics GPU in steps 1 and 3, and in step 5 I have the same WinError 127 error as usual. Screenshot 2024-06-10 181203 Screenshot 2024-06-10 181420 Screenshot 2024-06-10 181457

MikyLanfra avatar Jun 10 '24 16:06 MikyLanfra

@MikyLanfra I am unable to reproduce this issue on a system with nearly similar configuration (Core i7 1195G7 with Xe Graphics). I could successfully run a sample ResNet50 inference on the Iris Xe iGPU. Took the following steps while testing, (1) installed latest ARC, Xe driver pack ,
(2) installed latest x86 Microsoft Visual C++ Redistributable (3) install and source oneapi base toolkit 2024.1 (4) created conda env and installed ipex (had to downgrade setuptools version to <70 pip_list.txt)

As you suspect, it could be your python env getting messed up, you could try creating a new conda env and installing ipex afresh.

#start a new anaconda prompt, source oneapi/setvars.bat
conda create -n ipex_fresh python=3.10
conda activate ipex_fresh
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.post0 --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/

vishnumadhu365 avatar Jun 13 '24 08:06 vishnumadhu365

Hi @MikyLanfra , as @vishnumadhu365 suggests, you should install pkg-config libuv in your env set up process and normally it will pass.

ZhaoqiongZ avatar Jul 18 '24 02:07 ZhaoqiongZ

I have the same issue on CPU:14900k, GPU:arc a770 on Win 11 Pro. OSError: [WinError 126] The specified module could not be found. Error loading ".conda\envs\ipex\lib\site-packages\intel_extension_for_pytorch\bin\intel-ext-pt-gpu.dll" or one of its dependencies.

sunilmathew-mcw avatar Jul 18 '24 14:07 sunilmathew-mcw

Hi @sunilmathew-mcw , your error is different and not related to backend_with_compiler.dll, so conda install pkg-config libuv will not help. could you collect your OS env with

wget https://raw.githubusercontent.com/intel/intel-extension-for-pytorch/main/scripts/collect_env.py
python collect_env.py

before that you can try pip install dpcpp-cpp-rt==2024.1 mkl-dpcpp==2024.1

ZhaoqiongZ avatar Jul 22 '24 06:07 ZhaoqiongZ

Hi @ZhaoqiongZ , I actually had removed my conda env, when I tried to recreate I did get

(ipex) PS C:\Users\sunil> 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())];"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\sunil\.conda\envs\ipex\Lib\site-packages\torch\__init__.py", line 139, in <module>
    raise err
OSError: [WinError 126] The specified module could not be found. Error loading "C:\Users\sunil\.conda\envs\ipex\Lib\site-packages\torch\lib\backend_with_compiler.dll" or one of its dependencies.
pip install dpcpp-cpp-rt==2024.1 mkl-dpcpp==2024.1

then I tried what you suggested pip install dpcpp-cpp-rt==2024.1 mkl-dpcpp==2024.1

then the error went away, thank you very much! Now I am able to run the ipex examples

sunilmathew-mcw avatar Jul 22 '24 14:07 sunilmathew-mcw