【发布时间】:2021-11-08 04:06:23
【问题描述】:
我有一个无法解决的问题...我阅读了 Pytorch 文档以摆脱这个问题,但我的代码看起来不错,但发生了错误。
indices = ...
X = ...
Y = ...
print(torch.min(indices)) # tensor(0, device='cuda:0')
print(torch.max(indices)) # tensor(30, device='cuda:0')
print(indices.dtype) # torch.int64
print(indices.shape) # torch.Size([498])
print(X.shape) # torch.Size([498, 2048])
print(X.dtype) # torch.float32
print(Y.shape) # torch.Size([31, 2048])
print(Y.dtype) # torch.float32
Y = Y.index_add(0, indices, X)
index_add 的调用导致:
RuntimeError: number of dims don't match in permute
我做错了什么?提前谢谢你。
编辑: 来自文档:
张量的第dim维度必须与长度相同 索引(必须是向量),并且所有其他维度必须匹配 self,否则将引发错误。
在这种情况下dim=0 tensor=X self=Y 并且遵循X.shape[0] 应该等于len(indices) 并且X.shape[1] 应该等于Y.shape[1],就是这样......它可能是一个pytorch错误吗?
编辑2: 该错误仅针对特定的张量值并使用:
torch.use_deterministic_algorithms(True)
torch.manual_seed(1234)
所以应该是pytorch的bug。
【问题讨论】:
-
你能提供一个完全可重现的错误代码吗?使用种子和特定张量。
标签: python pytorch runtime-error