当我试图从hdf5文件加载一个非常大的数据集时,遇到了MemoryError。我在下面附上了一个简短的例子。
import dask
import dask.array as da
import h5py
from dask.distributed import Client
client = Client('tcp://10.11.69.71:44393')
handle = h5py.File('h5_file.h5', 'r') # matrix size: (4500, 6291456)
a = da.from_array(handle['_data'], chunks='auto') # matrix size: (6291456, 128)
st1 = da.random.random((a.shape[1], 128))
st = client.run(start)
res = da.matmul(a, st1)
res.compute()
这会导致以下错误:
distributed.worker - WARNING - Compute Failed
Function: execute_task
args: ((subgraph_callable, (<function concatenate_axes at 0x2b85d304a0d0>, [array([[ 42., 50., 5., ..., 168., 203., 214.],
[129., 159., 0., ..., 187., 153., 136.],
[ 0., 0., 0., ..., 228., 209., 204.],
...,
[ 18., 28., 13., ..., 255., 227., 218.],
[ 79., 86., 61., ..., 53., 64., 55.],
[ 42., 76., 106., ..., 101., 35., 20.]], dtype=float32), array([[ 50., 60., 33., ..., 169., 204., 215.],
[ 24., 111., 0., ..., 185., 151., 133.],
[ 0., 0., 0., ..., 226., 207., 202.],
...,
[ 17., 23., 14., ..., 255., 228., 219.],
[111., 120., 101., ..., 53., 64., 55.],
[ 85., 98., 90., ..., 100., 37., 22.]], dtype=float32), array([[ 65., 61., 35., ..., 170., 205., 215.],
[215., 237., 214., ..., 184., 149., 131.],
[ 49., 42., 21., ..., 223., 205., 200.],
...,
[ 16., 20., 11., ..., 255., 229., 220.],
[ 85., 85., 69., ..., 53., 64., 54.],
[ 6
kwargs: {}
Exception: MemoryError()
我是否加载数据错误?我也试着使用结果,但没有用。
PS我正在使用dask-mpi创建我的客户端
请注意,通过调用.compute
,您要求将计算的输出作为内存中的单个numpy数组返回给您。
如果您的输出非常大,那么您可能希望使用类似to_hdf5
的函数将其保存到文件中。