【问题标题】:Theano: Cannot allocate memory error for "shape.eval()" but not "np.asarray"Theano:无法为“shape.eval()”分配内存错误,但不是“np.asarray”
【发布时间】: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)?

【问题讨论】:

    标签: python theano


    【解决方案1】:

    发现问题。见here

    eval() 调用 subprocess()(用于编译),后者又调用 fork()

    此进程分配有大量虚拟内存 (vsize)。此外,此主机上没有配置交换。尽管执行此eval() 所需的实际内存很小,但我相信fork 分配虚拟内存失败并因此出现错误。

    添加交换空间使问题消失。交换空间从未被使用过,但我相信足以满足虚拟内存分配。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-16
      • 1970-01-01
      • 2013-12-19
      • 2017-12-07
      • 2016-04-17
      • 1970-01-01
      • 2018-11-15
      相关资源
      最近更新 更多