Ensure local_used_maps_tmp is distinct from local_used_maps_[i] (#54474)
Summary:
Followup/hotfix for https://github.com/pytorch/pytorch/pull/53160. rohan-varma and zhaojuanmao were seeing https://github.com/pytorch/pytorch/pull/53160/files#diff-9273e5ff7b40f30d6a4444d1c7be9fe9a5c2068070c68af4e7b0ac2d4cff0923R582 fire in some internal workloads, indicating `local_used_maps_tmp` wasn't actually being created as a distinct temporary, in other words, `local_used_maps_[i]` was already pinned for some reason. This seems like a bug with the CPU allocator: [`local_used_maps_` should not have been pinned on construction](https://github.com/pytorch/pytorch/blob/9be4c75fa0399a292e95ef8f3c79457e4b5b2338/torch/lib/c10d/reducer.cpp#L180-L183). We should [investigate that separately](https://github.com/pytorch/pytorch/pull/53160/files#r599188373).
In the meantime, the present PR should ensure `local_used_maps_tmp` is always distinct from `local_used_maps_[i]` (and therefore prevents the race condition described in https://github.com/pytorch/pytorch/pull/51360) even if `local_used_maps_[i]`is already pinned.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/54474
Reviewed By: zhaojuanmao
Differential Revision: D27268039
Pulled By: rohan-varma
fbshipit-source-id: ab9af3dd845098bde788cb28a9217caea246ddfa