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 tensor printing in trainer.test() #5138

Merged
merged 9 commits into from
Jan 25, 2021

Conversation

bryant1410
Copy link
Contributor

@bryant1410 bryant1410 commented Dec 14, 2020

What does this PR do?

Fix printing tensors when showing test results, so it goes from this

DATALOADER:0 TEST RESULTS
{'fake_test_acc': tensor(4.7004e-14, device="cuda:0")}

to this

DATALOADER:0 TEST RESULTS
{'fake_test_acc': 4.7004e-14}

Fixes #5107

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • 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? Otherwise, we ask you to create a separate PR for every change.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

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; Bugfixes should be including in bug-fix release milestones (m.f.X) and features should be included in (m.X.b) releases.

Did you have fun?

Make sure you had fun coding 🙃

@bryant1410 bryant1410 changed the title Fix showing test results for tensors Fix tensor printing in trainer.test() Dec 14, 2020
@codecov
Copy link

codecov bot commented Dec 16, 2020

Codecov Report

Merging #5138 (1579f1f) into master (0346b63) will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           master   #5138   +/-   ##
======================================
  Coverage      93%     93%           
======================================
  Files         135     135           
  Lines       10023   10023           
======================================
  Hits         9356    9356           
  Misses        667     667           

@awaelchli awaelchli added feature Is an improvement or enhancement logging Related to the `LoggerConnector` and `log()` priority: 2 Low priority task labels Dec 16, 2020
@Borda Borda added this to the 1.2 milestone Dec 16, 2020
…onnector.py

Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>
@pep8speaks
Copy link

pep8speaks commented Dec 18, 2020

Hello @bryant1410! Thanks for updating this PR.

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-01-25 05:32:33 UTC

@tchaton tchaton enabled auto-merge (squash) January 11, 2021 12:41
Comment on lines +259 to +260
pprint({k: (v.item() if v.numel() == 1 else v.tolist()) if isinstance(v, torch.Tensor) else v
for k, v in results.items()})
Copy link
Member

@justusschock justusschock Jan 11, 2021

Choose a reason for hiding this comment

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

Just thinking if it is worth to actually do our own pprint (extend the existing one), that does this kind of unwrapping for tensors so that we can simply reuse this one (also nice for user)

@Borda
Copy link
Member

Borda commented Jan 11, 2021

well, shall this be rather a feature?

@Borda Borda modified the milestones: 1.2, 1.1.x Jan 11, 2021
@tchaton tchaton merged commit 30227eb into Lightning-AI:master Jan 25, 2021
@bryant1410 bryant1410 deleted the pprint-results branch January 25, 2021 16:09
tchaton pushed a commit that referenced this pull request Feb 3, 2021
* Fix showing test results for tensors

* Fix docs

* Update pytorch_lightning/trainer/connectors/logger_connector/logger_connector.py

Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>

* Fix lint issues

Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>
Borda pushed a commit that referenced this pull request Feb 4, 2021
* Fix showing test results for tensors

* Fix docs

* Update pytorch_lightning/trainer/connectors/logger_connector/logger_connector.py

Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>

* Fix lint issues

Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>
Borda pushed a commit that referenced this pull request Feb 4, 2021
* Fix showing test results for tensors

* Fix docs

* Update pytorch_lightning/trainer/connectors/logger_connector/logger_connector.py

Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>

* Fix lint issues

Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>
Borda pushed a commit that referenced this pull request Feb 4, 2021
* Fix showing test results for tensors

* Fix docs

* Update pytorch_lightning/trainer/connectors/logger_connector/logger_connector.py

Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>

* Fix lint issues

Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>
Borda pushed a commit that referenced this pull request Feb 4, 2021
* Fix showing test results for tensors

* Fix docs

* Update pytorch_lightning/trainer/connectors/logger_connector/logger_connector.py

Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>

* Fix lint issues

Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>
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 logging Related to the `LoggerConnector` and `log()` priority: 2 Low priority task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pretty print tensors in trainer.test()
7 participants