remove clone
in _compute_jacobian_wrt_params_with_sample_wise_trick
#1111
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.
Summary:
In https://www.internalfb.com/code/fbsource/[76c57d350097]/fbcode/pytorch/captum/captum/_utils/gradient.py?lines=840-841 we are calling
clone
on the elements ofinputs
. However, sinceinputs
is of typeTuple[Any,...]
, those elements may not be Tensors, and thus may not have the clone method.My understanding is that we call
clone
because inapply_gradient_requirements
, we changerequires_grad=True
for all elements ofinputs
. Even if those elements were Tensors, this would not be necessary, because in this function we seek gradients wrt to parameters of the model, andinputs
refers to inputs to the model. Furthermore, sinceinputs
is not a tuple of tensors, it is not actually possible to callapply_gradient_requirements
oninputs
.Also see discussion at https://www.internalfb.com/diff/D41687791 (288cd3a6754d85cbcb0ce74784aa014876284b6c)?dst_version_fbid=1539905103125262&transaction_fbid=587574556076948
In summary, because
inputs
is of typeTuple[Any,...]
and notTuple[Tensor,...]
, it does not make sense to callclone
on the elements ofinputs
, nor callapply_gradient_requirements(inputs)
. And furthermore, we do not actually need to call the latter, becauseinputs
is not parameters. Thus, this diff simply removes those 2 calls.Differential Revision: D43135296