In that case, I would just sample the values using torch.multinomial:
x = torch.tensor([2, 3, 2, 1, 2, 3, 2])
unique = torch.unique(x)
weight = x.unsqueeze(0) == unique.unsqueeze(1)
torch.multinomial(weight.float(), num_samples=1)