guard torch distributed check (#39057)

* guard torch distributed check

* Update src/transformers/pipelines/base.py

---------

Co-authored-by: Matt <Rocketknight1@users.noreply.github.com>
This commit is contained in:
Tijana Vukovic 2025-06-27 16:49:47 +02:00 committed by GitHub
parent 49d9fd49bd
commit c8764ab935
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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