在GPU(Windows)上运行Theano的命令

时间:2016-10-20 14:38:19

标签: python windows python-2.7 cmd theano

我在这里讨论教程http://deeplearning.net/software/theano/tutorial/using_gpu.html

我使用的代码

from theano import function, config, shared, sandbox
import theano.tensor as T
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([], 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')

Testing Theano with GPU部分: 有一些命令行将Theano标志设置为在cpu或gpu上运行。问题是我不知道把这些命令放进去。

我试过windows cmd

THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python theanogpu_example.py

然后我得到

'THEANO_FLAGS' is not recognized as an internal or external command,
operable program or batch file.

t1

但是,我可以使用命令

在cpu上运行代码
python theanogpu_example.py

t2

我想在GPU上运行代码,我应该怎么做(在tutorial中使用这些命令)?

解决方案 感谢@Blauelf关于windows环境变量的想法。 但是,param必须分开

set THEANO_FLAGS="mode=FAST_RUN"  & set THEANO_FLAGS="device=gpu" & set THEANO_FLAGS="floatX=float32" & python theanogpu_example.py 

1 个答案:

答案 0 :(得分:5)

the docs开始,THEANO_FLAGS是一个环境变量。因此,当您在Windows上时,您可能想要更改

THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python theanogpu_example.py

set THEANO_FLAGS="mode=FAST_RUN,device=gpu,floatX=float32" & python theanogpu_example.py