Make sure torch_is_available before using torch.distributed (#37693)

fix
This commit is contained in:
Mohamed Mekkouri 2025-04-24 11:31:35 +02:00 committed by GitHub
parent 864e9636ff
commit 02baa61fab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -997,7 +997,7 @@ class Pipeline(_ScikitCompat, PushToHubMixin):
else:
self.device = device if device is not None else -1
if torch.distributed.is_initialized():
if is_torch_available() and torch.distributed.is_initialized():
self.device = self.model.device
logger.warning(f"Device set to use {self.device}")