-
Notifications
You must be signed in to change notification settings - Fork 412
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 slow performance for confusion matrix based metrics #1302
Conversation
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.
LGTM 🎉
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #1302 +/- ##
======================================
- Coverage 87% 87% -0%
======================================
Files 190 190
Lines 11121 11120 -1
======================================
- Hits 9621 9620 -1
Misses 1500 1500 |
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.
@SkafteNicki For now, I think sticking to the default here makes sense. I would be open for changing this conditionally in the future, but this would require more experimenting :)
do you want to open an issue for it so we won't forget? 🦦 |
* bincount fix * chlog (cherry picked from commit 8cc0cd7)
@SkafteNicki I stumbled upon this issue and did some investigation. The new implementation used I ran a quick performance test with different tensor sizes. Integer implementation: z = torch.zeros(4, device=unique_mapping.device, dtype=unique_mapping.dtype)
return z.index_add_(0, unique_mapping, torch.ones_like(unique_mapping)) Float implementation: z = torch.zeros(4, device=unique_mapping.device, dtype=torch.float64)
return z.index_add_(0, unique_mapping, torch.ones_like(unique_mapping, dtype=torch.float64)) Timing results on RTX 3090 (in milliseconds):
Timing results on CPU (in milliseconds):
Looks like |
What does this PR do?
Fixes #1267
Fixes #1277
After the refactor the underlying
_bincount
function that does a lot of the computations for confusion matrix based metrics was changed. I did some testing at the time and everything seemed to be fine. However, for large inputs theimplementation is really slow.
Here is a direct comparison in colab:
https://colab.research.google.com/drive/18tGZj_dPria6NSwVOIgwPXO8mJBr21kc?usp=sharing
The results:
The TLDR:
The simple fix currently in this PR is to change it back to the old implementation. The alternative is that we have something like this in the code:
where we have to set N based on some experimentation.
@Borda, @justusschock opinions?
Before submitting
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 🙃