Skip to content
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

Neuron Aggregation #495

Closed
wants to merge 7 commits into from
Closed

Conversation

vivekmig
Copy link
Contributor

This adds support for neuron aggregation, neuron_selector can be a function which returns a custom aggregate of a layer's neurons for all neuron methods other than neuron conductance, which has dependence on output gradients. The neuron_index argument was renamed, and a deprecation decorator was added to provide a warning for usage of the old parameter as a keyword argument. This decorator can be removed prior to the 0.4.0 release.

Documentation of the new callable functionality has been added to NeuronDeepLift, this documentation will be propagated to other relevant methods after review.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vivekmig has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@NarineK NarineK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you for working on this, @vivekmig!
A question: Are we allowing slice dt for neuron_selector and summing per example across all neurons ? According to the documentation Callable can return scalar per example but it can also return slice, can't it ?

tests/attr/neuron/test_neuron_deeplift.py Show resolved Hide resolved
captum/attr/_utils/common.py Outdated Show resolved Hide resolved
captum/attr/_utils/attribution.py Show resolved Hide resolved
captum/attr/_core/neuron/neuron_integrated_gradients.py Outdated Show resolved Hide resolved
captum/attr/_core/neuron/neuron_deep_lift.py Outdated Show resolved Hide resolved
captum/attr/_core/neuron/neuron_deep_lift.py Outdated Show resolved Hide resolved
sum of the neurons in the layer or sum of neurons with
activations in a particular range. It is expected that
this function returns either a tensor with one element
or a scalar per example.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the gradient attribution algorithms such as IG it must return a scalar per example, doesn't it ?

captum/attr/_core/neuron/neuron_deep_lift.py Outdated Show resolved Hide resolved
captum/_utils/gradient.py Outdated Show resolved Hide resolved
captum/_utils/common.py Show resolved Hide resolved
@@ -423,7 +423,9 @@ def _forward_layer_eval_with_neuron_grads(
evals in a dictionary protected by a lock, analogous to the gather implementation
for the core PyTorch DataParallel implementation.
"""
grad_enabled = True if gradient_neuron_index is not None or grad_enabled else False
grad_enabled = (
True if gradient_neuron_selector is not None or grad_enabled else False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: redundant if-else, grad_enabled = gradient_neuron_selector is not None or grad_enabled

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vivekmig has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@vivekmig merged this pull request in aae5228.

NarineK pushed a commit to NarineK/captum-1 that referenced this pull request Nov 19, 2020
Summary:
This adds support for neuron aggregation, neuron_selector can be a function which returns a custom aggregate of a layer's neurons for all neuron methods other than neuron conductance, which has dependence on output gradients. The neuron_index argument was renamed, and a deprecation decorator was added to provide a warning for usage of the old parameter as a keyword argument. This decorator can be removed prior to the 0.4.0 release.

Documentation of the new callable functionality has been added to NeuronDeepLift, this documentation will be propagated to other relevant methods after review.

Pull Request resolved: pytorch#495

Reviewed By: miguelmartin75

Differential Revision: D24346065

Pulled By: vivekmig

fbshipit-source-id: c3853e19256de4c8c32a8ff615965bf513a5cd22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants