Stable sort for the CPU take 2. (#51790)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/38681.
A duplicate of https://github.com/pytorch/pytorch/pull/50052 created to become importable to the fb internal tests.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51790
Reviewed By: agolynski
Differential Revision: D26279045
Pulled By: glaringlee
fbshipit-source-id: 348e171dee9c370a76002b65d0c82c329f57a421