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

passing batch outputs to on_train_batch_end #4369

Merged
merged 19 commits into from
Jan 26, 2021

Conversation

swethmandava
Copy link
Contributor

@swethmandava swethmandava commented Oct 26, 2020

What does this PR do?

Passes batch outputs to on_train_batch_end instead of epoch end outputs

Fixes #4326

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together? Otherwise, we ask you to create a separate PR for every change.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

PR review

  • [Y] Is this pull request ready for review? (if not, please submit in draft mode)

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@pep8speaks
Copy link

pep8speaks commented Oct 26, 2020

Hello @swethmandava! Thanks for updating this PR.

Line 256:85: W504 line break after binary operator

Line 140:121: E501 line too long (121 > 120 characters)

Comment last updated at 2021-01-26 12:16:43 UTC

@mergify mergify bot requested a review from a team October 26, 2020 13:19
@edenlightning
Copy link
Contributor

Thanks for the PR!

Please take a second look as it seems test are failing...

@edenlightning edenlightning added this to the 1.0.x milestone Oct 27, 2020
@rohitgr7 rohitgr7 self-requested a review October 27, 2020 14:31
@Borda
Copy link
Member

Borda commented Nov 3, 2020

@swethmandava could you please check failing tests and also add a test for this change?

@Borda Borda added the waiting on author Waiting on user action, correction, or update label Nov 3, 2020
@edenlightning edenlightning modified the milestones: 1.0.x, 1.0.7 Nov 10, 2020
@Borda Borda modified the milestones: 1.0.7, 1.0.x Nov 11, 2020
@swethmandava
Copy link
Contributor Author

@Borda @edenlightning fixed pytest errors. it now fails with /bin/bash: /root/miniconda3/envs/lightning/lib/libtinfo.so.6: no version information available (required by /bin/bash) seems to be conda version related - can you help?

@BotScutters
Copy link

Hey all, I'm working on a callback that would generate a plot of model outputs each epoch and encountering an issue that appears to be related to this. I'd expect I should be able to grab the model outputs from the outputs arg of on_training_batch_end, on_validation_batch_end, etc., but this shows comes in as None. A bit of googling brought me here, and it seems this issue has gone a little stale.

Is this issue still being worked on? If not, is there a suggested workaround? Thanks!

@swethmandava
Copy link
Contributor Author

swethmandava commented Jan 14, 2021

@SeanNaren @tchaton can this be merged?

@s-rog s-rog linked an issue Jan 15, 2021 that may be closed by this pull request
Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to have a test ?

@SeanNaren
Copy link
Contributor

Apologies for the stale! A simple boring model test that ensures that if the user overrides this hook, they retrieve the appropriate model outputs would be nice :)

Similar to this: https://github.com/PyTorchLightning/pytorch-lightning/blob/master/tests/models/test_hooks.py#L52

thanks for working on this!

batch_output.training_step_output_for_epoch_end,
self.early_stopping_accumulator,
self.checkpoint_accumulator,
)

# hook
# TODO: add outputs to batches
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyone knows what this todo means?

@swethmandava
Copy link
Contributor Author

Apologies for the stale! A simple boring model test that ensures that if the user overrides this hook, they retrieve the appropriate model outputs would be nice :)

Similar to this: https://github.com/PyTorchLightning/pytorch-lightning/blob/master/tests/models/test_hooks.py#L52

thanks for working on this!

Done!

Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

@SeanNaren SeanNaren added the ready PRs ready to be merged label Jan 26, 2021
@Borda Borda requested a review from awaelchli January 26, 2021 12:49
@SeanNaren SeanNaren merged commit 5fcca4e into Lightning-AI:master Jan 26, 2021
@SeanNaren
Copy link
Contributor

Thanks @swethmandava for doing this and apologies on the delay, fell through the cracks a few times...


class LoggingCallback(pl.Callback):

def on_train_epoch_end(self, trainer, pl_module):
Copy link
Member

@Borda Borda Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SeanNaren flake8 found this bug, but it was still merged, could pls fix it in #5666
most likely on_train_epoch_end >> on_train_epoch_start as *_end is here twice

@Borda Borda mentioned this pull request Jan 26, 2021
12 tasks
Borda pushed a commit that referenced this pull request Feb 4, 2021
* passing batch outputs to on_train_batch_end

* styling

* updating epoch end logic

* also condition on on_train_epoch_end hooks

* more readable

* pep8

* pep8

* readability suggestion accepted

Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>

* adding test_training_epoch_end_metrics_collection_on_override test

* fix formatting

* fix formatting

Co-authored-by: Swetha Mandava <smandava@nvidia.com>
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Co-authored-by: Sean Naren <sean.narenthiran@gmail.com>
Co-authored-by: Roger Shieh <sh.rog@protonmail.ch>

(cherry picked from commit 5fcca4e)
Borda pushed a commit that referenced this pull request Feb 4, 2021
* passing batch outputs to on_train_batch_end

* styling

* updating epoch end logic

* also condition on on_train_epoch_end hooks

* more readable

* pep8

* pep8

* readability suggestion accepted

Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>

* adding test_training_epoch_end_metrics_collection_on_override test

* fix formatting

* fix formatting

Co-authored-by: Swetha Mandava <smandava@nvidia.com>
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Co-authored-by: Sean Naren <sean.narenthiran@gmail.com>
Co-authored-by: Roger Shieh <sh.rog@protonmail.ch>

(cherry picked from commit 5fcca4e)
Borda pushed a commit that referenced this pull request Feb 4, 2021
* passing batch outputs to on_train_batch_end

* styling

* updating epoch end logic

* also condition on on_train_epoch_end hooks

* more readable

* pep8

* pep8

* readability suggestion accepted

Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>

* adding test_training_epoch_end_metrics_collection_on_override test

* fix formatting

* fix formatting

Co-authored-by: Swetha Mandava <smandava@nvidia.com>
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Co-authored-by: Sean Naren <sean.narenthiran@gmail.com>
Co-authored-by: Roger Shieh <sh.rog@protonmail.ch>

(cherry picked from commit 5fcca4e)
Borda pushed a commit that referenced this pull request Feb 4, 2021
* passing batch outputs to on_train_batch_end

* styling

* updating epoch end logic

* also condition on on_train_epoch_end hooks

* more readable

* pep8

* pep8

* readability suggestion accepted

Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>

* adding test_training_epoch_end_metrics_collection_on_override test

* fix formatting

* fix formatting

Co-authored-by: Swetha Mandava <smandava@nvidia.com>
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Co-authored-by: Sean Naren <sean.narenthiran@gmail.com>
Co-authored-by: Roger Shieh <sh.rog@protonmail.ch>

(cherry picked from commit 5fcca4e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working design Includes a design discussion ready PRs ready to be merged refactor
Projects
None yet
9 participants