Skip to content

Testing linux job fix #1586

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

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
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
4 changes: 1 addition & 3 deletions captum/_utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _is_tuple(inputs: Tensor) -> Literal[False]: ...

@typing.overload
def _is_tuple(
inputs: TensorOrTupleOfTensorsGeneric, # type: ignore
inputs: Union[Tensor, Tuple[Tensor, ...]],
) -> bool: ...


Expand Down Expand Up @@ -373,8 +373,6 @@ def _expand_target(
def _expand_feature_mask(
feature_mask: Union[Tensor, Tuple[Tensor, ...]], n_samples: int
) -> Tuple[Tensor, ...]:
# pyre-fixme[6]: For 1st argument expected `Tensor` but got `Union[Tensor,
# typing.Tuple[Tensor, ...]]`.
is_feature_mask_tuple = _is_tuple(feature_mask)
feature_mask = _format_tensor_into_tuples(feature_mask)
feature_mask_new = tuple(
Expand Down
3 changes: 1 addition & 2 deletions captum/_utils/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class Model(ABC):
def fit(
self,
train_data: DataLoader,
# pyre-fixme[2]: Parameter must be annotated.
**kwargs,
**kwargs: object,
) -> Optional[Dict[str, Union[int, float, Tensor]]]:
r"""
Override this method to actually train your model.
Expand Down
46 changes: 26 additions & 20 deletions captum/attr/_core/deep_lift.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,20 +348,21 @@ def attribute( # type: ignore
self._remove_hooks(main_model_hooks)

undo_gradient_requirements(inputs_tuple, gradient_mask)
# pyre-fixme[7]: Expected `Union[Tuple[Variable[TensorOrTupleOfTensorsGeneric...
return _compute_conv_delta_and_format_attrs(
self,
return_convergence_delta,
attributions,
baselines,
inputs_tuple,
additional_forward_args,
target,
is_inputs_tuple,
return cast(
TensorOrTupleOfTensorsGeneric,
_compute_conv_delta_and_format_attrs(
self,
return_convergence_delta,
attributions,
baselines,
inputs_tuple,
additional_forward_args,
target,
is_inputs_tuple,
),
)

# 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 DeepLift.
"""
Expand Down Expand Up @@ -831,11 +832,18 @@ def attribute( # type: ignore
)

if return_convergence_delta:
# pyre-fixme[7]: Expected `Union[Tuple[Variable[TensorOrTupleOfTensorsGen...
return _format_output(is_inputs_tuple, attributions), delta
return (
cast(
TensorOrTupleOfTensorsGeneric,
_format_output(is_inputs_tuple, attributions),
),
delta,
)
else:
# pyre-fixme[7]: Expected `Union[Tuple[Variable[TensorOrTupleOfTensorsGen...
return _format_output(is_inputs_tuple, attributions)
return cast(
TensorOrTupleOfTensorsGeneric,
_format_output(is_inputs_tuple, attributions),
)

def _expand_inputs_baselines_targets(
self,
Expand Down Expand Up @@ -995,10 +1003,8 @@ def maxpool3d(

def maxpool(
module: Module,
# pyre-fixme[24]: Generic type `Callable` expects 2 type parameters.
pool_func: Callable,
# pyre-fixme[24]: Generic type `Callable` expects 2 type parameters.
unpool_func: Callable,
pool_func: Callable[..., Tuple[Tensor, Tensor]],
unpool_func: Callable[..., Tensor],
inputs: Tensor,
outputs: Tensor,
grad_input: Tensor,
Expand Down
65 changes: 32 additions & 33 deletions captum/attr/_core/feature_ablation.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,10 @@ def attribute(
if attr_progress is not None:
attr_progress.close()

# pyre-fixme[7]: Expected `Variable[TensorOrTupleOfTensorsGeneric <:
# [Tensor, typing.Tuple[Tensor, ...]]]`
# but got `Union[Tensor, typing.Tuple[Tensor, ...]]`.
return self._generate_result(total_attrib, weights, is_inputs_tuple) # type: ignore # noqa: E501 line too long
return cast(
TensorOrTupleOfTensorsGeneric,
self._generate_result(total_attrib, weights, is_inputs_tuple),
)

def _attribute_with_independent_feature_masks(
self,
Expand Down Expand Up @@ -629,8 +629,7 @@ def _should_skip_inputs_and_warn(
all_empty = False
if self._min_examples_per_batch_grouped is not None and (
formatted_inputs[tensor_idx].shape[0]
# pyre-ignore[58]: Type has been narrowed to int
< self._min_examples_per_batch_grouped
< cast(int, self._min_examples_per_batch_grouped)
):
should_skip = True
break
Expand Down Expand Up @@ -789,35 +788,35 @@ def attribute_future(
)

if enable_cross_tensor_attribution:
# pyre-fixme[7]: Expected `Future[Variable[TensorOrTupleOfTensorsGeneric
# <:[Tensor, typing.Tuple[Tensor, ...]]]]` but got
# `Future[Union[Tensor, typing.Tuple[Tensor, ...]]]`
return self._attribute_with_cross_tensor_feature_masks_future( # type: ignore # noqa: E501 line too long
formatted_inputs=formatted_inputs,
formatted_additional_forward_args=formatted_additional_forward_args,
target=target,
baselines=baselines,
formatted_feature_mask=formatted_feature_mask,
attr_progress=attr_progress,
processed_initial_eval_fut=processed_initial_eval_fut,
is_inputs_tuple=is_inputs_tuple,
perturbations_per_eval=perturbations_per_eval,
return cast(
Future[TensorOrTupleOfTensorsGeneric],
self._attribute_with_cross_tensor_feature_masks_future( # type: ignore
formatted_inputs=formatted_inputs,
formatted_additional_forward_args=formatted_additional_forward_args, # noqa: E501 line too long
target=target,
baselines=baselines,
formatted_feature_mask=formatted_feature_mask,
attr_progress=attr_progress,
processed_initial_eval_fut=processed_initial_eval_fut,
is_inputs_tuple=is_inputs_tuple,
perturbations_per_eval=perturbations_per_eval,
),
)
else:
# pyre-fixme[7]: Expected `Future[Variable[TensorOrTupleOfTensorsGeneric
# <:[Tensor, typing.Tuple[Tensor, ...]]]]` but got
# `Future[Union[Tensor, typing.Tuple[Tensor, ...]]]`
return self._attribute_with_independent_feature_masks_future( # type: ignore # noqa: E501 line too long
formatted_inputs,
formatted_additional_forward_args,
target,
baselines,
formatted_feature_mask,
perturbations_per_eval,
attr_progress,
processed_initial_eval_fut,
is_inputs_tuple,
**kwargs,
return cast(
Future[TensorOrTupleOfTensorsGeneric],
self._attribute_with_independent_feature_masks_future( # type: ignore # noqa: E501 line too long
formatted_inputs,
formatted_additional_forward_args,
target,
baselines,
formatted_feature_mask,
perturbations_per_eval,
attr_progress,
processed_initial_eval_fut,
is_inputs_tuple,
**kwargs,
),
)

def _attribute_with_independent_feature_masks_future(
Expand Down
11 changes: 5 additions & 6 deletions captum/attr/_core/guided_backprop_deconvnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# pyre-strict
import warnings
from typing import Callable, List, Optional, Tuple, Union
from typing import cast, List, Optional, Tuple, Union

import torch
import torch.nn.functional as F
Expand Down Expand Up @@ -78,12 +78,11 @@ def attribute(
self._remove_hooks()

undo_gradient_requirements(inputs_tuple, gradient_mask)
# pyre-fixme[7]: Expected `TensorOrTupleOfTensorsGeneric` but got
# `Tuple[Tensor, ...]`.
return _format_output(is_inputs_tuple, gradients)
return cast(
TensorOrTupleOfTensorsGeneric, _format_output(is_inputs_tuple, gradients)
)

# 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 ModifiedReluGradientAttribution.
"""
Expand Down
9 changes: 5 additions & 4 deletions captum/attr/_core/guided_grad_cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# pyre-strict
import warnings
from typing import List, Optional, Union
from typing import cast, List, Optional, Union

import torch
from captum._utils.common import _format_output, _format_tensor_into_tuples, _is_tuple
Expand Down Expand Up @@ -223,6 +223,7 @@ def attribute(
)
output_attr.append(torch.empty(0))

# pyre-fixme[7]: Expected `TensorOrTupleOfTensorsGeneric` but got
# `Tuple[Tensor, ...]`.
return _format_output(is_inputs_tuple, tuple(output_attr))
return cast(
TensorOrTupleOfTensorsGeneric,
_format_output(is_inputs_tuple, tuple(output_attr)),
)
11 changes: 5 additions & 6 deletions captum/attr/_core/input_x_gradient.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

# pyre-strict
from typing import Callable, Optional
from typing import Callable, cast, Optional

from captum._utils.common import _format_output, _format_tensor_into_tuples, _is_tuple
from captum._utils.gradient import (
Expand Down Expand Up @@ -126,12 +126,11 @@ def attribute(
)

undo_gradient_requirements(inputs_tuple, gradient_mask)
# pyre-fixme[7]: Expected `TensorOrTupleOfTensorsGeneric` but got
# `Tuple[Tensor, ...]`.
return _format_output(is_inputs_tuple, attributions)
return cast(
TensorOrTupleOfTensorsGeneric, _format_output(is_inputs_tuple, attributions)
)

# 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 InputXGradient.
"""
Expand Down
24 changes: 13 additions & 11 deletions captum/attr/_core/integrated_gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# pyre-strict
import typing
from typing import Callable, List, Literal, Optional, Tuple, Union
from typing import Callable, cast, List, Literal, Optional, Tuple, Union

import torch
from captum._utils.common import (
Expand Down Expand Up @@ -301,16 +301,18 @@ def attribute( # type: ignore
additional_forward_args=additional_forward_args,
target=target,
)
# pyre-fixme[7]: Expected `Union[Tuple[Variable[TensorOrTupleOfTensorsGen...
return _format_output(is_inputs_tuple, attributions), delta
# pyre-fixme[7]: Expected
# `Union[Tuple[Variable[TensorOrTupleOfTensorsGeneric <: [Tensor,
# typing.Tuple[Tensor, ...]]], Tensor], Variable[TensorOrTupleOfTensorsGeneric
# <: [Tensor, typing.Tuple[Tensor, ...]]]]` 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),
),
delta,
)
return cast(
TensorOrTupleOfTensorsGeneric, _format_output(is_inputs_tuple, attributions)
)

def attribute_future(self) -> None:
r"""
This method is not implemented for IntegratedGradients.
"""
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
Loading
Loading