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

Remove Strategy.on_tpu property #11536

Merged
merged 3 commits into from
Jan 20, 2022

Conversation

ananthsub
Copy link
Contributor

@ananthsub ananthsub commented Jan 19, 2022

What does this PR do?

Part of #10416

Reasons for removal:

  • This can be deduced from the root_device property. The property on_tpu is redundant yet it's also an abstractmethod. Requiring every strategy class to implement this is boilerplate.
  • We don't offer on_ipu or on_X for existing accelerator implementations
  • Given the Accelerator is also customizable/pluggable, the pattern of offering on_gpu and on_tpu flags doesn't scale.

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

Yes: removes the on_tpu property from the Strategy base class.
Reason: The strategy is still an experimental API, and this is part of making it stable

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 list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is welcome to review the PR.
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 🙃

@ananthsub ananthsub mentioned this pull request Jan 19, 2022
12 tasks
@mergify mergify bot added the ready PRs ready to be merged label Jan 19, 2022
@ananthsub ananthsub enabled auto-merge (squash) January 19, 2022 06:08
@ananthsub ananthsub force-pushed the feat/rm-on-tpu-strategy branch from 227edf0 to 4ea1dff Compare January 19, 2022 21:49
@four4fish four4fish closed this Jan 19, 2022
auto-merge was automatically disabled January 19, 2022 22:44

Pull request was closed

@four4fish four4fish reopened this Jan 19, 2022
@four4fish
Copy link
Contributor

+1 to this change. I realized the on_tpu is not actually used anywhere, only in tests. Other than on_tpu(), the _XLA_AVAILABLE check is only used at import time. Should we have device_availablity check at X_accelerator initialization time?

@codecov
Copy link

codecov bot commented Jan 19, 2022

Codecov Report

Merging #11536 (4ea1dff) into master (f41d1e5) will decrease coverage by 4%.
The diff coverage is n/a.

@@           Coverage Diff            @@
##           master   #11536    +/-   ##
========================================
- Coverage      92%      88%    -4%     
========================================
  Files         194      194            
  Lines       16972    16961    -11     
========================================
- Hits        15611    14964   -647     
- Misses       1361     1997   +636     

@ananthsub ananthsub enabled auto-merge (squash) January 19, 2022 23:19
@ananthsub
Copy link
Contributor Author

ananthsub commented Jan 20, 2022

+1 to this change. I realized the on_tpu is not actually used anywhere, only in tests. Other than on_tpu(), the _XLA_AVAILABLE check is only used at import time. Should we have device_availablity check at X_accelerator initialization time?

@kaushikb11 what do you think^?

In general I am in favor of those checks running as early as possible to avoid wasting users' time. In the GPU accelerator, we do check this here: https://github.com/PyTorchLightning/pytorch-lightning/blob/f41d1e5e5ebb7040a39d137695e818cada9a9234/pytorch_lightning/accelerators/gpu.py#L36-L44

But we don't assert that cuda is available - should we?
And should we do that at the init time vs in setup_environment ?

@four4fish Would this also simplify the accelerator connector initialization logic?

Regardless, I'd like to handle it in a separate issue & PR 😄

@four4fish
Copy link
Contributor

four4fish commented Jan 20, 2022

@ananthsub @kaushikb11 I think we can introduce a new function called _device_check() in X_Accelerator, which will be called by accelerator_connector right after accelerator initialization.
We don't have consistent device availibliies check in neither accelerator class, strategies class nor accelerator_connector at this point, so I introduced it in the new accelerator_connector rewrite . But it's not ideal, I think it's a better fit in accelerator API. I will create a issue, let's discuss in the issue

@kaushikb11
Copy link
Contributor

@four4fish @ananthsub I agree. We could add device_check functionality in the Accelerator Class. I had planned to add it after starting to work on #10687

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 !

@ananthsub ananthsub merged commit 1bd6fc9 into Lightning-AI:master Jan 20, 2022
@ananthsub ananthsub deleted the feat/rm-on-tpu-strategy branch January 20, 2022 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Includes a breaking change ready PRs ready to be merged strategy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants