大家好

最近因為一下要跑keras一下又要跑pytorch
所以安裝來安裝去的
有點混亂
就我的經驗
如果重新安裝pytorch時候非常容易會因為版本問題導致CUDA無法正確啟用
目前我就遇到這情況

2022-05-16 11:47:39.039332: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudnn64_7.dll
2022-05-16 11:47:39.739986: E tensorflow/stream_executor/cuda/cuda_dnn.cc:318] Loaded runtime CuDNN library: 7.5.1 but source was compiled with: 7.6.5. CuDNN library major and minor version needs to match or have higher minor version in case of CuDNN 7.0 or later version. If using a binary install, upgrade your CuDNN library. If building from sources, make sure the library loaded at runtime is compatible with the version specified during compile configuration.
2022-05-16 11:47:39.750899: E tensorflow/stream_executor/cuda/cuda_dnn.cc:318] Loaded runtime CuDNN library: 7.5.1 but source was compiled with: 7.6.5. CuDNN library major and minor version needs to match or have higher minor version in case of CuDNN 7.0 or later version. If using a binary install, upgrade your CuDNN library. If building from sources, make sure the library loaded at runtime is compatible with the version specified during compile configuration.

有時候這種錯誤很難摸清楚頭緒
因為會想說:
我不是都在 tensorflow keras 訓練?
且我都沒有動CuDNN 版本也沒有動 tensorflow keras
怎麼會突然不能訓練呢?
經過一輪嘗試


發現原因還是出在 pytorch


在讀取cuda類的時候會出現這一段話:

2022-05-16 11:52:51.407473: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll

這邊會想:
我不是用CUDA 10.2 嗎?
這邊怎麼顯示 cudart64_101.dll ?
我這邊才想起來
我之前有用過其實我原本是用 CUDA 10.1
之後才改 CUDA 10.2
然後有用CUDA 10.2的 CuDNN
在 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin
的cudart64_102.dll
放到
C:\Python37\Lib\site-packages\torch\lib
新增一個 cudart64_101.dll

意思是說 原本
tensorflow 2.3.0是配合 CUDA 10.1的
是我用這種偷吃步讓 tensorflow 2.3.0可以配合 CUDA 10.2
只是我忘記了 (很久之前弄得,忘記了)

結果因為這次不小心更新了 torch
造成裡面的 cudart64_101.dll 被蓋掉了

(圖: 注意目前存取cuda的版本中的cudart64_101.dll 當然要注意tensorflow版本存取的到底是哪一個檔案 )

(圖: 確認目前執行的python 中的 torch資料夾裡面的cudart64_101.dll 是否版本與 cuda的一致)

 

總之

當出現
Loaded runtime CuDNN library: XXX but source was compiled with: XXX
這樣的錯誤時候
就是代表 torch 中的 cudart64_XXX.dll 版本 跟 目前使用的 CUDA的 cudart64_XXX.dll 是不一樣的

朝這個方向去解決就對了
給大家參考囉
感謝