Mac OS X 与 Linux 上的 Numpy 和内存分配
Numpy and memory allocation on Mac OS X vs. Linux
我使用 numpy 使用 64 位加载大型矩阵 Python。
它在 Mac8GB 内存的 book Pro 上运行良好。
>>> from sklearn.preprocessing import MultiLabelBinarizer
>>> mb = MultiLabelBinarizer()
>>> matrix = mb.fit_transform(questions_topics)
>>> sys.getsizeof(matrix)
47975472376
>>> matrix.shape
(2999967, 1999)
但它在 Ubuntu Google 具有 16GB 内存和 10GB 交换空间的 VM 实例上引发 MemoryError
。
>>> y = mb.fit_transform(questions_topics)
/home/Liwink/anaconda3/lib/python3.5/site-packages/scipy/sparse/base.py in _process_toarray_args(self, order, out)
1037 return out
1038 else:
-> 1039 return np.zeros(self.shape, dtype=self.dtype, order=order)
1040
1041 def __numpy_ufunc__(self, func, method, pos, inputs, **kwargs):
MemoryError:
矩阵在MacOS加载时需要50G VIRT。
我有两个问题:
- 矩阵(大约50GB)保存在内存还是磁盘中?
- 如何在 VM 上加载此矩阵?
谢谢@juanpa.arrivillaga,我通过increasing the swap解决了问题。
但它仍然不完美,因为在 Ubuntu 上它会先用完内存,但在 Mac OS 上它 "saves" 内存很多。
在 Ubuntu 上:
在 Mac OS 上:
在 Ubuntu 上,它比在 Mac OS 上使用更多的 RES。
如何节省 Ubuntu 上的内存?
我使用 numpy 使用 64 位加载大型矩阵 Python。
它在 Mac8GB 内存的 book Pro 上运行良好。
>>> from sklearn.preprocessing import MultiLabelBinarizer
>>> mb = MultiLabelBinarizer()
>>> matrix = mb.fit_transform(questions_topics)
>>> sys.getsizeof(matrix)
47975472376
>>> matrix.shape
(2999967, 1999)
但它在 Ubuntu Google 具有 16GB 内存和 10GB 交换空间的 VM 实例上引发 MemoryError
。
>>> y = mb.fit_transform(questions_topics)
/home/Liwink/anaconda3/lib/python3.5/site-packages/scipy/sparse/base.py in _process_toarray_args(self, order, out)
1037 return out
1038 else:
-> 1039 return np.zeros(self.shape, dtype=self.dtype, order=order)
1040
1041 def __numpy_ufunc__(self, func, method, pos, inputs, **kwargs):
MemoryError:
矩阵在MacOS加载时需要50G VIRT。
我有两个问题:
- 矩阵(大约50GB)保存在内存还是磁盘中?
- 如何在 VM 上加载此矩阵?
谢谢@juanpa.arrivillaga,我通过increasing the swap解决了问题。
但它仍然不完美,因为在 Ubuntu 上它会先用完内存,但在 Mac OS 上它 "saves" 内存很多。
在 Ubuntu 上:
在 Mac OS 上:
在 Ubuntu 上,它比在 Mac OS 上使用更多的 RES。
如何节省 Ubuntu 上的内存?