Thanks for the answer K. Frank!



 KFrank:

If by “the way I said” means to perform your computation with a single
pytorch tensor operation in the presence of duplicate indices


This is indeed what I mean



 KFrank:

In my experience, as with Vainaijr’s observation, “the last addition for
each index, and give 2, not 2.4,” the behavior is as if the result for just
one of a set duplicate indices overwrites the others. Furthermore, I
believe that pytorch makes no guarantee as to which index “wins” so
that your result may change if you move your computation to the gpu
or change the size of your tensors, etc.


It really feels like acting as you describe here, and the more I think about this, the more I feel like there isn’t any clean way of doing this with tensor operations.
I used a workaround specific to my application in order to avoid this issue for now, but I still hope that an expert sees that topic and gives insights as I think that I am not the first to encounter an issue similar to this one.