Skip to content

Commit

Permalink
Add type error suppressions for upcoming upgrade (#1339)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #1339

Reviewed By: MaggieMoss

Differential Revision: D62387661
  • Loading branch information
Pyre Bot Jr. authored and facebook-github-bot committed Sep 9, 2024
1 parent d8ceaa8 commit 03c55ee
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions captum/attr/_core/dataloader_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ def attribute(
assert len(input_roles) == len(inputs), (
"input_roles must have the same size as the return of the dataloader,",
f"length of input_roles is {len(input_roles)} ",
# pyre-fixme[6]: For 1st argument expected
# `pyre_extensions.ReadOnly[Sized]` but got
# `Optional[typing.Tuple[typing.Any, ...]]`.
f"whereas the length of dataloader return is {len(inputs)}",
)

Expand All @@ -395,6 +398,9 @@ def attribute(
"Baselines must have the same size as the return of the dataloader ",
"that need attribution",
f"length of baseline is {len(baselines)} ",
# pyre-fixme[6]: For 1st argument expected
# `pyre_extensions.ReadOnly[Sized]` but got
# `Optional[typing.Tuple[typing.Any, ...]]`.
f'whereas the length of dataloader return with role "0" is {len(inputs)}',
)

Expand All @@ -413,6 +419,9 @@ def attribute(
"Feature mask must have the same size as the return of the dataloader ",
"that need attribution",
f"length of feature_mask is {len(feature_mask)} ",
# pyre-fixme[6]: For 1st argument expected
# `pyre_extensions.ReadOnly[Sized]` but got
# `Optional[typing.Tuple[typing.Any, ...]]`.
f'whereas the length of dataloader return with role "0" is {len(inputs)}',
)

Expand Down
3 changes: 3 additions & 0 deletions captum/attr/_core/deep_lift.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,9 @@ def attribute( # type: ignore
" with more than one example but found: {}."
" If baselines are provided in shape of scalars or with a single"
" baseline example, `DeepLift`"
# pyre-fixme[16]: Item `Callable` of `Union[(...) ->
# TensorOrTupleOfTensorsGeneric, TensorOrTupleOfTensorsGeneric]` has no
# attribute `__getitem__`.
" approach can be used instead.".format(baselines[0])
)

Expand Down
3 changes: 3 additions & 0 deletions captum/attr/_core/gradient_shap.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ def attribute(
# attribute `__getitem__`.
assert isinstance(baselines[0], torch.Tensor), (
"Baselines distribution has to be provided in a form "
# pyre-fixme[16]: Item `Callable` of `Union[(...) ->
# TensorOrTupleOfTensorsGeneric, TensorOrTupleOfTensorsGeneric]` has no
# attribute `__getitem__`.
"of a torch.Tensor {}.".format(baselines[0])
)

Expand Down
2 changes: 2 additions & 0 deletions captum/attr/_core/layer/layer_gradient_shap.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ def attribute(
# TensorOrTupleOfTensorsGeneric]` has no attribute `__getitem__`.
assert isinstance(baselines[0], torch.Tensor), (
"Baselines distribution has to be provided in a form "
# pyre-fixme[16]: Item `Callable` of `Union[(...) -> Any,
# TensorOrTupleOfTensorsGeneric]` has no attribute `__getitem__`.
"of a torch.Tensor {}.".format(baselines[0])
)

Expand Down
4 changes: 4 additions & 0 deletions captum/attr/_utils/attribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, forward_func: Callable) -> None:
self.forward_func = forward_func

# pyre-fixme[24]: Generic type `Callable` expects 2 type parameters.
# pyre-fixme[13]: Attribute `attribute` is never initialized.
attribute: Callable
r"""
This method computes and returns the attribution values for each input tensor.
Expand Down Expand Up @@ -74,6 +75,7 @@ def __init__(self, forward_func: Callable) -> None:
"""

# pyre-fixme[24] Generic type `Callable` expects 2 type parameters.
# pyre-fixme[13]: Attribute `attribute_future` is never initialized.
attribute_future: Callable

r"""
Expand Down Expand Up @@ -126,6 +128,7 @@ def has_convergence_delta(self) -> bool:
return False

# pyre-fixme[24]: Generic type `Callable` expects 2 type parameters.
# pyre-fixme[13]: Attribute `compute_convergence_delta` is never initialized.
compute_convergence_delta: Callable
r"""
The attribution algorithms which derive `Attribution` class and provide
Expand Down Expand Up @@ -504,6 +507,7 @@ def __init__(
InternalAttribution.__init__(self, forward_func, layer, device_ids)

# pyre-fixme[24]: Generic type `Callable` expects 2 type parameters.
# pyre-fixme[13]: Attribute `attribute` is never initialized.
attribute: Callable
r"""
This method computes and returns the neuron attribution values for each
Expand Down
1 change: 1 addition & 0 deletions captum/concept/_core/concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(self, model: Module) -> None:
self.model = model

# pyre-fixme[24]: Generic type `Callable` expects 2 type parameters.
# pyre-fixme[13]: Attribute `interpret` is never initialized.
interpret: Callable
r"""
An abstract interpret method that performs concept-based model interpretability
Expand Down
4 changes: 4 additions & 0 deletions captum/robust/_core/metrics/min_param_perturbation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ def drange(
min_val: Union[int, float], max_val: Union[int, float], step_val: Union[int, float]
) -> Generator[Union[int, float], None, None]:
curr = min_val
# pyre-fixme[58]: `>` is not supported for operand types `Union[float, int]` and
# `int`.
while curr < max_val:
yield curr
# pyre-fixme[58]: `+` is not supported for operand types `Union[float, int]`
# and `Union[float, int]`.
curr += step_val


Expand Down
1 change: 1 addition & 0 deletions captum/robust/_core/perturbation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Perturbation:
"""

# pyre-fixme[24]: Generic type `Callable` expects 2 type parameters.
# pyre-fixme[13]: Attribute `perturb` is never initialized.
perturb: Callable
r"""
This method computes and returns the perturbed input for each input tensor.
Expand Down

0 comments on commit 03c55ee

Please sign in to comment.