-
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
Compositional metrics #5464
Compositional metrics #5464
Conversation
Hello @justusschock! Thanks for updating this PR.
Comment last updated at 2021-01-26 14:35:27 UTC |
Very cool! Is there a reason that the Also, is there a way we could register all of these methods dynamically? Something like: operations = {
"__add__": torch.add,
"__mul__": torch.mul,
...
}
def register_operations():
for attr, fn in operations.items():
setattr(Metric, attr, lambda self, other: CompositionalMetric(fn, self, other)) |
@teddykoker the registering should be possible, we just have to split it into 2 groups: The ones that have two arguments and the ones having only one arg. I also think, that we should not use lambdas here since that way we might run into issues for some DP/DDP backends due to pickling. regarding the import: it has to be somewhat locally, since the compositional metric depends on |
Since some of the operations also need the input in the opposite order i.e |
@SkafteNicki I have one more question for you. I just reused your kwargs filter, but right now I noticed, that if the user does not explicitly define argument names but just |
You are right that it does not work, since the signature keys would then be simply import inspect
def f(*args, **kwargs):
return 1
signature = inspect.signature(f)
print(signature.parameters.keys()) #odict_keys(['args', 'kwargs']) I agree that in this case we should just forward everything. |
Codecov Report
@@ Coverage Diff @@
## release/1.2-dev #5464 +/- ##
================================================
- Coverage 93% 93% -0%
================================================
Files 153 154 +1
Lines 10890 11041 +151
================================================
+ Hits 10077 10214 +137
- Misses 813 827 +14 |
@justusschock it seems that we have merged something where most tests are failing https://github.com/PyTorchLightning/pytorch-lightning/runs/1769896518 |
What does this PR do?
Fixes #5392
Implements composition of metrics with simple operator interface like
metric_a + metric_b
.Before submitting
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:
Did you have fun?
Make sure you had fun coding 🙃