diff --git a/src/transformers/sagemaker/training_args_sm.py b/src/transformers/sagemaker/training_args_sm.py index 7328a831b979..6be0deb1f479 100644 --- a/src/transformers/sagemaker/training_args_sm.py +++ b/src/transformers/sagemaker/training_args_sm.py @@ -77,7 +77,7 @@ def __post_init__(self): @cached_property def _setup_devices(self) -> "torch.device": logger.info("PyTorch: setting up devices") - if torch.distributed.is_initialized() and self.local_rank == -1: + if torch.distributed.is_available() and torch.distributed.is_initialized() and self.local_rank == -1: logger.warning( "torch.distributed process group is initialized, but local_rank == -1. " "In order to use Torch DDP, launch your script with `python -m torch.distributed.launch" diff --git a/src/transformers/training_args.py b/src/transformers/training_args.py index adaf50da8ffe..68efcbd5cf1c 100644 --- a/src/transformers/training_args.py +++ b/src/transformers/training_args.py @@ -1032,7 +1032,7 @@ def eval_batch_size(self) -> int: @torch_required def _setup_devices(self) -> "torch.device": logger.info("PyTorch: setting up devices") - if torch.distributed.is_initialized() and self.local_rank == -1: + if torch.distributed.is_available() and torch.distributed.is_initialized() and self.local_rank == -1: logger.warning( "torch.distributed process group is initialized, but local_rank == -1. " "In order to use Torch DDP, launch your script with `python -m torch.distributed.launch"