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

Fix user warning produced by apex + scheduler combination #1873

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Fixed

- Fixed user warning when apex was used together with learning rate schedulers ([#1873](https://github.com/PyTorchLightning/pytorch-lightning/pull/1873))

## [0.7.6] - 2020-05-16

### Added
Expand Down
8 changes: 8 additions & 0 deletions pytorch_lightning/trainer/distrib_data_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,14 @@ def ddp_train(self, process_idx, model):
model, optimizers = model.configure_apex(amp, model, self.optimizers, self.amp_level)
self.optimizers = optimizers

# Reinitialize optimizer.step properties added by schedulers
for lr_scheduler in self.lr_schedulers:
SkafteNicki marked this conversation as resolved.
Show resolved Hide resolved
for optimizer in self.optimizers:
scheduler = lr_scheduler['scheduler']
# check that we dont mix users optimizers and schedulers
if scheduler.optimizer == optimizer:
scheduler.__class__.__mro__[-2].__init__(scheduler, optimizer)
SkafteNicki marked this conversation as resolved.
Show resolved Hide resolved

# DDP2 uses all GPUs on the machine
if self.distributed_backend == 'ddp':
device_ids = [self.root_gpu]
Expand Down