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

How optimizer frequencies works #3481

Closed
7rick03ligh7 opened this issue Sep 12, 2020 · 10 comments
Closed

How optimizer frequencies works #3481

7rick03ligh7 opened this issue Sep 12, 2020 · 10 comments
Labels
question Further information is requested

Comments

@7rick03ligh7
Copy link

❓ Questions and Help

What is your question?

I don't understand how optimizer frequencies works
#1269

Code

When I tried to work with them as a list of optimizers, I got this error
It arises after training_step()
image

What's your environment?

  • OS: [Win]
  • Packaging [conda]
  • Version [0.9.0]

P.S.

If you have a pytorch-lightning WGAN implementation or something with n_critics I would appreciate if you could share )

@7rick03ligh7 7rick03ligh7 added the question Further information is requested label Sep 12, 2020
@rohitgr7
Copy link
Contributor

it's fixed on master #3229

@7rick03ligh7
Copy link
Author

@rohitgr7
Oh, thanks
But... How can I install from master in conda?

@awaelchli
Copy link
Contributor

pip install --upgrade git+https://github.com/PyTorchLightning/pytorch-lightning.git in your conda env

@7rick03ligh7
Copy link
Author

7rick03ligh7 commented Sep 13, 2020

Ok, but I'm still interested in the sequence of function calls.

  1. Am I right that the pseudocode with multiple optimizers looks like this?
    image

  2. If I use multiple optimizers with different outputs in training_step() how it will work in training_epoch_end()? I mean how I can aggregate outputs only from the first optimizer and something like that. In other words, how structured outputs from different optimizers in training_epoch_end()
    image

  3. How progress_bar will change with multiple optimizers and different outputs?
    For example:
    optimizer_idx == 0 will HAVE a 'acc' output, which will be monitored
    optimizer_idx == 1 will NOT HAVE a 'acc' output

@awaelchli
Copy link
Contributor

  1. I think yes, this is roughly it
  2. With multiple optimizers, you will get a list of lists in training_epoch_end. If using Results, you get List[List[Result]] and with dict you get List[List[dict]]. The top list has length equal to the number of optimizers. The inner list has length equal to the number of training steps.
  3. Don't know, never tried it, but I would assume the progress bar dict gets merged.

@7rick03ligh7
Copy link
Author

@awaelchli
Thanks for the reply

I tried it and got this:
image
All outputs from optimizers sent to a single list
Remind that I used frequencies (opt1 freq=1, opt2 freq=4)

Is it ok, or it's a bug?

@rohitgr7
Copy link
Contributor

@7rick03ligh7
if you are using multiple optimizers with no frequencies defined you will get:

With multiple optimizers, you will get a list of lists in training_epoch_end. If using Results, you get List[List[Result]] and with dict you get List[List[dict]]. The top list has a length equal to the number of optimizers. The inner list has a length equal to the number of training steps.

but, when you have some frequencies defined, each training_step will use only 1 optimizer depending upon the current training_step, and outputs from the other step with different optimizer won't be transferred. So you will have a list with the size equal to the number of training_steps.

Your output is excepted so it's not a bug.

@awaelchli
Copy link
Contributor

@rohitgr7 yes! subtle difference there, but very important! this is indeed working as intended.
@7rick03ligh7 for reference, what @rohitgr7 explained is also written here in the "Note" section:
https://pytorch-lightning.readthedocs.io/en/latest/api/pytorch_lightning.core.html#pytorch_lightning.core.LightningModule.configure_optimizers

@7rick03ligh7
Copy link
Author

@awaelchli yeah, but in the documentation, it is not clear that with frequencies the outputs will be in a single list (at least for me)

@7rick03ligh7
Copy link
Author

@awaelchli
@rohitgr7

Anyway, thanks for your replies)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants