For anyone who stumbles over this thread again, a small modification to @smth 's answer works:
import torch
x = torch.tensor([1, 2, 2, 3])
uq_vals,inverse_ixs,counts = torch.unique(x, sorted=True, return_inverse=True,return_counts=True)
cumsum_counts = counts.cumsum(dim=0)
possible_ranks = torch.zeros_like(counts)
possible_ranks[1:] = cumsum_counts[:-1]
ranks = possible_ranks[inverse_ixs]
print(x,
      ranks)