1. 程式人生 > >Theano和Tensorflow多GPU使用問題

Theano和Tensorflow多GPU使用問題

我使用的是tensorflow-gpu (1.2.1)和Theano (0.9.0),2個4G視訊記憶體Nvidia Quadro M2000 GPU。

1. theano: ValueError: Could not infer context from inputs 

THEANO_FLAGS="contexts=dev0->cuda0;dev1->cuda1,gpuarray.preallocate=0.95,mode=FAST_RUN,floatX=float32,on_unused_input=warn"  python config.py

ERROR (theano.gof.opt): SeqOptimizer apply <theano.gpuarray.opt.GraphToGPU object at 0xdfe69210>
ERROR: SeqOptimizer apply <theano.gpuarray.opt.GraphToGPU object at 0xdfe69210>
ERROR (theano.gof.opt): Traceback:
ERROR: Traceback:
ERROR (theano.gof.opt): Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/theano/gof/opt.py", line 235, in apply
    sub_prof = optimizer.optimize(fgraph)
  File "/usr/lib/python2.7/site-packages/theano/gof/opt.py", line 87, in optimize
    ret = self.apply(fgraph, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/theano/gpuarray/opt.py", line 322, in apply
    target = infer_context_name(*fgraph.inputs)
  File "/usr/lib/python2.7/site-packages/theano/gpuarray/basic_ops.py", line 122, in infer_context_name
    raise ValueError("Could not infer context from inputs")
ValueError: Could not infer context from inputs 
theano不能自動支援多GPU,需要自己指定一個,只能在一個上面跑, 需要指定一個裝置device=cuda0。

支援多GPU, 需要自己程式設計,參考http://deeplearning.net/software/theano/tutorial/using_multi_gpu.html#

2. tensorflow: ResourceExhaustedError: OOM when allocating tensor with 

    theano: MemoryError: Error allocating 1440000000 bytes of device memory (out of memory).

說明GPU記憶體不夠,要調小輸入或網路單元。

3. theano切換成新的GPU backend

WARNING (theano.sandbox.cuda): The cuda backend is deprecated and will be removed in the next release (v0.10)

theano 0.9.0從cuda backend切換gpuarray backend,需要安裝python2-Cython-0.25+和libgpuarray-0.6.3+, 然後通過gpuarray.preallocate來指定。