This code should work:
x = torch.tensor([5,5,3,3,4,4])
x_unique = torch.unique(x, sorted=True)
x_idx = (torch.cat([(x==x_u).nonzero()[0] for x_u in x_unique])).sort()[0]
print(x[x_idx])
> tensor([5, 3, 4])