1)concatenate tensors into tensor C
2)stable sort C on CPU, keep indices
3)do torch.unique_consecutive, return counts & indices
4)select indices where count is 2
5)map indices back to indices in C, due to stable sort they should only point to the first tensor (a)
disclaimer: I haven’t done this in practice