Stable sort for CPU (#50052)
Summary:
Fixes [https://github.com/pytorch/pytorch/issues/38681](https://github.com/pytorch/pytorch/issues/38681) for the CPU.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/50052
Reviewed By: mrshenli
Differential Revision: D25900823
Pulled By: glaringlee
fbshipit-source-id: 1a3fa336037d0aa2344d79f46dcacfd478a353d1