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

Fix(Early Stopping): move best score to device #7959

Merged
merged 2 commits into from
Jun 21, 2021

Conversation

kaushikb11
Copy link
Contributor

@kaushikb11 kaushikb11 commented Jun 13, 2021

What does this PR do?

Fixes #7936

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 🙃

@codecov
Copy link

codecov bot commented Jun 13, 2021

Codecov Report

Merging #7959 (c5c4c76) into master (599d6db) will decrease coverage by 5%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #7959    +/-   ##
=======================================
- Coverage      92%     87%    -5%     
=======================================
  Files         207     207            
  Lines       13484   13484            
=======================================
- Hits        12354   11713   -641     
- Misses       1130    1771   +641     

@kaushikb11 kaushikb11 marked this pull request as ready for review June 18, 2021 03:34
@kaushikb11 kaushikb11 added the bug Something isn't working label Jun 18, 2021
@kaushikb11 kaushikb11 added this to the v1.3.x milestone Jun 18, 2021
Copy link
Member

@ethanwharris ethanwharris left a comment

Choose a reason for hiding this comment

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

LGTM - at least, it does what it says it does haha

@awaelchli awaelchli added the accelerator: tpu Tensor Processing Unit label Jun 18, 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 !

@tchaton tchaton added the ready PRs ready to be merged label Jun 21, 2021
@@ -277,6 +277,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Pass the `stage` argument of `Callback.{setup,teardown}` as a keyword ([#7973](https://github.com/PyTorchLightning/pytorch-lightning/pull/7973))


- Fixed move best score to device in EarlyStopping Callback ([#7959](https://github.com/PyTorchLightning/pytorch-lightning/pull/7959))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Fixed move best score to device in EarlyStopping Callback ([#7959](https://github.com/PyTorchLightning/pytorch-lightning/pull/7959))
- Fixed move best score to device in EarlyStopping Callback ([#7959](https://github.com/PyTorchLightning/pytorch-lightning/pull/7959))

as your comments suggest, this fix applies only for tpu right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It applies to other accelerators as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

how would I reproduce an error on a GPU for example?

why can't we do for example this:

self.best_score.to(current.device)

moving one tensor to the device but the other not in a monitor_op is only going to raise questions for the reader of this code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

>>> torch_inf = torch.tensor(np.Inf)
>>> value = torch.tensor(5, device=xm.xla_device())
>>> torch.lt(value, torch_inf)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: torch_xla/csrc/aten_xla_bridge.cpp:69 : Check failed: xtensor
*** Begin stack trace ***
	tensorflow::CurrentStackTrace()

Similar code for Cuda devices won't throw an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

I got the following error (device with 2 gpus and using ddp)
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!`

I also felt that self.best_score.to(current.device) was safer..

@kaushikb11 kaushikb11 enabled auto-merge (squash) June 21, 2021 09:37
@kaushikb11 kaushikb11 merged commit 2303f9c into Lightning-AI:master Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accelerator: tpu Tensor Processing Unit bug Something isn't working ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Early Stopping throwing error for training on TPUs
6 participants