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

New metric classes (#1326) #1877

Merged
merged 16 commits into from May 19, 2020
Merged

New metric classes (#1326) #1877

merged 16 commits into from May 19, 2020

Conversation

justusschock
Copy link
Member

@justusschock justusschock commented May 18, 2020

followup #1326

* Create metrics package

* Create metric.py

* Create utils.py

* Create __init__.py

* add tests for metric utils

* add docstrings for metrics utils

* add function to recursively apply other function to collection

* add tests for this function

* update test

* Update pytorch_lightning/metrics/metric.py

Co-Authored-By: Jirka Borovec <Borda@users.noreply.github.com>

* update metric name

* remove example docs

* fix tests

* add metric tests

* fix to tensor conversion

* fix apply to collection

* Update CHANGELOG.md

* Update pytorch_lightning/metrics/metric.py

Co-Authored-By: Jirka Borovec <Borda@users.noreply.github.com>

* remove tests from init

* add missing type annotations

* rename utils to convertors

* Create metrics.rst

* Update index.rst

* Update index.rst

* Update pytorch_lightning/metrics/convertors.py

Co-Authored-By: Jirka Borovec <Borda@users.noreply.github.com>

* Update pytorch_lightning/metrics/convertors.py

Co-Authored-By: Jirka Borovec <Borda@users.noreply.github.com>

* Update pytorch_lightning/metrics/convertors.py

Co-Authored-By: Jirka Borovec <Borda@users.noreply.github.com>

* Update pytorch_lightning/metrics/metric.py

Co-Authored-By: Jirka Borovec <Borda@users.noreply.github.com>

* Update tests/utilities/test_apply_to_collection.py

Co-Authored-By: Jirka Borovec <Borda@users.noreply.github.com>

* Update tests/utilities/test_apply_to_collection.py

Co-Authored-By: Jirka Borovec <Borda@users.noreply.github.com>

* Update tests/metrics/convertors.py

Co-Authored-By: Jirka Borovec <Borda@users.noreply.github.com>

* Apply suggestions from code review

Co-Authored-By: Jirka Borovec <Borda@users.noreply.github.com>

* add doctest example

* rename file and fix imports

* added parametrized test

* replace lambda with inlined function

* rename apply_to_collection to apply_func

* Separated class description from init args

* Apply suggestions from code review

Co-Authored-By: Jirka Borovec <Borda@users.noreply.github.com>

* adjust random values

* suppress output when seeding

* remove gpu from doctest

* Add requested changes and add ellipsis for doctest

* forgot to push these files...

* add explicit check for dtype to convert to

* fix ddp tests

* remove explicit ddp destruction

Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
@justusschock justusschock marked this pull request as draft May 18, 2020 19:41
@mergify mergify bot requested a review from a team May 18, 2020 19:42
@justusschock justusschock marked this pull request as ready for review May 18, 2020 19:43
@mergify
Copy link
Contributor

mergify bot commented May 18, 2020

This pull request is now in conflict... :(

@pep8speaks
Copy link

pep8speaks commented May 18, 2020

Hello @justusschock! Thanks for updating this PR.

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

Comment last updated at 2020-05-19 14:43:12 UTC

@justusschock justusschock self-assigned this May 19, 2020
@justusschock justusschock added this to in Progress in Metrics package via automation May 19, 2020
Copy link
Member

@awaelchli awaelchli left a comment

Choose a reason for hiding this comment

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

I just read all the code and found some typos, but didn't have time yet to clone and test myself.
The code is very nice!

pytorch_lightning/metrics/__init__.py Outdated Show resolved Hide resolved
pytorch_lightning/metrics/__init__.py Outdated Show resolved Hide resolved
pytorch_lightning/metrics/__init__.py Outdated Show resolved Hide resolved
pytorch_lightning/metrics/__init__.py Outdated Show resolved Hide resolved
pytorch_lightning/metrics/converters.py Outdated Show resolved Hide resolved
pytorch_lightning/metrics/converters.py Outdated Show resolved Hide resolved
pytorch_lightning/metrics/converters.py Outdated Show resolved Hide resolved
pytorch_lightning/metrics/metric.py Outdated Show resolved Hide resolved

def __call__(self, *args, **kwargs) -> torch.Tensor:
def _to_device_dtype(x: torch.Tensor) -> torch.Tensor:
return x.to(device=self.device, dtype=self.dtype)
Copy link
Member

Choose a reason for hiding this comment

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

should the metrics also do non blocking transfers maybe? this was recently added in another pr when the batch is moved. or is there too little impact?

Copy link
Member

Choose a reason for hiding this comment

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

I guess that there was a comment that the non-blocking is by default...

Copy link
Member

Choose a reason for hiding this comment

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

where did you find that?

Copy link
Member

Choose a reason for hiding this comment

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

ok, not found it, so maybe just my bad :]

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed this (@Borda the comment you're referring to was in another context :) )

from typing import Any, Callable, Union


def apply_to_collection(data: Any, dtype: Union[type, tuple], function: Callable, *args, **kwargs) -> Any:
Copy link
Member

Choose a reason for hiding this comment

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

this is very useful!! ❤️

@mergify mergify bot requested a review from a team May 19, 2020 09:47
@Borda
Copy link
Member

Borda commented May 19, 2020

@justusschock I would not do this with standard PR as we want to get this merge without squash, so I would prefer to rebase this branch to master and merge it directly so we do not lose track of particular changes...
EDIT: but maybe it is fine as we have merged just one PR to the metrics branch

@Borda Borda marked this pull request as draft May 19, 2020 10:16
@Borda Borda changed the title Metric classes (#1326) Metric classes May 19, 2020
@Borda Borda changed the title Metric classes New metric classes (#1326) May 19, 2020
Borda and others added 2 commits May 19, 2020 12:19
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
.github/workflows/ci-testing.yml Show resolved Hide resolved
pytorch_lightning/metrics/converters.py Outdated Show resolved Hide resolved

def __call__(self, *args, **kwargs) -> torch.Tensor:
def _to_device_dtype(x: torch.Tensor) -> torch.Tensor:
return x.to(device=self.device, dtype=self.dtype)
Copy link
Member

Choose a reason for hiding this comment

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

I guess that there was a comment that the non-blocking is by default...

@mergify mergify bot requested a review from a team May 19, 2020 10:29
@Borda Borda marked this pull request as ready for review May 19, 2020 10:29
@Borda Borda added the feature Is an improvement or enhancement label May 19, 2020
@Borda Borda added this to the 0.8.0 milestone May 19, 2020
@justusschock
Copy link
Member Author

@Borda then let's do it with the rebasing thing. Anything I need to do for this? :)

@justusschock
Copy link
Member Author

@awaelchli Thanks, You're a like a human grammar dict :D

@Borda
Copy link
Member

Borda commented May 19, 2020

@Borda then let's do it with the rebasing thing. Anything I need to do for this? :)

looking at the commit history and there was only one PR merged to this branch so we can go the standard way... I ve rebased it so it shall be fine now...

@justusschock
Copy link
Member Author

Thanks :) I added the non-blocking stuff. So it should be ready to go :)

@Borda Borda added the ready PRs ready to be merged label May 19, 2020
@Borda Borda requested a review from awaelchli May 19, 2020 12:42
@mergify mergify bot requested a review from a team May 19, 2020 14:42
@williamFalcon williamFalcon merged commit 9b62963 into master May 19, 2020
Metrics package automation moved this from in Progress to Done May 19, 2020
@williamFalcon
Copy link
Contributor

@justusschock amazing!

@Borda Borda mentioned this pull request May 20, 2020
@Borda Borda deleted the metrics branch May 26, 2020 17:02
@Borda Borda modified the milestones: 0.8.0, Metrics May 26, 2020
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 ready PRs ready to be merged
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants