-
Notifications
You must be signed in to change notification settings - Fork 164
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
potential bug: reference leak when torch is loaded and a function errors #666
Comments
Seems to be something with pytorch and third-party modules generally - e.g. python/cpython#98253. Probably not a big issue but still worrying. See also nanobind FAQ on the issue https://nanobind.readthedocs.io/en/latest/faq.html#why-am-i-getting-errors-about-leaked-functions-and-types |
Got the same issue and memory keeps building up until shutting down the program. Found a previous issue #117, and it seems that their example code also has memory leaks in 0.5.4.
>>> ants.__version__
'0.5.4' |
Can you please post a reproducible example? |
There was also a report of something similar in #678 - the user appears to have deleted their comments but it was something about running registrations in a loop. I tried reporting memory usage in a loop but it appeared to increase a lot then only very slightly after the first iteration. Hard to tell if it was a small leak or just background optimization processes. Or maybe Python was not reporting memory correctly. Will definitely investigate further if there's an example, ideally using built-in antspy data or failing that some other public data |
I can't get the torch warnings on my Intel Mac
torch == 2.2.2 |
Leaving this thread for the torch issue. For general memory leak problems, please see #733. |
For some reasons when I run in bare python in terminal, it doesn't complain about the memory leaks. However, the memory leak still persists. For example, the following example keeps occupying more memories (activity monitor shows 7GB RAM usage after a few hundred iters. However, the diff of memory table shows nothing (signs of mem leak). My suspect of import ants
import numpy as np
img = np.random.random((400, 400))
img_ants = ants.image_clone(ants.from_numpy(img), pixeltype='float')
from pympler.tracker import SummaryTracker
tracker = SummaryTracker()
for i in range(5000):
ants.image_similarity(img_ants, img_ants, metric_type='Correlation')
if i % 100 == 0:
# expect no change in memory table, but increased memory usage
print(tracker.print_diff()) |
Oh just saw your message. Thanks for reference. I'll dig more into this (indeed we need reproducible example but this is tricky) |
Thanks @dipterix , this tracks with what I found previously - Python doesn't think it's using the memory, I think there's leftover C++ objects. |
When torch is loaded and a function errors, there is a reference leak reported when the ipython console is exited. This does not seem to happen in a normal python console and only when torch is loaded. Very weird.. I've seen this a few other times but never reproducible so unsure if it's the same issue or if there's a general reference leak.
Then
exit()
and you get this:The text was updated successfully, but these errors were encountered: