[PyTorch] Implement improved version of gather_ranges_to_dense (#66677)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/66677
Reviewed By: wfanzju
Differential Revision: D31676536
fbshipit-source-id: a2eb1b1f9e5a0b78f89c3aad19f97acb7c05e1f8