googlecolab不使用gpu来编写无代码

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

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

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

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

  1. from theano import function, config, shared, tensor as tt
  2. import numpy
  3. import time
  4. vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
  5. iters = 1000
  6. rng = numpy.random.RandomState(22)
  7. x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
  8. f = function([], tt.exp(x))
  9. print(f.maker.fgraph.toposort())
  10. t0 = time.time()
  11. for i in range(iters):
  12. r = f()
  13. t1 = time.time()
  14. print("Looping %d times took %f seconds" % (iters, t1 - t0))
  15. print("Result is %s" % (r,))
  16. if numpy.any([isinstance(x.op, theano.tensor.elemwise.Elemwise) and
  17. ('Gpu' not in type(x.op).__name__)
  18. for x in f.maker.fgraph.toposort()]):
  19. print('Used the cpu')
  20. else:
  21. print('Used the gpu')

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

暂无答案!

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

相关问题