Skip to content

Commit

Permalink
Fix Trainer when model is loaded on a different GPU (huggingface#23792)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgugger authored May 31, 2023
1 parent 0963a25 commit 68d53bc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,12 @@ def __init__(
else:
self.is_model_parallel = False

if (
getattr(model, "hf_device_map", None) is not None
and len([device for device in set(model.hf_device_map.values()) if device not in ["cpu", "disk"]]) > 1
and not self.is_model_parallel
):
self.is_model_parallel = True
if getattr(model, "hf_device_map", None) is not None:
devices = [device for device in set(model.hf_device_map.values()) if device not in ["cpu", "disk"]]
if len(devices) > 1:
self.is_model_parallel = True
else:
self.is_model_parallel = self.args.device != torch.device(devices[0])

# warn users
logger.info(
Expand Down

0 comments on commit 68d53bc

Please sign in to comment.