-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Cast to >=float32 tensor when passing scalar to self.log #19046
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #19046 +/- ##
=========================================
- Coverage 76% 49% -27%
=========================================
Files 447 435 -12
Lines 36375 36419 +44
=========================================
- Hits 27520 17816 -9704
- Misses 8855 18603 +9748 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried writing a test for this but it's complicated since the metric will be moved to float32
after, so we would need to dynamically patch the call to result.log
. It's not worth it.
def test_log_tensor_wrap_dtype():
class MyModel(LightningModule):
def test_step(self, *_):
self.log("foo", 1.23, batch_size=1)
model = MyModel()
trainer = Trainer(logger=False, enable_checkpointing=False, enable_model_summary=False, enable_progress_bar=False)
# using the context manager class for cleanup, but users would use `set_default_dtype` directly
with _DtypeContextManager(torch.float16):
trainer.test(model, [0])
assert trainer.callback_metrics["foo"].dtype == torch.float32
This attempt passes anyways without your PR checked out
LGTM
Co-authored-by: awaelchli <[email protected]> (cherry picked from commit 1fcb4ae)
Co-authored-by: awaelchli <[email protected]> (cherry picked from commit 1fcb4ae)
What does this PR do?
Ensures that values get cast to float32+ tensors when passed to
self.log
.Fixes #18984
Before submitting
PR review
Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:
Reviewer checklist
📚 Documentation preview 📚: https://pytorch-lightning--19046.org.readthedocs.build/en/19046/