-
Notifications
You must be signed in to change notification settings - Fork 216
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
reduce concordance_index_censored's memory use #362
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #362 +/- ##
==========================================
- Coverage 97.92% 97.92% -0.01%
==========================================
Files 37 37
Lines 3326 3323 -3
Branches 502 502
==========================================
- Hits 3257 3254 -3
Misses 33 33
Partials 36 36
☔ View full report in Codecov by Sentry. |
Indeed, the memory usage is quite excessive, great catch! I believe you can optimize it even further by
|
This reverts commit d7d8ab8. Resolved Conflicts: sksurv/metrics.py
Hi @sebp - thank you very much for reviewing and suggesting further optimisations! generators: i had to read up on that and the changes i made are a first attempt then; tests continue to pass. empty mask outside the loop and fill resetting inside the loop: i tried that but didn't observe a reduced number of allocations, perhaps a mask inside the loop can be efficiently 'recycled' if it's the same shape and dtype? allocation observation was via memray's getting started step and naive mouse-hover-for-tooltip manual inspection of the flame graph. having |
I don't know how numpy handles memory allocations either. Since you actually used a memory profiler and did not observe a difference, I would prefer the more readable code as well. |
Checklist
What does this implement/fix? Explain your changes
issue encountered: Passing relatively lots of technical data samples to
concordance_index_censored
results in "kernel died" in a notebook environment.analysis
concordance_index_censored
computation calls _get_comparable which returns up toN
masks of lengthN
whereN
is the number of samples being scored._get_comparable
returns all the masks and the caller iterates over all the masks but it uses only one mask at a time.proposed solution
_get_comparable
to return (smaller) mask information instead of (potentially much larger) full mask content._get_comparable
caller to construct the full mask from the mask info, one mask at a time at the point of use.testing
Existing tests continue to pass. In terms of additional test coverage, I've tried to build a test_metrics.py case but wasn't able to easily reproduce the issue running locally but in a more resource-constrained environment it is easily reproduced e.g. via this code snippet: