-
Notifications
You must be signed in to change notification settings - Fork 22
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
Forward Hooks Persist After Destroying FeatureExtractor #72
Comments
ShuntaroAoki
added a commit
that referenced
this issue
Jul 29, 2024
Fix issue #72 Forward Hooks Persist After Destroying FeatureExtractor
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue
When the FeatureExtractor is initialized in
bdpy.recon.torch.icnn.reconstruct,
it registers forward hooks on theencoder
. However, the registered forward hooks are not erased after thereconstruct
is returned andfeature_extractor
is destroyed. This leads to a problem that the remaining forward hooks keep accumulating features and occupy memory when the same encoder instance is used forreconstruct
multiple times.Here's a snippet that illustrates the behavior of
FeatureExtractor
Yes, the example in the cookbook avoids this problem by initializing
encoder
for each image, but this is not effective when using larger models.Suggestion
One possible fix is to add a destructor method that clears forward hooks from the layers:
The text was updated successfully, but these errors were encountered: