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

[IPU] Call accelerator hooks regardless if LM hook overridden 1/n #7826

Merged
merged 6 commits into from
Jun 4, 2021

Conversation

SeanNaren
Copy link
Contributor

@SeanNaren SeanNaren commented Jun 3, 2021

What does this PR do?

When defining a new accelerator, I noticed that some hooks were not called by the Trainer unless if the hook was overridden in the LightningModule.

We now call all hooks, and the edge case for DP where a reduction is necessary if the user doesn't do it themselves is now handled in the DP plugin. I don't think any tests were required, as all hooks are already tested.

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?
  • 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)

PR review

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • 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

Did you have fun?

Make sure you had fun coding 🙃

@SeanNaren SeanNaren added the feature Is an improvement or enhancement label Jun 3, 2021
@SeanNaren SeanNaren added this to the v1.4 milestone Jun 3, 2021
@SeanNaren SeanNaren self-assigned this Jun 3, 2021
@codecov
Copy link

codecov bot commented Jun 3, 2021

Codecov Report

Merging #7826 (f28d388) into master (51d370f) will decrease coverage by 0%.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           master   #7826   +/-   ##
======================================
- Coverage      93%     92%   -0%     
======================================
  Files         202     202           
  Lines       13042   13050    +8     
======================================
- Hits        12077   12047   -30     
- Misses        965    1003   +38     

Comment on lines -1240 to -1241
# if the PL module doesn't have the hook then call the accelerator
# used to auto-reduce things for the user with Results obj
Copy link
Contributor

@awaelchli awaelchli Jun 4, 2021

Choose a reason for hiding this comment

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

one example is training_step_end for DP which is handled in the plugin. If user doesn't do the reduction we do it in the accelerator. But now with the change, if the user has it overridden you still call training_step_end on the DP plugin which will do another automatic reduction.

@@ -101,10 +102,16 @@ def predict_step(self, *args, **kwargs):
return self.model(*args, **kwargs)

def training_step_end(self, output):
return self.reduce(output)
if not is_overridden("training_step_end", self.lightning_module):
Copy link
Contributor

Choose a reason for hiding this comment

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

@SeanNaren this check for DP should take care of the previous rule we had: only auto reduce if user did not do it themself.

@SeanNaren SeanNaren marked this pull request as ready for review June 4, 2021 10:57
@SeanNaren SeanNaren changed the title [WIP] Call accelerator hooks regardless if overridden 1/n Call accelerator hooks regardless if overridden 1/n Jun 4, 2021
@SeanNaren SeanNaren changed the title Call accelerator hooks regardless if overridden 1/n Call accelerator hooks regardless if LM hook overridden 1/n Jun 4, 2021
@SeanNaren SeanNaren changed the title Call accelerator hooks regardless if LM hook overridden 1/n Call accelerator hooks regardless if LM hook overridden IPU 1/n Jun 4, 2021
@SeanNaren SeanNaren changed the title Call accelerator hooks regardless if LM hook overridden IPU 1/n [IPU] Call accelerator hooks regardless if LM hook overridden 1/n Jun 4, 2021
Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

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

LGTM. I think this solution is an okay compromise between a quick fix and a slow refactor.

pytorch_lightning/trainer/trainer.py Outdated Show resolved Hide resolved
Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com>
pytorch_lightning/trainer/trainer.py Outdated Show resolved Hide resolved
@SeanNaren SeanNaren enabled auto-merge (squash) June 4, 2021 13:59
@SeanNaren SeanNaren disabled auto-merge June 4, 2021 15:04
@SeanNaren SeanNaren enabled auto-merge (squash) June 4, 2021 15:04
@mergify mergify bot added the has conflicts label Jun 4, 2021
@mergify mergify bot removed the has conflicts label Jun 4, 2021
# used to auto-reduce things for the user with Results obj
elif hasattr(self.accelerator, hook_name):
# call the accelerator hook
if hasattr(self.accelerator, hook_name):
Copy link
Contributor

@ananthsub ananthsub Jun 4, 2021

Choose a reason for hiding this comment

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

I feel less comfortable adding more dependencies to call_hook. this glues together calling code across 3 distinct interfaces: callback hooks, model hooks, and accelerator hooks. what happens if one takes different arguments? or if we need to call them in different orders?

separately (unrelated to this PR) we're aggregating all of these hooks together in the profiling results. the model/callbacks/accelerator could all have different behavior. i think it's worth splitting out these into separate profiling sections to give provide more fine-grained visibility

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, the accelerator hooks shouldn't be a part of call_hook.

Also agree on the profiling comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks @ananthsub!

For the IPU integration we'll be moving as is, but after I want to remove this logic for the accelerators from this call, and call them explicitly through the loop functions as this can foster some nasty bugs as you suggested. Does that sound fair?

Copy link
Contributor

Choose a reason for hiding this comment

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

@SeanNaren that sounds good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants