From 7e035ad4b96c8fea0dca0a192c21038a96b2fd2a Mon Sep 17 00:00:00 2001 From: Vivek Miglani Date: Sun, 28 Dec 2025 15:29:07 -0800 Subject: [PATCH 1/4] Reenable type checking in OSS GH Workflow (#1696) Summary: Reenabling OSS type checking step, skipping pyre check but keeping original mypy checks Pyre issues will be fixed in a stacked diff Differential Revision: D89819451 --- .github/workflows/test-pip-cpu-with-type-checks.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-pip-cpu-with-type-checks.yml b/.github/workflows/test-pip-cpu-with-type-checks.yml index 108223fc07..2a50b57efe 100644 --- a/.github/workflows/test-pip-cpu-with-type-checks.yml +++ b/.github/workflows/test-pip-cpu-with-type-checks.yml @@ -10,7 +10,6 @@ on: jobs: tests: - if: false # Workflow disabled strategy: matrix: pytorch_args: ["", "-n"] @@ -24,6 +23,7 @@ jobs: sudo chmod -R 777 . ./scripts/install_via_pip.sh ${{ matrix.pytorch_args }} ./scripts/run_mypy.sh - pyre check + # Disabling pyre check until numpy issues are resolved + # pyre check # Run Tests python3 -m pytest -ra --cov=. --cov-report term-missing From af8614085e1386ec1c494ea6a941e77bebe7e7b9 Mon Sep 17 00:00:00 2001 From: Vivek Miglani Date: Sun, 28 Dec 2025 15:29:07 -0800 Subject: [PATCH 2/4] Remove redundant cast calls in gauss_legendre_builders (#1706) Summary: The `cast()` calls in the `step_sizes` and `alphas` functions within `gauss_legendre_builders()` were flagged as redundant by Pyre type checker since the values being cast are already of type `np.ndarray`. Replaced the inline cast pattern with explicit typed variable assignments. Differential Revision: D89871122 --- captum/attr/_utils/approximation_methods.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/captum/attr/_utils/approximation_methods.py b/captum/attr/_utils/approximation_methods.py index 9af3cf9580..ec3b01377c 100644 --- a/captum/attr/_utils/approximation_methods.py +++ b/captum/attr/_utils/approximation_methods.py @@ -2,7 +2,7 @@ # pyre-strict from enum import Enum -from typing import Callable, cast, List, Tuple +from typing import Callable, List, Tuple import torch @@ -126,15 +126,13 @@ def gauss_legendre_builders() -> ( def step_sizes(n: int) -> List[float]: assert n > 0, "The number of steps has to be larger than zero" # Scaling from 2 to 1 - return cast( - NDArray[np.float64], 0.5 * np.polynomial.legendre.leggauss(n)[1] - ).tolist() + result: NDArray[np.float64] = 0.5 * np.polynomial.legendre.leggauss(n)[1] + return result.tolist() def alphas(n: int) -> List[float]: assert n > 0, "The number of steps has to be larger than zero" # Scaling from [-1, 1] to [0, 1] - return cast( - NDArray[np.float64], 0.5 * (1 + np.polynomial.legendre.leggauss(n)[0]) - ).tolist() + result: NDArray[np.float64] = 0.5 * (1 + np.polynomial.legendre.leggauss(n)[0]) + return result.tolist() return step_sizes, alphas From 04e90ea99e9b1d968a1aa817c8a2898c152e8731 Mon Sep 17 00:00:00 2001 From: Vivek Miglani Date: Sun, 28 Dec 2025 15:29:07 -0800 Subject: [PATCH 3/4] Remove unused pyre-ignore comment in CAV.load (#1707) Summary: The `pyre-ignore[16]` comment for `np.core.multiarray._reconstruct` was no longer suppressing any type errors and Pyre flagged it as an unused ignore. Removed the obsolete comment while keeping the `type: ignore[attr-defined]` for mypy compatibility. Differential Revision: D89870752 --- captum/concept/_core/cav.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/captum/concept/_core/cav.py b/captum/concept/_core/cav.py index 8b96056d35..243105fed8 100644 --- a/captum/concept/_core/cav.py +++ b/captum/concept/_core/cav.py @@ -171,8 +171,6 @@ def load( ctx: AbstractContextManager[None, None] if hasattr(torch.serialization, "safe_globals"): safe_globals = [ - # pyre-ignore[16]: Module `numpy.core.multiarray` has no attribute - # `_reconstruct` np.core.multiarray._reconstruct, # type: ignore[attr-defined] np.ndarray, np.dtype, From 27ddb9b2f0c8f1fe7bed26588ee47e1fd96fee0d Mon Sep 17 00:00:00 2001 From: Vivek Miglani Date: Sun, 28 Dec 2025 15:29:07 -0800 Subject: [PATCH 4/4] Add pyre-ignore for Future instantiation in common.py and basic_models.py Summary: Pyre reports `Call error [29]: typing.Type[Future] is not a function` when instantiating `torch.futures.Future()` because the type stubs declare it as a generic type rather than a callable class. Added `pyre-ignore[29]` comments to suppress these false positives since `Future` is callable at runtime. This affects: - `_construct_future_forward` in common.py - `BasicModel_MultiLayer_with_Future.forward` in basic_models.py Differential Revision: D89870780 --- captum/_utils/common.py | 1 + captum/testing/helpers/basic_models.py | 1 + 2 files changed, 2 insertions(+) diff --git a/captum/_utils/common.py b/captum/_utils/common.py index 757e5b0b97..a44d815ab7 100644 --- a/captum/_utils/common.py +++ b/captum/_utils/common.py @@ -574,6 +574,7 @@ def _format_outputs( # pyre-fixme[24] Callable requires 2 arguments def _construct_future_forward(original_forward: Callable) -> Callable: def future_forward(*args: Any, **kwargs: Any) -> torch.futures.Future[Tensor]: + # pyre-ignore[29]: `Future` is callable at runtime fut: torch.futures.Future[Tensor] = torch.futures.Future() fut.set_result(original_forward(*args, **kwargs)) return fut diff --git a/captum/testing/helpers/basic_models.py b/captum/testing/helpers/basic_models.py index f663baa2dd..cd5b3a76de 100644 --- a/captum/testing/helpers/basic_models.py +++ b/captum/testing/helpers/basic_models.py @@ -581,6 +581,7 @@ def forward( self.relu(lin1_out) else: relu_out = self.relu(lin1_out) + # pyre-ignore[29]: `Future` is callable at runtime result = Future() lin2_out = self.linear2(relu_out) if multidim_output: