-
Notifications
You must be signed in to change notification settings - Fork 547
Optim-wip: Improve ModuleOutputsHook, testing coverage #834
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
Merged
NarineK
merged 5 commits into
meta-pytorch:optim-wip
from
ProGamerGov:optim-wip-fix-hook-bug
May 17, 2022
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1f6c2d5
Improve ModuleOutputsHook, testing coverage, & fix bug
ProGamerGov 66a3aa0
Make hook fix optional
ProGamerGov da3d028
Remove hacky hook fix
ProGamerGov 3d5c3d5
Lint: Fix import order
ProGamerGov 95539d5
Merge branch 'optim-wip' into optim-wip-fix-hook-bug
ProGamerGov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
As you mentioned this is dangerous to do because we can remove hooks that we didn't set and the function name happen to be the same. Why don't we remove only the hooks that we set right after we are done with the hook ? I thought that all hooks we be removed here, won't they ?
https://github.com/pytorch/captum/blob/6e7f0bd761ca538a6fce30dbd4e0e6007fc6abe5/captum/optim/_core/optimization.py#L97
If there is a bug and we miss some of them, then we should rather make sure that we removed them after optimization is finished.
Uh oh!
There was an error while loading. Please reload this page.
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.
The idea was that the problem would be fixed if the individual ran
InputOptimizationa second time, but I now realize that this would break the ability to use multiple instances ofInputOptimization.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.
Maybe we could somehow let the user decide when to run the cleanup code?
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.
There does not appear to be a way to detect whether or not the hooks are still being used, so letting the user decide if they want to perform this fix is probably the best choice.
Uh oh!
There was an error while loading. Please reload this page.
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.
We could probably add this function to the API for users:
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.
@ProGamerGov, in your example: does it occur after we intialize
opt.InputOptimization(model, loss_fn, image)second time ?Do you have a notebook where we can debug the error ?
Uh oh!
There was an error while loading. Please reload this page.
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.
@NarineK Just setup / install captum with the optim module, and run this snippet of code to reproduce it:
The
InputOptimizationinit function just callsModuleOutputsHook, so we can just do the same in order to make it easier to reproduce.Uh oh!
There was an error while loading. Please reload this page.
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.
It occurs because we often reuse the same target instance in notebooks for example, and thus the hooks attached to target instance are not removed. I don't think that it's something we can avoid, but we can make users aware of it and provide the option to mitigate it's effects.
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.
cc-ing @vivekmig - Vivek can help with this issue
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.
@NarineK I can remove the hook removal functions for this PR, so we can merge it. Then in a later PR we can revisit this minor hook duplication bug as it's a very niche issue at the moment that won't interfere with anything at the moment.