首先声明一下,我是接着本专题写的,所以到此应该已经装好了NVIDIA显卡驱动、cudnn、以及常用的库如numpy等
1. 我们先配置镜像(提速,可选)
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
2. 安装theano
conda install theano pygpu
配置:
sudo gedit ~/.theanorc
添加:
[global]
floatX=float32
device=gpu
base_compiledir=~/external/.theano/
allow_gc=False
warn_float64=warn
[mode]=FAST_RUN
[nvcc]
fastmath=True
[cuda]
root=/usr/local/cuda
自己cuda位置可通过whereis cuda进行查看
之后保存退出,终端输入python然后import theano,
结果报错:
'You are tring to use the old GPU back-end. '
ValueError: You are tring to use the old GPU back-end. It was removed from Theano. Use device=cuda* now. See https://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end%28gpuarray%29 for more information.
我尝试更新一下:
pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git
无果
无奈只好修改.theanorc文件:
[global]
floatX=float32
#device=gpu
device=cuda0
base_compiledir=~/external/.theano/
allow_gc=False
warn_float64=warn
[mode]=FAST_RUN
[nvcc]
fastmath=True
[cuda]
root=/usr/local/cuda
继续测试,报错:
RuntimeError:
To use MKL 2018 with Theano either update the numpy conda packages to
their latest build or set "MKL_THREADING_LAYER=GNU" in your
environment.
解决方法:
conda uninstall mkl=2018
conda install mkl=2017
之后python import theano,一切正常
参考:
https://blog.csdn.net/u010751535/article/details/50806073/
https://blog.csdn.net/legend_hua/article/details/79732587
https://stackoverflow.com/questions/49048734/runtimeerror-to-use-mkl-2018-with-theano-you-must-set-mkl-threading-layer-gnu