Skip to content

Commit

Permalink
Update tpu_spawn.py
Browse files Browse the repository at this point in the history
  • Loading branch information
four4fish committed Dec 1, 2021
1 parent 4e9d9f0 commit 72fc1d9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pytorch_lightning/plugins/training_type/tpu_spawn.py
Expand Up @@ -131,9 +131,10 @@ def _move_optimizer_state(self, device: Optional[torch.device] = None) -> None:
"""Moves the state of the optimizers to the TPU if needed."""
# TODO: `self.root_device` would raise error if called outside the spawn process
# while training on 8 and more cores.
device = device or self.root_device
for opt in self.optimizers:
for p, v in opt.state.items():
opt.state[p] = apply_to_collection(v, torch.Tensor, move_data_to_device, xm.xla_device())
opt.state[p] = apply_to_collection(v, torch.Tensor, move_data_to_device, device)

def _setup_model(self, model: Module) -> Module:
return model
Expand Down

0 comments on commit 72fc1d9

Please sign in to comment.