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

Write predictions in LightningModule instead of EvalResult #3882

Merged
merged 2 commits into from
Oct 5, 2020

Conversation

nateraw
Copy link
Contributor

@nateraw nateraw commented Oct 5, 2020

What does this PR do?

Fixes #3870

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.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

Comment on lines +307 to +313
def write_prediction(self, name, value, filename='predictions.pt'):
self.trainer.evaluation_loop.predictions._add_prediction(name, value, filename)

def write_prediction_dict(self, predictions_dict, filename='predictions.pt'):
for k, v in predictions_dict.items():
self.write_prediction(k, v, filename)

Copy link
Contributor

Choose a reason for hiding this comment

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

does this write out as a CSV file? do you think this makes more sense as a callback?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

writes to list of dictionaries via torch.save. making predictions is different for every use case, so this way lets user define how they want to do it.

Could be achieved with callback (in fact, that's how I originally was doing this), but that would only work for 1 use case.

@codecov
Copy link

codecov bot commented Oct 5, 2020

Codecov Report

Merging #3882 into master will increase coverage by 4%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #3882    +/-   ##
=======================================
+ Coverage      84%     87%    +4%     
=======================================
  Files         119     117     -2     
  Lines        9764    9155   -609     
=======================================
- Hits         8169    8002   -167     
+ Misses       1595    1153   -442     

@nateraw nateraw marked this pull request as ready for review October 5, 2020 21:43
@mergify mergify bot requested a review from a team October 5, 2020 21:44
@williamFalcon williamFalcon merged commit 1954d7c into Lightning-AI:master Oct 5, 2020
@ananthsub
Copy link
Contributor

@nateraw please use fsspec here: https://github.com/PyTorchLightning/pytorch-lightning/blob/cea5f1f53876399dfaa0d37accdc527af7ca39af/pytorch_lightning/trainer/supporters.py#L138-L165

so we can save files beyond local disk

@Borda Borda added this to the 0.10.0 milestone Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable .write and .write_dict from LM
4 participants