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

4

我在这里讲解教程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')

测试GPU的Theano章节中: 有一些命令行可以设置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上运行代码,使用教程中的这些命令,应该怎么做?

解决方案
感谢@Blauelf提出的Windows环境变量的想法。 然而,参数必须分开。

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

1
多个 set THEANO_FLAGS= 行将替换先前的内容(这就是为什么脚本有时包含像 set PATH=%PATH%;C:\myDir 这样的代码,其中 %PATH% 会自动替换为先前的值),因此在该命令行中,只有最后一个 set 实际上会产生影响。 - Blauelf
1个回答

5

根据文档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

那部分听起来也很有趣:为GPU使用配置THEANO - Blauelf

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接