Pytorch RuntimeError:[在CPUAllocator.cpp:56上执行失败] posix_memalign(&data,gAlignment,nbytes)==0。12 vs 0

roo*_*m13 6 python recommendation-engine python-3.x cosine-similarity pytorch

我正在构建一个基于内容的简单推荐系统。为了以GPU加速的方式计算余弦相似度,我使用Pytorch

在从中创建tfidf词汇张量csr_matrix,它会提示以下RuntimeErrorr

RuntimeError: [enforce fail at CPUAllocator.cpp:56] posix_memalign(&data, gAlignment, nbytes) == 0. 12 vs 0

我这样做是这样的:

coo = tfidf_matrix.tocoo()
values = coo.data
indices = np.vstack( (coo.row, coo.col ))
i = torch.LongTensor(indices)
v = torch.FloatTensor(values)
tfidf_matrix_tensor = torch.sparse.FloatTensor(i, v, torch.Size(coo1.shape)).to_dense() 
# Prompts the error
Run Code Online (Sandbox Code Playgroud)

我尝试了一个小的测试(tfidf矩阵大小= 10,296)数据集,它可以工作。实际数据集中的tfidf矩阵大小为(27639,226957)

And*_*yar 2

我尝试了在旧版本的 PyTorch 中引发此错误的同一段代码。它说我需要更多的内存。因此,这不是 PyTorch 错误。唯一的解决方案是以某种方式减小矩阵大小。