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

Add type error suppressions for upcoming upgrade #1379

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions captum/attr/_core/deep_lift.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ def _backward_hook(
"network.".format(module)
)

# pyre-fixme[6]: For 1st argument expected `Type[Union[ELU, LeakyReLU, ReLU,
# Sigmoid, Softmax, Softplus, Tanh, MaxPool1d, MaxPool2d, MaxPool3d]]` but got
# `Type[Module]`.
multipliers = SUPPORTED_NON_LINEAR[type(module)](
module,
module.input,
Expand Down
2 changes: 2 additions & 0 deletions captum/attr/_core/noise_tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def update_sum_attribution_and_sq(
else sum_attribution_sq[i] + current_attribution_sq
)

# pyre-fixme[53]: Captured variable `attr_func` is not annotated.
# pyre-fixme[53]: Captured variable `is_inputs_tuple` is not annotated.
def compute_partial_attribution(
inputs_with_noise_partition: Tuple[Tensor, ...],
# pyre-fixme[2]: Parameter annotation cannot be `Any`.
Expand Down
3 changes: 3 additions & 0 deletions captum/metrics/_core/infidelity.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ def _generate_perturbations(
"""

# pyre-fixme[3]: Return type must be annotated.
# pyre-fixme[53]: Captured variable `baselines_expanded` is not annotated.
# pyre-fixme[53]: Captured variable `inputs_expanded` is not annotated.
def call_perturb_func():
r""" """
baselines_pert = None
Expand Down Expand Up @@ -485,6 +487,7 @@ def _validate_inputs_and_perturbations(
is: {}"""
).format(perturb[0].shape, input_perturbed[0].shape)

# pyre-fixme[53]: Captured variable `bsz` is not annotated.
def _next_infidelity_tensors(
current_n_perturb_samples: int,
) -> Union[Tuple[Tensor], Tuple[Tensor, Tensor, Tensor]]:
Expand Down
2 changes: 2 additions & 0 deletions captum/metrics/_core/sensitivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ def max_values(input_tnsr: Tensor) -> Tensor:
# pyre-fixme[33]: Given annotation cannot be `Any`.
kwargs_copy: Any = None

# pyre-fixme[53]: Captured variable `bsz` is not annotated.
# pyre-fixme[53]: Captured variable `expl_inputs` is not annotated.
def _next_sensitivity_max(current_n_perturb_samples: int) -> Tensor:
inputs_perturbed = _generate_perturbations(current_n_perturb_samples)

Expand Down
31 changes: 31 additions & 0 deletions tests/influence/_core/test_tracin_k_most_influential.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ class TestTracInGetKMostInfluential(BaseTest):
param_list: List[
Tuple[str, DataInfluenceConstructor, bool, bool, int, int, str, bool]
] = []
# pyre-fixme[16]: `type` has no attribute `batch_size`.
# pyre-fixme[16]: `type` has no attribute `k`.
for batch_size, k in [(4, 7), (7, 4), (40, 5), (5, 40), (40, 45)]:
# pyre-fixme[16]: `type` has no attribute `unpack_inputs`.
for unpack_inputs in [True, False]:
# pyre-fixme[16]: `type` has no attribute `proponents`.
for proponents in [True, False]:
# pyre-fixme[16]: `type` has no attribute `gpu_setting`.
for gpu_setting in GPU_SETTING_LIST:
# pyre-fixme[16]: `type` has no attribute `reduction`.
# pyre-fixme[16]: `type` has no attribute `constr`.
# pyre-fixme[16]: `type` has no attribute `aggregate`.
for reduction, constr, aggregate in [
(
"none",
Expand All @@ -50,6 +58,9 @@ class TestTracInGetKMostInfluential(BaseTest):
name="linear2",
layers=(
["module.linear2"]
# pyre-fixme[16]:
# `TestTracInGetKMostInfluential` has no attribute
# `gpu_setting`.
if gpu_setting == "cuda_data_parallel"
else ["linear2"]
),
Expand All @@ -58,19 +69,39 @@ class TestTracInGetKMostInfluential(BaseTest):
),
]:
if not (
# pyre-fixme[16]: `TestTracInGetKMostInfluential` has no
# attribute `constr`.
"sample_wise_grads_per_batch" in constr.kwargs
and constr.kwargs["sample_wise_grads_per_batch"]
and is_gpu(gpu_setting)
):
param_list.append(
(
# pyre-fixme[16]:
# `TestTracInGetKMostInfluential` has no attribute
# `reduction`.
reduction,
constr,
# pyre-fixme[16]:
# `TestTracInGetKMostInfluential` has no attribute
# `unpack_inputs`.
unpack_inputs,
# pyre-fixme[16]:
# `TestTracInGetKMostInfluential` has no attribute
# `proponents`.
proponents,
# pyre-fixme[16]:
# `TestTracInGetKMostInfluential` has no attribute
# `batch_size`.
batch_size,
# pyre-fixme[16]:
# `TestTracInGetKMostInfluential` has no attribute
# `k`.
k,
gpu_setting,
# pyre-fixme[16]:
# `TestTracInGetKMostInfluential` has no attribute
# `aggregate`.
aggregate,
)
)
Expand Down
13 changes: 13 additions & 0 deletions tests/influence/_core/test_tracin_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ def _test_tracin_regression_setup(
param_list: List[Tuple[Optional[str], DataInfluenceConstructor, str, int, bool]] = (
[]
)
# pyre-fixme[16]: `type` has no attribute `use_gpu`.
for use_gpu in use_gpu_list:
# pyre-fixme[16]: `type` has no attribute `dim`.
for dim in [1, 20]:
# pyre-fixme[16]: `type` has no attribute `mode`.
# pyre-fixme[16]: `type` has no attribute `reduction`.
# pyre-fixme[16]: `type` has no attribute `constructor`.
for mode, reduction, constructor in [
(
"check_idx",
Expand All @@ -74,6 +79,8 @@ def _test_tracin_regression_setup(
DataInfluenceConstructor(
TracInCP,
name="TracInCP_fc1",
# pyre-fixme[16]: `TestTracInRegression` has no attribute
# `use_gpu`.
layers=["module.fc1"] if use_gpu else ["fc1"],
),
),
Expand Down Expand Up @@ -138,7 +145,13 @@ def _test_tracin_regression_setup(
), # add a test where `duplicate_loss_fn` is True
),
]:
# pyre-fixme[16]: `TestTracInRegression` has no attribute `mode`.
if not (mode == "sample_wise_trick" and use_gpu):
# pyre-fixme[16]: `TestTracInRegression` has no attribute
# `reduction`.
# pyre-fixme[16]: `TestTracInRegression` has no attribute
# `constructor`.
# pyre-fixme[16]: `TestTracInRegression` has no attribute `dim`.
param_list.append((reduction, constructor, mode, dim, use_gpu))

# pyre-fixme[56]: Pyre was not able to infer the type of argument
Expand Down
12 changes: 12 additions & 0 deletions tests/influence/_core/test_tracin_self_influence.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ class TestTracInSelfInfluence(BaseTest):

# add tests for `TracInCPBase` implementations

# pyre-fixme[16]: `type` has no attribute `unpack_inputs`.
for unpack_inputs in [True, False]:
# pyre-fixme[16]: `type` has no attribute `gpu_setting`.
for gpu_setting in GPU_SETTING_LIST:
# pyre-fixme[16]: `type` has no attribute `reduction`.
# pyre-fixme[16]: `type` has no attribute `constructor`.
for reduction, constructor in [
(
"none",
Expand All @@ -45,6 +49,8 @@ class TestTracInSelfInfluence(BaseTest):
name="TracInCP_linear1",
layers=(
["module.linear1"]
# pyre-fixme[16]: `TestTracInSelfInfluence` has no
# attribute `gpu_setting`.
if gpu_setting == "cuda_data_parallel"
else ["linear1"]
),
Expand Down Expand Up @@ -84,11 +90,17 @@ class TestTracInSelfInfluence(BaseTest):
),
]:
if not (
# pyre-fixme[16]: `TestTracInSelfInfluence` has no attribute
# `constructor`.
"sample_wise_grads_per_batch" in constructor.kwargs
and constructor.kwargs["sample_wise_grads_per_batch"]
and is_gpu(gpu_setting)
):
param_list.append(
# pyre-fixme[16]: `TestTracInSelfInfluence` has no attribute
# `reduction`.
# pyre-fixme[16]: `TestTracInSelfInfluence` has no attribute
# `unpack_inputs`.
(reduction, constructor, unpack_inputs, gpu_setting)
)

Expand Down