Hi, all!
Trying to circumvent another apparent bug in PyTorch.
This might be related to this post (which was never fully resolved).
Relevant code fragment (with print statements for debugging, mask
is also made for debugging):
mask = torch.where(graph_clusters_i == cluster_id, torch.ones_like(graph_clusters_i), torch.zeros_like(graph_clusters_i))
index_equals_cluster_id = torch.where(graph_clusters_i == cluster_id)
print("mask.sum()......................: ", mask.sum())
print("type(graph_clusters_i)..........: ", type(graph_clusters_i))
print("graph_clusters_i.shape..........: ", graph_clusters_i.shape)
print("graph_clusters_i.device.........: ", graph_clusters_i.device)
print("type(cluster_id)................: ", type(cluster_id))
print("cluster_id......................: ", cluster_id)
print("len(index_equals_cluster_id)....: ", len(index_equals_cluster_id))
print("type(index_equals_cluster_id)...: ", type(index_equals_cluster_id))
print("type(index_equals_cluster_id[0]): ", type(index_equals_cluster_id[0]))
print("index_equals_cluster_id[0].shape: ", index_equals_cluster_id[0].shape)
x = index_equals_cluster_id[0].tolist() # <-- error here!
The output is:
mask.sum()…: tensor(939, device=‘cuda:0’)
type(graph_clusters_i)…: <class ‘torch.Tensor’>
graph_clusters_i.shape…: torch.Size([1165, 1])
graph_clusters_i.device…: cuda:0
type(cluster_id)…: <class ‘int’>
cluster_id…: 0
len(index_equals_cluster_id)…: 2
type(index_equals_cluster_id)…: <class ‘tuple’>
type(index_equals_cluster_id[0]): <class ‘torch.Tensor’>
index_equals_cluster_id[0].shape: torch.Size([-2133151913])
Traceback (most recent call last):
(A few lines omitted for brevity>)
File “/home/algomorph/.local/lib/python3.8/site-packages/torch/nn/modules/module.py”, line 889, in _call_impl
result = self.forward(*input, **kwargs)
File “/home/algomorph/Workbench/NeuralTracking/model/model.py”, line 437, in forward
x = index_equals_cluster_id[0].tolist() # ← error here!
RuntimeError: Trying to create tensor with negative dimension -2133151913: [-2133151913]
Any idea about how to fix or avoid this?