-
Notifications
You must be signed in to change notification settings - Fork 479
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 gradient requirements for layer methods #647
Conversation
@vivekmig has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
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! Thank you for the fix. Couple nits and questions.
captum/_utils/gradient.py
Outdated
@@ -23,7 +23,9 @@ | |||
) | |||
|
|||
|
|||
def apply_gradient_requirements(inputs: Tuple[Tensor, ...]) -> List[bool]: | |||
def apply_gradient_requirements( | |||
inputs: Tuple[Tensor, ...], warn: bool = False |
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.
nit: In order to support original behavior don't we want to not warn only when we know that warning is not necessary in case of layer approaches ?
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.
Great catch, thanks! Yes, you're definitely right, meant to set the default to True
@vivekmig has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
This updates gradient requirements to be set on layer inputs / outputs rather than original inputs, which ensures that gradient requirements are set when inputs are non-floating point (e.g. token indices). This also avoids unnecessarily requiring gradients between the input and target layer, when only layer gradients are required.