Skip to content

Fix Lime pyre fixme issues #1611

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 6 commits 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: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
tests:
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
with:
runner: linux.12xlarge
docker-image: cimg/python:3.11
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-pip-cpu-with-type-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
pytorch_args: ["", "-n"]
fail-fast: false
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
with:
runner: linux.12xlarge
docker-image: cimg/python:3.11
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-pip-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- pytorch_args: "-v 2.1.0"
docker_img: "cimg/python:3.12"
fail-fast: false
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
with:
runner: linux.12xlarge
docker-image: ${{ matrix.docker_img }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-pip-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
cuda_arch_version: ["12.1"]
fail-fast: false
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
with:
runner: linux.4xlarge.nvidia.gpu
repository: pytorch/captum
Expand Down
3 changes: 1 addition & 2 deletions captum/attr/_core/kernel_shap.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ def attribute( # type: ignore
show_progress=show_progress,
)

# pyre-fixme[24] Generic type `Callable` expects 2 type parameters.
def attribute_future(self) -> Callable:
def attribute_future(self) -> None:
r"""
This method is not implemented for KernelShap.
"""
Expand Down
6 changes: 2 additions & 4 deletions captum/attr/_core/lime.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,7 @@ def generate_perturbation() -> (

return generate_perturbation

# pyre-fixme[24] Generic type `Callable` expects 2 type parameters.
def attribute_future(self) -> Callable:
def attribute_future(self) -> None:
r"""
This method is not implemented for LimeBase.
"""
Expand Down Expand Up @@ -1116,8 +1115,7 @@ def attribute( # type: ignore
show_progress=show_progress,
)

# pyre-fixme[24] Generic type `Callable` expects 2 type parameters.
def attribute_future(self) -> Callable:
def attribute_future(self) -> None:
return super().attribute_future()

def _attribute_kwargs( # type: ignore
Expand Down
11 changes: 6 additions & 5 deletions captum/attr/_core/lrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import typing
from collections import defaultdict
from typing import Any, Callable, cast, Dict, List, Literal, Optional, Tuple, Union
from typing import Any, cast, Dict, List, Literal, Optional, Tuple, Union

import torch.nn as nn
from captum._utils.common import (
Expand Down Expand Up @@ -230,16 +230,17 @@ def attribute(
undo_gradient_requirements(input_tuple, gradient_mask)

if return_convergence_delta:
# pyre-fixme[7]: Expected `Union[Tuple[Variable[TensorOrTupleOfTensorsGen...
return (
_format_output(is_inputs_tuple, relevances),
cast(
TensorOrTupleOfTensorsGeneric,
_format_output(is_inputs_tuple, relevances),
),
self.compute_convergence_delta(relevances, output),
)
else:
return _format_output(is_inputs_tuple, relevances) # type: ignore

# pyre-fixme[24] Generic type `Callable` expects 2 type parameters.
def attribute_future(self) -> Callable:
def attribute_future(self) -> None:
r"""
This method is not implemented for LRP.
"""
Expand Down
3 changes: 1 addition & 2 deletions captum/attr/_core/occlusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ def attribute( # type: ignore
show_progress=show_progress,
)

# pyre-fixme[24] Generic type `Callable` expects 2 type parameters.
def attribute_future(self) -> Callable:
def attribute_future(self) -> None:
r"""
This method is not implemented for Occlusion.
"""
Expand Down
12 changes: 6 additions & 6 deletions captum/attr/_core/saliency.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# pyre-strict

from typing import Callable, Optional
from typing import Callable, cast, Optional

import torch
from captum._utils.common import _format_output, _format_tensor_into_tuples, _is_tuple
Expand Down Expand Up @@ -138,12 +138,12 @@ def attribute(
else:
attributions = gradients
undo_gradient_requirements(inputs_tuple, gradient_mask)
# pyre-fixme[7]: Expected `TensorOrTupleOfTensorsGeneric` but got
# `Tuple[Tensor, ...]`.
return _format_output(is_inputs_tuple, attributions)

# pyre-fixme[24] Generic type `Callable` expects 2 type parameters.
def attribute_future(self) -> Callable:
return cast(
TensorOrTupleOfTensorsGeneric, _format_output(is_inputs_tuple, attributions)
)

def attribute_future(self) -> None:
r"""
This method is not implemented for Saliency.
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/attr/test_kernel_shap.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def test_futures_not_implemented(self) -> None:
kernel_shap = KernelShap(net)
attributions = None
with self.assertRaises(NotImplementedError):
attributions = kernel_shap.attribute_future()
attributions = kernel_shap.attribute_future() # type: ignore
self.assertEqual(attributions, None)

def _multi_input_scalar_kernel_shap_assert(self, func: Callable) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/attr/test_lime.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def test_futures_not_implemented(self) -> None:
)
attributions = None
with self.assertRaises(NotImplementedError):
attributions = lime.attribute_future()
attributions = lime.attribute_future() # type: ignore
self.assertEqual(attributions, None)

# pyre-fixme[24]: Generic type `Callable` expects 2 type parameters.
Expand Down
2 changes: 1 addition & 1 deletion tests/attr/test_lrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,5 @@ def test_futures_not_implemented(self) -> None:
lrp = LRP(model)
attributions = None
with self.assertRaises(NotImplementedError):
attributions = lrp.attribute_future()
attributions = lrp.attribute_future() # type: ignore
self.assertEqual(attributions, None)
2 changes: 1 addition & 1 deletion tests/attr/test_occlusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def test_futures_not_implemented(self) -> None:
occ = Occlusion(net)
attributions = None
with self.assertRaises(NotImplementedError):
attributions = occ.attribute_future()
attributions = occ.attribute_future() # type: ignore
self.assertEqual(attributions, None)

@unittest.mock.patch("sys.stderr", new_callable=io.StringIO)
Expand Down
2 changes: 1 addition & 1 deletion tests/attr/test_saliency.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_futures_not_implemented(self) -> None:
saliency = Saliency(model)
attributions = None
with self.assertRaises(NotImplementedError):
attributions = saliency.attribute_future()
attributions = saliency.attribute_future() # type: ignore
self.assertEqual(attributions, None)

def _saliency_base_assert(
Expand Down