theano 这磨人的小妖精

Theano升级到1.0后,在import theano 时总会出现如下提醒,在没升级之前之前是没有的.
>> import theano
Using cuDNN version 5110 on context None
Mapped name None to device cuda: GeForce GTX 960M (0000:01:00.0)
看到这提示感觉很不爽,所以按照上面的提示去试依旧没有解决.
首先按照给出的提示,我重新安装cudnn5.1.10,安装完成之后又出现了下面的情况:
>> import theano
Using cuDNN version 5105 on context None
Mapped name None to device cuda: GeForce GTX 960M (0000:01:00.0)
所以我觉得这和cudnn版本没有任何关系.
按照网上的一个脚本s.py,如下:
from theano import function, config, shared, sandbox
import theano.tensor as T
import numpy
import time

vlen = 10 * 96 * 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([], T.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, T.Elemwise) for x in f.maker.fgraph.toposort()]):
    print('Used the cpu')
else:
    print('Used the gpu')

用来检测使用cpu计算还是gpu.
根目录下的.theanorc文件配置如下:
[global]
device=cuda
floatX=float32
force_device=True

[nvcc]
fastmath = True

执行s.py,结果如下:
[GpuElemwise{exp,no_inplace}((float32, vector)>), HostFromGpu(gpuarray)(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 0.653164 seconds
Result is [ 1.23178029  1.61879349  1.52278066 ...,  1.57353055  1.96092069
  2.0558939 ]
Used the cpu

然后我修改了.theanorc文件,如下:
[global]
device=cpu
floatX=float32
force_device=True

[nvcc]
fastmath = True

执行s.py,结果如下:
[Elemwise{exp,no_inplace}()]
Looping 1000 times took 13.154794 seconds
Result is [ 1.23178029  1.61879337  1.52278066 ...,  1.57353067  1.96092069
  2.0558939 ]
Used the cpu

很神奇吧,明明两次耗时差异很大,
Looping 1000 times took 0.653164 seconds
Looping 1000 times took 13.154794 seconds
为何结果输出相同,都是used cpu?
所以,我觉得这个脚本是错误的.
在解决这个问题过程中,我发现好多人都遇到了同样的问题,所以记录下来,以供大家参考,如果说错了,也请大家不吝指出.

你可能感兴趣的:(机器学习)