Skip to content

Add pyre fixme for downstream type errors from D65753120 #1439

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions captum/attr/_core/dataloader_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def _perturb_inputs(
else:
baseline = baselines[attr_inp_count]

# pyre-fixme[58]: `*` is not supported for operand types `object` and
# `Tensor`.
perturbed_inp = inp * pert_mask + baseline * (1 - pert_mask)
perturbed_inputs.append(perturbed_inp)

Expand Down
5 changes: 4 additions & 1 deletion captum/attr/_core/feature_ablation.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,10 @@ def _construct_ablated_input(
).long()
current_mask = current_mask.to(expanded_input.device)
ablated_tensor = (
expanded_input * (1 - current_mask).to(expanded_input.dtype)
expanded_input
* (1 - current_mask).to(expanded_input.dtype)
# pyre-fixme[58]: `*` is not supported for operand types `Union[None, float,
# Tensor]` and `Tensor`.
) + (baseline * current_mask.to(expanded_input.dtype))
return ablated_tensor, current_mask

Expand Down
2 changes: 2 additions & 0 deletions captum/attr/_core/occlusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ def _construct_ablated_input(
torch.ones(1, dtype=torch.long, device=expanded_input.device)
- input_mask
).to(expanded_input.dtype)
# pyre-fixme[58]: `*` is not supported for operand types `Union[None, float,
# Tensor]` and `Tensor`.
) + (baseline * input_mask.to(expanded_input.dtype))
return ablated_tensor, input_mask

Expand Down
2 changes: 2 additions & 0 deletions captum/metrics/_core/infidelity.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ def _next_infidelity_tensors(
inputs_fwd = torch.repeat_interleave(
inputs_fwd, current_n_perturb_samples, dim=0
)
# pyre-fixme[58]: `-` is not supported for operand types `Tensor` and
# `Union[Future[Tensor], Tensor]`.
perturbed_fwd_diffs = inputs_fwd - inputs_perturbed_fwd
attributions_expanded = tuple(
torch.repeat_interleave(attribution, current_n_perturb_samples, dim=0)
Expand Down
2 changes: 2 additions & 0 deletions captum/module/gaussian_stochastic_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def _get_gate_active_probs(self) -> Tensor:
probs (Tensor): probabilities tensor of the gates are active
in shape(n_gates)
"""
# pyre-fixme[58]: `/` is not supported for operand types `Parameter` and
# `Optional[float]`.
x = self.mu / self.std
return 0.5 * (1 + torch.erf(x / math.sqrt(2)))

Expand Down
2 changes: 2 additions & 0 deletions tests/attr/test_input_x_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def _input_x_gradient_classification_assert(self, nt_type: str = "vanilla") -> N
attributions = input_x_grad.attribute(input, target)
output = model(input)[:, target]
output.backward()
# pyre-fixme[58]: `*` is not supported for operand types
# `Optional[Tensor]` and `Tensor`.
expected = input.grad * input
assertTensorAlmostEqual(self, attributions, expected, 0.00001, "max")
else:
Expand Down
Loading