It certainly isn’t an efficient way memory-wise, but you might check, if it would yield a speed up compute-wise:
a = torch.tensor([[1,2], [4,5], [7,8]])
b = torch.tensor([[2,3], [7,5], [-1,7]])

ret = a.view(-1, 1, 1) == b
idx = torch.arange(3).unsqueeze(1).expand(-1, 2).reshape(-1)
print(ret[torch.arange(ret.size(0)), idx])
> tensor([[False, False],
          [ True, False],
          [False, False],
          [False,  True],
          [False,  True],
          [False, False]])