【问题标题】:Pytorch RuntimeError: [enforce fail at CPUAllocator.cpp:56] posix_memalign(&data, gAlignment, nbytes) == 0. 12 vs 0Pytorch RuntimeError: [enforce fail at CPUAllocator.cpp:56] posix_memalign(&data, gAlignment, nbytes) == 0. 12 vs 0
【发布时间】:2019-10-09 21:30:11
【问题描述】:

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

在从 csr_matrix 创建 tfidf 词汇张量时,它会提示以下 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

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

【问题讨论】:

  • 这可能是 PyTorch 中的一个错误,最好通过在 github issues 上提问来解决。

标签: python python-3.x pytorch recommendation-engine cosine-similarity


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我在转换小型 Numpy 矩阵时遇到了同样的问题,修复方法是使用 torch.tensor 而不是 torch.Tensor。我想一旦你这样做了,你就可以转换为你想要的特定类型的张量。

    【讨论】:

      猜你喜欢
      • 2021-01-20
      • 1970-01-01
      • 2018-01-27
      • 1970-01-01
      • 2014-06-30
      • 2021-03-03
      • 2023-03-25
      • 2017-01-23
      • 2020-11-15
      相关资源
      最近更新 更多