def to_gpu(self, gpu_ids: Union[int, list, ]): if isinstance(gpu_ids, int): gpu_ids = [gpu_ids] self.gpu_ids = gpu_ids self.device = (torch.device('cuda', self.gpu_ids[0]) if self.gpu_ids[0] >= 0 else torch.device('cpu')) self.net.to(self.device) if self.optimizer is not None: move_optim(self.optimizer, self.device)
def to_gpu(self, gpu_ids: Union[int, list, ]) -> None: """Move network to specified GPU(s). Parameters ---------- gpu_ids GPU(s) on which to perform training or prediction. """ if isinstance(gpu_ids, int): gpu_ids = [gpu_ids] self.gpu_ids = gpu_ids self.device = (torch.device('cuda', self.gpu_ids[0]) if self.gpu_ids[0] >= 0 else torch.device('cpu')) self.net.to(self.device) if self.optimizer is not None: move_optim(self.optimizer, self.device)