Import torch error It's so frustrating

————————————————————————————
python 3.9

cuda-cccl 12.3.101 0 nvidia
cuda-cudart 12.1.105 0 nvidia
cuda-cudart-dev 12.1.105 0 nvidia
cuda-cupti 12.1.105 0 nvidia
cuda-libraries 12.1.0 0 nvidia
cuda-libraries-dev 12.1.0 0 nvidia
cuda-nvrtc 12.1.105 0 nvidia
cuda-nvrtc-dev 12.1.105 0 nvidia
cuda-nvtx 12.1.105 0 nvidia
cuda-opencl 12.3.101 0 nvidia
cuda-opencl-dev 12.3.101 0 nvidia
cuda-profiler-api 12.3.101 0 nvidia
cuda-runtime 12.1.0 0 nvidia
pytorch-cuda 12.1 hde6ce7c_5 pytorch

pytorch 2.2.0 py3.9_cuda12.1_cudnn8_0 pytorch
pytorch-cuda 12.1 hde6ce7c_5 pytorch
pytorch-mutex 1.0 cuda pytorch
torchaudio 2.2.0 pypi_0 pypi
torchvision 0.17.0 pypi_0 pypi
————————————————————————————
An attempt to import torch results in an error message

"OSError Traceback (most recent call last)
Cell In[4], line 3
1 import os
2 os.environ[‘KMP_DUPLICATE_LIB_OK’]=‘True’
----> 3 import torch

File d:\ProgramData\miniconda3\envs\bayes\lib\site-packages\torch_init_.py:130
128 err = ctypes.WinError(last_error)
129 err.strerror += f’ Error loading “{dll}” or one of its dependencies.’
→ 130 raise err
131 elif res is not None:
132 is_loaded = True

OSError: [WinError 182] operating system cannot run %1. Error loading “d:\ProgramData\miniconda3\envs\bayes\lib\site-packages\torch\lib\fbgemm.dl”
————————————————————————————
(1) I can find the file under the path “d:\ProgramData\miniconda3\envs\bayes\lib\site-packages\torch\lib\fbgemm.dl”.
(2) Use “import ctypes “alone
ctypes.CDLL(r"D:\ProgramData\miniconda3\envs\bayes\Lib\site-packages\torch\lib\fbgemm.dll”)” also failed.
(3) Use software “Dependencies” to find “could not find libiomp5md.dll file on the disk anymore”. I found “libiomp5md.dll” under another folder and used “import ctypes”
ctypes.CDLL(r"D:\ProgramData\miniconda3\envs\bayes\Library\bin\libiomp5md.dll")", this works.

What else can I do to check?

Had the same error, it couldn’t load fbgemm.dll. I tried downgrading CUDA to 12.1.1, that didn’t solve it. Then I just created a new env in conda, installed PyTorch w/ CUDA 12.1 via pip (conda installer kept breaking mid-download), then I tested again and it worked (with CUDA still on 12.1.1).

Can’t believe it! I succeed in the same way, so much thanks.

1 Like