Skip to content

Commit

Permalink
Add changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
four4fish committed Dec 1, 2021
1 parent 4c8ba27 commit d70cac3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -188,6 +188,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Removed argument `return_result` from the `DDPSpawnPlugin.spawn()` method ([#10867](https://github.com/PyTorchLightning/pytorch-lightning/pull/10867))


- Removed unnessesary `_move_optimizer_state` method overrides from `TPUSpawnPlugin` and `SingleTPUPlugin` ([#10849](https://github.com/PyTorchLightning/pytorch-lightning/pull/10849))


### Fixed

- Fixed an issue with `SignalConnector` not restoring the default signal handlers on teardown when running on SLURM or with fault-tolerant training enabled ([#10611](https://github.com/PyTorchLightning/pytorch-lightning/pull/10611))
Expand Down
13 changes: 1 addition & 12 deletions pytorch_lightning/plugins/training_type/tpu_spawn.py
Expand Up @@ -33,7 +33,7 @@
from pytorch_lightning.trainer.connectors.data_connector import DataConnector
from pytorch_lightning.trainer.states import TrainerFn
from pytorch_lightning.utilities import _TPU_AVAILABLE, find_shared_parameters, rank_zero_warn, set_shared_parameters
from pytorch_lightning.utilities.apply_func import apply_to_collection, move_data_to_device
from pytorch_lightning.utilities.apply_func import move_data_to_device
from pytorch_lightning.utilities.data import has_len
from pytorch_lightning.utilities.distributed import rank_zero_only, ReduceOp
from pytorch_lightning.utilities.exceptions import MisconfigurationException
Expand Down Expand Up @@ -128,17 +128,6 @@ def setup(self, trainer: "pl.Trainer") -> None:
self.setup_optimizers(trainer)
self.setup_precision_plugin()

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.
if device:
raise ValueError(f"device should be None" f" found: {device}.")
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, device)

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

Expand Down
Expand Up @@ -108,10 +108,9 @@ def setup_precision_plugin(self) -> None:

def _move_optimizer_state(self, device: Optional[torch.device] = None) -> None:
"""Moves the state of the optimizers to the GPU if needed."""
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, device)
opt.state[p] = apply_to_collection(v, torch.Tensor, move_data_to_device, device or self.root_device)

def optimizer_state(self, optimizer: Optimizer) -> Dict[str, Tensor]:
"""Returns state of an optimizer.
Expand Down

0 comments on commit d70cac3

Please sign in to comment.