googlecolab不使用gpu来编写无代码

fcwjkofz  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(326)

我想在googlecolab中训练一个基于theano的模型。我使用以下方法将运行时类型设置为gpu,并将theano标志设备设置为cuda:

import os
os.environ['THEANO_FLAGS'] = "device=cuda,force_device=True,floatX=float32"
import theano

但它似乎不使用GPU,因为以下单元的输出总是“由cpu使用”:

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

我已经安装pygpu在康达福吉建议在https://discourse.pymc.io/t/pymc3-with-gpu-support-on-google-colab/1649/2 但这并没有改变什么。
有人能帮忙解决这个问题吗?提前谢谢。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题