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

Always use trainer.call_hook #8498

Merged
merged 36 commits into from
Aug 20, 2021
Merged

Conversation

carmocca
Copy link
Contributor

@carmocca carmocca commented Jul 20, 2021

What does this PR do?

Always try to use trainer.call_hook to call hooks as we need it to set the _current_fx_name attribute in the LightningModule which is required for logging.

Since call_hook also calls any trainer and accelerator methods with the same name, we need to skip them for setup and teardown.

A test is added which tries to self.log() in all LightningModule and Callback hooks to assert that MisconfigurationException is raised.

Part of #7898

Follow-ups

  • The new test could assert the final logged values.
  • We should refactor call_hook. The current pattern of always calling the accelerator and trainer hooks of the same name is dangerous. Also, we want the users to interact with it after loop customization. [RFC] Re-design call_hook interface #8506

Does your PR introduce any breaking changes ? If yes, please list them.

None intended

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • 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?
  • [n/a] Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)
  • Did you list all the breaking changes introduced by this pull request?

PR review

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

@carmocca carmocca added bug Something isn't working logging Related to the `LoggerConnector` and `log()` labels Jul 20, 2021
@carmocca carmocca added this to the v1.4 milestone Jul 20, 2021
@carmocca carmocca self-assigned this Jul 20, 2021
@codecov
Copy link

codecov bot commented Jul 20, 2021

Codecov Report

Merging #8498 (e97c094) into master (d0efb55) will decrease coverage by 4%.
The diff coverage is 98%.

@@           Coverage Diff           @@
##           master   #8498    +/-   ##
=======================================
- Coverage      93%     89%    -4%     
=======================================
  Files         172     172            
  Lines       14093   14092     -1     
=======================================
- Hits        13095   12514   -581     
- Misses        998    1578   +580     

@carmocca carmocca marked this pull request as ready for review July 20, 2021 22:08
@carmocca carmocca marked this pull request as draft July 20, 2021 22:40
pytorch_lightning/trainer/data_loading.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/trainer.py Outdated Show resolved Hide resolved
@mergify mergify bot removed the has conflicts label Aug 6, 2021
Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

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

this will disable usage tracing in IDE, right?

@carmocca
Copy link
Contributor Author

carmocca commented Aug 9, 2021

this will disable usage tracing in IDE, right?

Yes, this was already the case. Most hooks are already using call_hook

If you have ideas about how to improve that, you can comment in #8506

@mergify mergify bot removed the has conflicts label Aug 10, 2021
@carmocca carmocca requested review from tchaton and Borda August 10, 2021 12:47
@mergify mergify bot removed the has conflicts label Aug 16, 2021
@mergify mergify bot added the ready PRs ready to be merged label Aug 16, 2021
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 ! Great work !

pytorch_lightning/trainer/trainer.py Show resolved Hide resolved
@carmocca carmocca merged commit e1442d2 into master Aug 20, 2021
@carmocca carmocca deleted the bugfix/call-hook-standardization branch August 20, 2021 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working logging Related to the `LoggerConnector` and `log()` ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants