TensorFlow1.8.0+cuda9.0+cudnn7.1.2

解决TensorFlow 1.7.0与cuDNN版本冲突问题,通过调整至TensorFlow 1.8.0实现与cuDNN 7.1的稳定兼容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

写在前面:tensorflow也可以用conda一条龙安装,如:

conda install tensorflow-gpu==2.1.0

会自动安装其他依赖包,包括cudatoolkit10.1和cudnn7.6,如果至此问题可以解决,下面的可以不用看了。
————————————————————————————————
记录一个折磨我三天的小(da)问题
很早以前就被cuda、cudnn、显卡驱动、TensorFlow、pytorch等等的版本之类的问题困扰,不同的代码可能会需要不同版本的包,直到有一天我使用了anaconda(见Ubuntu安装Anaconda),按不同代码的版本需求安装不同的包(见cuda、cudnn、pytorch、tensorflow安装)。平静了很久很久以后,又出现了一个新的问题。
有个代码之前能够成功运行,虽然这个环境的cuda、cudnn、TensorFlow版本一直都有问题。下面我记录一下我几个环境的包的版本。
环境A:TensorFlow-gpu1.7.0+cuda8.0+cudnn7.0.5
环境B:TensorFlow-gpu1.7.0+cuda8.0+cudnn7.0.5
环境C:TensorFlow-gpu1.7.0+cuda9.0+cudnn7.6.5
实际上环境A和环境B是一致的,根据TensorFlow、cuda、cudnn的版本对应关系(见cuda、cudnn、pytorch、tensorflow安装)TensorFlow1.7.0配套的应该为cuda9和cudnn7,环境C符合这个规则。
使用环境C运行代码报错:

E tensorflow/stream_executor/cuda/cuda_dnn.cc:396] Loaded runtime CuDNN library: 7650 (compatibility version 7600) but source was compiled with 7005 (compatibility version 7000). 
If using a binary install, upgrade your CuDNN library to match.
If building from sources, make sure the library loaded at runtime matches a compatible version specified during compile configuration.

这个TensorFlow1.7.0需要的cudnn7的版本为cudnn7.0的,7.6不适用,于是我就装上cudnn7.0,代码如下:

 conda install cudnn=7.0.5 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/

但是conda要强行将cuda9.0换成cuda8.0:

The following NEW packages will be INSTALLED:     
cudnn:           7.0.5-cuda8.0_0     https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main    

The following packages will be DOWNGRADED:
cudatoolkit:     9.0-h13b8566_0                                                              --> 8.0-3
Proceed ([y]/n)?

要装cudnn7.0只得选y,这样cuda就变成9.0了,无奈,就这样得到了环境A和B。
虽然这个版本对应有问题,但是可以运行。而且非常奇怪,即使分配了gpu,环境B只能用cpu运行tensorflow。而环境A只能用gpu运行tensorflow,即使我指定用cpu运行,也要找gpu。(确定两个环境的TensorFlow-gpu版本相同)
就这样我一直睁一只眼闭一只眼,没有管他们,直到昨天,环境A突然报错:

ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

好家伙,又突然需要cuda9.0,就像一头沉睡的狮子,小丑在他身上跳了几个月的舞,也不知道被什么突然惊醒了。同样的代码,同样的环境,只隔一天就完全不能跑了。
cuda9.0和cudnn7.0.5又不能在conda环境中同时存在(不在conda环境中应该是可以共存,但是这样安装起来非常不方便也不便于管理),来回装了几遍cuda9.0和cudnn7.0和tensorflow1.7,都无济于事。
将tensorflow退回1.4,则报错:

ImportError: libcublas.so.6.0: cannot open shared object file: No such file or directory

cudnn7.1是conda环境中和cuda9.0兼容的最低版本,但是使用cudnn7.1也报错:

E tensorflow/stream_executor/cuda/cuda_dnn.cc:396] Loaded runtime CuDNN library: 7102(compatibility version 7100) but source was compiled with 7005 (compatibility version 7000). 
If using a binary install, upgrade your CuDNN library to match.
If building from sources, make sure the library loaded at runtime matches a compatible version specified during compile configuration.

突然注意到tensorflow1.5-1.12这几个版本对应的都是cuda9和cudnn7,想到尝试tensorflow-gpu-1.8:

pip install tensorflow-gpu==1.8.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

成功,与cudnn7.1完美兼容,问题解决。
最终成功的环境:TensorFlow1.8.0+cuda9.0+cudnn7.1.2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值