Finally, I got PyTorch itself to admit there is some kind of bug here. Not sure how to report it though, because it’s a hell of a lot of code to get down to a minimal reproducible example.
The code:
index_equals_cluster_id = torch.where(graph_clusters_i == cluster_id)
dummy = index_equals_cluster_id[0].sum()  # This triggers some kind of bug

Output:

Traceback (most recent call last):
(Some intermediate calls 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 442, in forward
dummy = index_equals_cluster_id[0].sum()   # This triggers some kind of bug
RuntimeError: iter.numel() > 0 && iter.ntensors() - iter.noutputs() == 1 && iter.noutputs() >= 1 INTERNAL ASSERT FAILED at “/pytorch/aten/src/ATen/native/cuda/Reduce.cuh”:896, please report a bug to PyTorch.