比较两个稀疏矩阵失败并出现未实现错误
原文标题 :Comparing two sparse matrices fails with Not Implemented error
我最近开始在 Pytorch 中为一个大学项目编程。我想比较两个稀疏矩阵是否相等,但它返回了一个未实现的错误。我尝试在互联网上寻找解决方案,但没有找到任何线索。
torch.equal(matrix_1, matrix_2)
{NotImplementedError}Could not run ‘aten::equal’ with arguments from the ‘SparseCUDA’ backend。这可能是因为该后端不存在该运算符,或者在选择性/自定义构建过程中被省略(如果使用自定义构建)。如果您是在移动设备上使用 PyTorch 的 Facebook 员工,请访问 https://fburl.com/ptmfixes 了解可能的解决方案。’aten::equal’ 仅适用于这些后端:[CPU, CUDA, QuantizedCPU, BackendSelect, Python,命名、共轭、负数、ZeroTensor、ADInplaceOrView、AutogradOther、AutogradCPU、AutogradCUDA、AutogradXLA、AutogradLazy、AutogradXPU、AutogradMLC、AutogradHPU、AutogradNestedTensor、AutogradPrivateUse1、AutogradPrivateUse2、AutogradPrivateUse3、Tracer、AutocastCPU、Autocast、Batched、VmapMode、Functionalize]。
CPU: 注册在 C:\actions-runner_work\pytorch\pytorch\builder\windows\pytorch\build\aten\src\ATen\RegisterCPU.cpp:21063 [kernel]CUDA: 注册在 C:\actions-runner_work\pytorch\ pytorch\builder\windows\pytorch\build\aten\src\ATen…
回复
我来回复-
hpaulj 评论
我无法解决
torch
正在做什么或不做什么,但是稀疏矩阵的比较测试可能很棘手——至少计算成本很高。例如使用
scipy.sparse
:In [96]: M = sparse.coo_matrix(np.eye(3)) In [97]: M Out[97]: <3x3 sparse matrix of type '<class 'numpy.float64'>' with 3 stored elements in COOrdinate format> In [98]: M.A Out[98]: array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])
尝试逐元素比较:
In [99]: M == M <ipython-input-99-80b3ae713acc>:1: SparseEfficiencyWarning: Comparing sparse matrices using == is inefficient, try using != instead. M == M Out[99]: <3x3 sparse matrix of type '<class 'numpy.bool_'>' with 9 stored elements in Compressed Sparse Row format> In [100]: _.A Out[100]: array([[ True, True, True], [ True, True, True], [ True, True, True]])
请注意,如果 ‘full’ – 所有 9 个值都已设置,则结果。所有这些都暗示 0 的测试是相等的。
2年前