命令 运行 Theano on GPU (windows)
Command to run Theano on GPU (windows)
我这里讲教程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 部分:
有一些命令行在 cpu 或 gpu 上将 Theano 标志设置为 运行。问题是我不知道把这些命令放进去。
我试过 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.
但是,我可以在 cpu 上使用命令
运行 代码
python theanogpu_example.py
我想 运行 GPU 上的代码,我应该怎么做(使用 tutorial 中的这些命令)?
解决方案
感谢@Blauelf 关于 windows 环境变量的想法。
但是,参数必须分开
set THEANO_FLAGS="mode=FAST_RUN" & set THEANO_FLAGS="device=gpu" & set THEANO_FLAGS="floatX=float32" & python theanogpu_example.py
从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
我这里讲教程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 部分: 有一些命令行在 cpu 或 gpu 上将 Theano 标志设置为 运行。问题是我不知道把这些命令放进去。
我试过 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.
但是,我可以在 cpu 上使用命令
运行 代码python theanogpu_example.py
我想 运行 GPU 上的代码,我应该怎么做(使用 tutorial 中的这些命令)?
解决方案
感谢@Blauelf 关于 windows 环境变量的想法。
但是,参数必须分开
set THEANO_FLAGS="mode=FAST_RUN" & set THEANO_FLAGS="device=gpu" & set THEANO_FLAGS="floatX=float32" & python theanogpu_example.py
从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