Linux下安装miniconda
- 在官网下载miniconda3
- 执行:bash Miniconda3-latest-Linux-x86_64.sh 之后跟随提示步骤,安装过程中可以自动添加路径到配置文件,也可以之后进行配置。在这期间输入 yes no (在这里我是之后配置的所以执行3)
- 将其添加到大环境变量中去
-vim ~/.bashrc
-export PATH=~/anaconda3/bin:$PATH
-source ~/.bashrc
创建虚拟环境并安装theano (主要参考官网教程http://deeplearning.net/software/theano/install_ubuntu.html)
- 基于python2.7创建一个名为theano的环境: conda create --name theano python=2.7
- 进入虚拟环境: source activate theano
-
-使用pip安装:pip install Theano-使用conda安装:conda install numpy scipy mkl pip install parameterized conda install theano pygpu
- Install and configure the GPU drivers (这一步我没有尝试,因为本来就安装好了)
- 配置theanoGPU环境
vim ~/.theanorc
在空白文件中添加
[global]
floatX = float32
device = gpu3
[lib]
cnmem = 0.6 意味着有百分之60的显存分给当前终端 - 也可以不用5,直接在运行的时候使用命令:THEANO_FLAGS='device=cuda,floatX=float32'
(默认为cuda0) - 测试
test.py 文件:
from theano import function, config, shared, tensor
import numpy
import time
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
iters = 1000
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], tensor.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
if numpy.any([isinstance(x.op, tensor.Elemwise) and
('Gpu' not in type(x.op).__name__)
for x in f.maker.fgraph.toposort()]):
print('Used the cpu')
else:
print('Used the gpu')
执行:THEANO_FLAGS='device=cuda,floatX=float32' python test.py
结果:
···
Using cuDNN version 5105 on context None
Mapped name None to device cuda0: GeForce GTX 750 Ti (0000:07:00.0)
[GpuElemwise{exp,no_inplace}(<GpuArrayType<None>(float64, (False,))>), HostFromGpu(gpuarray)(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 1.697514 seconds
Result is [ 1.23178032 1.61879341 1.52278065 ..., 2.20771815 2.29967753
1.62323285]
Used the gpu
···
说明GPU配置使用成功
安装过程中出现的一些乱七八糟的问题
-
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.
解决方法:
1: vim ~/.bashrc
2:添加如下命令:
export THEANO_FLAGS='mode=FAST_RUN,device=cpu,floatX=float32'
3:使修改的theano设置生效:
source ~/.bashrc -
ModuleNotFoundError: No module named'nose'
解决办法:pip install nosey - /home/lyzhang/.miniconda3/envs/lyzhang2/lib/python2.7/site-packages/theano/scan_module/scan_perform_ext.py:76: UserWarning: The file scan_perform.c is not available. This donot happen normally. You are probably in a strangesetup. This mean Theano can not use the cython code for scan. If youwant to remove this warning, use the Theano flag'cxx=' (set to an empty string) to disable all ccode generation.
"The file scan_perform.c is not available. This do"
解决方法: 卸载原来安装的theano:pip uninstall theano
重新用pip安装:pip install theano
菜鸟一枚,有写的不对的地方欢迎留言指正呀~~
网友评论