Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleaning SWA #6259

Merged
merged 6 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Changed the order of `backward`, `step`, `zero_grad` to `zero_grad`, `backward`, `step` ([#6147](https://github.com/PyTorchLightning/pytorch-lightning/pull/6147))


- Renamed `pytorch_lightning.callbacks.swa` to `pytorch_lightning.callbacks.stochastic_weight_avg` ([#6259](https://github.com/PyTorchLightning/pytorch-lightning/pull/6259))


### Deprecated


Expand Down
2 changes: 1 addition & 1 deletion pytorch_lightning/callbacks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from pytorch_lightning.callbacks.progress import ProgressBar, ProgressBarBase
from pytorch_lightning.callbacks.pruning import ModelPruning
from pytorch_lightning.callbacks.quantization import QuantizationAwareTraining
from pytorch_lightning.callbacks.swa import StochasticWeightAveraging
from pytorch_lightning.callbacks.stochastic_weight_avg import StochasticWeightAveraging

__all__ = [
'BackboneFinetuning',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,10 @@ def __init__(
if isinstance(swa_epoch_start, float) and not (0 <= swa_epoch_start <= 1):
raise MisconfigurationException(err_msg)

if (
swa_lrs is not None and (
not isinstance(swa_lrs, (float, list)) or isinstance(swa_lrs, float) and swa_lrs <= 0
or isinstance(swa_lrs, list) and not all(lr > 0 and isinstance(lr, float) for lr in swa_lrs)
)
):
_wrong_type = not isinstance(swa_lrs, (float, list))
_wrong_float = isinstance(swa_lrs, float) and swa_lrs <= 0
_wrong_list = isinstance(swa_lrs, list) and not all(lr > 0 and isinstance(lr, float) for lr in swa_lrs)
if (swa_lrs is not None and (_wrong_type or _wrong_float or _wrong_list)):
Borda marked this conversation as resolved.
Show resolved Hide resolved
raise MisconfigurationException("The `swa_lrs` should be a positive float or a list of positive float.")

if avg_fn is not None and not isinstance(avg_fn, Callable):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _configure_swa_callbacks(self):
if not self.trainer._stochastic_weight_avg:
return

from pytorch_lightning.callbacks.swa import StochasticWeightAveraging
from pytorch_lightning.callbacks.stochastic_weight_avg import StochasticWeightAveraging
existing_swa = [cb for cb in self.trainer.callbacks if isinstance(cb, StochasticWeightAveraging)]
if not existing_swa:
self.trainer.callbacks = [StochasticWeightAveraging()] + self.trainer.callbacks
Expand Down