【发布时间】:2015-08-23 13:20:37
【问题描述】:
当我尝试使用 shape.eval() 打印共享变量的形状时,出现“无法分配内存”错误。但是当我将它转换为一个 numpy 数组(从而将其移动到 CPU)时,我不仅可以获得形状,还可以获得数组本身。请参阅下面它在 pdb 中停止的位置,数据已加载到 CPU/RAM 中,然后我正在尝试打印 p1 的形状:
(Pdb) p1
W
(Pdb) type(p1)
<class 'theano.sandbox.cuda.var.CudaNdarraySharedVariable'>
(Pdb) p1.shape.eval()
Problem occurred during compilation with the command line below:
/usr/bin/g++ -shared -g -O3 -fno-math-errno -Wno-unused-label -Wno-unused-variable -Wno-write-strings -D NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m64 -fPIC -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -o /home/ubuntu/.theano/compiledir_Linux-3.13--generic-x86_64-with-Ubuntu-14.04-trusty-x86_64-2.7.6-64/tmpe2w2zz/990b9feb030f7691b8412ea91249349d.so /home/ubuntu/.theano/compiledir_Linux-3.13--generic-x86_64-with-Ubuntu-14.04-trusty-x86_64-2.7.6-64/tmpe2w2zz/mod.cpp -L/usr/lib -lpython2.7
ERROR (theano.gof.cmodule): [Errno 12] Cannot allocate memory
2015-08-20 12:09:19,032 theano.gof.cmodule cmodule.py:1083 ERROR [Errno 12] Cannot allocate memory
*** OSError: [Errno 12] Cannot allocate memory
(Pdb) a1 = np.asarray(p1.eval())
(Pdb) a1.shape
(21504, 2048)
(Pdb) a1
array([[ 0.03940072, -0.03306604, -0.00602638, ..., -0.00931167,
0.05510775, 0.02733043],
[snip]
...,
[-0.06175347, 0.03134078, -0.06079643, ..., -0.03223133,
0.00347659, 0.03415193]], dtype=float32)
对于 p1,borrow 设置为 True,但这应该无关紧要,因为我使用的是 GPU,对吧?
内存中有足够的空闲空间:
$ free -m
total used free shared buffers cached
Mem: 15039 14815 224 0 1 4112
-/+ buffers/cache: 10701 4338
Swap: 0 0 0
此错误是 RAM(相对于 GPU 内存)错误,对吧?为什么我可以在将变量传到 CPU 后打印形状(使用 np.asarray),但是 shape.eval() 会打印错误?
解决此问题的好方法是什么(此外,可能是获得更多 RAM)?
【问题讨论】: