diff --git a/pytorch_lightning/trainer/distrib_parts.py b/pytorch_lightning/trainer/distrib_parts.py index d5217c8951..7abf987d5c 100644 --- a/pytorch_lightning/trainer/distrib_parts.py +++ b/pytorch_lightning/trainer/distrib_parts.py @@ -526,6 +526,9 @@ class TrainerDPMixin(ABC): if isinstance(device_ids, int): device_ids = list(range(device_ids)) + # set dp device + torch.cuda.set_device(self.root_gpu) + model = LightningDataParallel(model, device_ids=device_ids) self.run_pretrain_routine(model) diff --git a/pytorch_lightning/trainer/trainer.py b/pytorch_lightning/trainer/trainer.py index dca3df6a06..dca3d53928 100644 --- a/pytorch_lightning/trainer/trainer.py +++ b/pytorch_lightning/trainer/trainer.py @@ -389,6 +389,7 @@ class Trainer( self.gpus = gpus self.data_parallel_device_ids = parse_gpu_ids(self.gpus) self.root_gpu = determine_root_gpu_device(self.data_parallel_device_ids) + self.root_device = torch.device("cpu") # tpu state flags self.use_tpu = False