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

training multiple optimizers with different frequency #3234

Closed
amit-ruf opened this issue Aug 27, 2020 · 3 comments · Fixed by #3229
Closed

training multiple optimizers with different frequency #3234

amit-ruf opened this issue Aug 27, 2020 · 3 comments · Fixed by #3229
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@amit-ruf
Copy link

Hi,
I believe there's a small bug in training_loop.py line @

782 which seems to crash my WGAN trainer, having 3 optimizers.

Details:
Take a look at training_loop.py @ line 872:
batch_outputs[opt_idx].append(opt_closure_result.training_step_output_for_epoch_end)

opt_idx should point to the optimizer index (0,1,2 in my case) and batch_outputs should be a list of length 3 (in my application).
However, batch_outputs is initialized to a list @ line 818:
batch_outputs = [[] for i in range(len(self._get_optimizers_iterable()))]
If self.optimizer_frequencies is defined then the output of _self.get_optimizers_iterable will be a list of a single tuple, therefore batch_outputs shall be a list with a single item only and the loop will fail @ line 872 due to out of index error.

Fix:
@ line 872 replace with:
batch_outputs = [[] for i in range(len(self.optimizers))]
replace line 561 with:
if optimizer_idx_outputs:
sample_output = optimizer_idx_outputs[-1]
else:
sample_output = None

Attached is a modified training_loop.py
Unfortunately, I don't have a minimal example to replicate the bug and I can't publish my full training testbench.

@github-actions
Copy link
Contributor

Hi! thanks for your contribution!, great first issue!

@rohitgr7
Copy link
Contributor

Duplicate #3143

@awaelchli awaelchli added bug Something isn't working duplicate This issue or pull request already exists labels Aug 27, 2020
@awaelchli awaelchli linked a pull request Aug 27, 2020 that will close this issue
7 tasks
@awaelchli awaelchli changed the title probably a bug: training multiple optimizers with different frequency training multiple optimizers with different frequency Aug 27, 2020
@awaelchli
Copy link
Contributor

#3229 will fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants