Skip to content

Commit

Permalink
Remove Strategy.optimizer_zero_grad (#11246)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellepintz authored Jan 3, 2022
1 parent 4eede7c commit b082715
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

- Removed `Strategy.init_optimizers` in favor of `Strategy.setup_optimizers` ([#11236](https://github.com/PyTorchLightning/pytorch-lightning/pull/11236))


- Removed `Strategy.optimizer_zero_grad` ([#11246](https://github.com/PyTorchLightning/pytorch-lightning/pull/11246))

### Fixed

- Fixed security vulnerabilities CVE-2020-1747 and CVE-2020-14343 caused by the `PyYAML` dependency ([#11099](https://github.com/PyTorchLightning/pytorch-lightning/pull/11099))
Expand Down
2 changes: 1 addition & 1 deletion pytorch_lightning/loops/optimization/optimizer_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def _optimizer_zero_grad(self, batch_idx: int, optimizer: torch.optim.Optimizer,
optimizer: the current optimizer
opt_idx: the index of the current optimizer
"""
self.trainer._call_strategy_hook(
self.trainer._call_lightning_module_hook(
"optimizer_zero_grad", self.trainer.current_epoch, batch_idx, optimizer, opt_idx
)
self.optim_progress.optimizer.zero_grad.increment_completed()
Expand Down
4 changes: 0 additions & 4 deletions pytorch_lightning/strategies/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,6 @@ def optimizer_step(
model = model or self.lightning_module
self.precision_plugin.optimizer_step(model, optimizer, opt_idx, closure, **kwargs)

def optimizer_zero_grad(self, current_epoch: int, batch_idx: int, optimizer: Optimizer, opt_idx: int) -> None:
"""Zeros all model parameter's gradients."""
self.lightning_module.optimizer_zero_grad(current_epoch, batch_idx, optimizer, opt_idx)

def _setup_model_and_optimizers(self, model: Module, optimizers: List[Optimizer]) -> Tuple[Module, List[Optimizer]]:
"""Setup a model and multiple optimizers together.
Expand Down

0 comments on commit b082715

Please sign in to comment.