首页 文章

CuPy耗尽内存

提问于
浏览
1

我一直在测试CuPy库并使用einsum完成一个简单的矩阵乘法:

C = cp.einsum('pqrs,rs->pq', A, B)

A和B的尺寸是,(41,41,41,41)(41,41),接受性 . 我还检查了它们的大小,即22606088字节,13448字节 .

While running the code, I am getting the following error message:
OutOfMemoryError: out of memory to allocate 38000834048 bytes (total 38023468032 bytes)

它表明我的内存不足 . 是否有任何选项可以将数据部分发送到设备并按批次执行操作?

1 回答

  • 0

    我认为没有选择为一个阵列部分发送数据 .

    我之前遇到过同样的问题,这可能是因为杯子的einsum效率尚未优化 . https://github.com/cupy/cupy/issues/19#issuecomment-322972682

    如果您可以尝试使用 transposereshapematmul 等替换您的einsum功能,请尝试这些 .

    我猜

    C = cp.einsum('pqrs,rs->pq', A, B)
    

    相当于

    p, q, r, s = A.shape
    A = cp.reshape(A, (p, q, r*s))
    B = cp.reshape(B, (1, 1, r*s))
    C = cp.sum(A * B, axis=2)
    

相关问题