[ptd] Fix test config in destroy_pg (#166463)

Summary: When device_type is CPU we will not use device id from CUDA which is enabled in https://github.com/pytorch/pytorch/pull/161015. However, we should not exclude the case when the accelerator itself is CPU. This PR fixes it.

Test Plan: UT

Differential Revision: D85714901

Pull Request resolved: https://github.com/pytorch/pytorch/pull/166463
Approved by: https://github.com/mori360, https://github.com/fegin
This commit is contained in:
Junjie Wang (PyTorch) 2025-10-29 04:35:01 +00:00 committed by PyTorch MergeBot
parent 0e19561e23
commit 774abb018e

View File

@ -447,7 +447,7 @@ class DTensorTestBase(MultiProcessTestCase):
torch.cuda.current_device() if self.device_type == "cuda" else self.rank
)
if self.device_type == "cpu" and torch._C._get_accelerator().type != "cpu":
if self.device_type == "cpu":
# NOTE: when `device_id` is not None, barrier() will choose the accelerator
# of the most pripority, which means if the test specifies to use CPU for
# testing while CUDA is available on the host, the barrier() will use CUDA.