Skip to content

Commit

Permalink
Moving the Base Test Helper (#1485)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #1485

moving the base test helper to the captum library. This has a lot of file dependency so apologies for the large Diff

Reviewed By: cyrjano, lurunming

Differential Revision: D68174196

fbshipit-source-id: 84f180748bd6c70cba1b7079a14e97e520228feb
  • Loading branch information
styusuf authored and facebook-github-bot committed Jan 16, 2025
1 parent 4b7879c commit b487891
Show file tree
Hide file tree
Showing 93 changed files with 246 additions and 217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# pyre-strict

try:
from tests.helpers.fb.internal_base import FbBaseTest as BaseTest
from captum.testing.helpers.fb.internal_base import FbBaseTest as BaseTest

__all__ = [
"BaseTest",
Expand All @@ -13,4 +13,4 @@
# tests/helpers/__init__.py:13: error: Incompatible import of "BaseTest"
# (imported name has type "type[BaseTest]", local name has type
# "type[FbBaseTest]") [assignment]
from tests.helpers.basic import BaseTest # type: ignore
from captum.testing.helpers.basic import BaseTest # type: ignore
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/attr/helpers/attribution_delta_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Tuple, Union

import torch
from tests.helpers import BaseTest
from captum.testing.helpers import BaseTest
from torch import Tensor


Expand Down
2 changes: 1 addition & 1 deletion tests/attr/helpers/get_config_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import torch
from captum._utils.gradient import compute_gradients
from tests.helpers.basic_models import BasicModel, BasicModel5_MultiArgs
from captum.testing.helpers.basic_models import BasicModel, BasicModel5_MultiArgs
from torch import Tensor
from torch.nn import Module

Expand Down
4 changes: 2 additions & 2 deletions tests/attr/helpers/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
from captum.attr._core.saliency import Saliency
from captum.attr._core.shapley_value import ShapleyValueSampling
from captum.attr._utils.input_layer_wrapper import ModelInputWrapper
from tests.helpers.basic import set_all_random_seeds
from tests.helpers.basic_models import (
from captum.testing.helpers.basic import set_all_random_seeds
from captum.testing.helpers.basic_models import (
BasicModel_ConvNet,
BasicModel_MultiLayer,
BasicModel_MultiLayer_MultiInput,
Expand Down
8 changes: 4 additions & 4 deletions tests/attr/layer/test_grad_cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import torch
from captum._utils.typing import TensorLikeList
from captum.attr._core.layer.grad_cam import LayerGradCam
from packaging import version
from tests.helpers import BaseTest
from tests.helpers.basic import assertTensorTuplesAlmostEqual
from tests.helpers.basic_models import (
from captum.testing.helpers import BaseTest
from captum.testing.helpers.basic import assertTensorTuplesAlmostEqual
from captum.testing.helpers.basic_models import (
BasicModel_ConvNet_One_Conv,
BasicModel_MultiLayer,
)
from packaging import version
from torch import Tensor
from torch.nn import Module

Expand Down
6 changes: 3 additions & 3 deletions tests/attr/layer/test_internal_influence.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import torch
from captum._utils.typing import BaselineType
from captum.attr._core.layer.internal_influence import InternalInfluence
from packaging import version
from tests.helpers.basic import assertTensorTuplesAlmostEqual, BaseTest
from tests.helpers.basic_models import (
from captum.testing.helpers.basic import assertTensorTuplesAlmostEqual, BaseTest
from captum.testing.helpers.basic_models import (
BasicModel_MultiLayer,
BasicModel_MultiLayer_MultiInput,
)
from packaging import version
from torch import Tensor
from torch.nn import Module

Expand Down
4 changes: 2 additions & 2 deletions tests/attr/layer/test_layer_ablation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import torch
from captum._utils.typing import BaselineType
from captum.attr._core.layer.layer_feature_ablation import LayerFeatureAblation
from tests.helpers.basic import assertTensorTuplesAlmostEqual, BaseTest
from tests.helpers.basic_models import (
from captum.testing.helpers.basic import assertTensorTuplesAlmostEqual, BaseTest
from captum.testing.helpers.basic_models import (
BasicModel_ConvNet_One_Conv,
BasicModel_MultiLayer,
BasicModel_MultiLayer_MultiInput,
Expand Down
4 changes: 2 additions & 2 deletions tests/attr/layer/test_layer_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import torch
import torch.nn as nn
from captum.attr._core.layer.layer_activation import LayerActivation
from tests.helpers.basic import (
from captum.testing.helpers.basic import (
assertTensorAlmostEqual,
assertTensorTuplesAlmostEqual,
BaseTest,
)
from tests.helpers.basic_models import (
from captum.testing.helpers.basic_models import (
BasicModel_MultiLayer,
BasicModel_MultiLayer_MultiInput,
Conv1dSeqModel,
Expand Down
8 changes: 4 additions & 4 deletions tests/attr/layer/test_layer_conductance.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
import torch
from captum._utils.typing import BaselineType
from captum.attr._core.layer.layer_conductance import LayerConductance
from packaging import version
from tests.attr.helpers.conductance_reference import ConductanceReference
from tests.helpers.basic import (
from captum.testing.helpers.basic import (
assertTensorAlmostEqual,
assertTensorTuplesAlmostEqual,
BaseTest,
)
from tests.helpers.basic_models import (
from captum.testing.helpers.basic_models import (
BasicModel_ConvNet,
BasicModel_MultiLayer,
BasicModel_MultiLayer_MultiInput,
)
from packaging import version
from tests.attr.helpers.conductance_reference import ConductanceReference
from torch import Tensor
from torch.nn import Module

Expand Down
14 changes: 7 additions & 7 deletions tests/attr/layer/test_layer_deeplift.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@

import torch
from captum.attr._core.layer.layer_deep_lift import LayerDeepLift, LayerDeepLiftShap
from packaging import version
from tests.attr.helpers.neuron_layer_testing_util import (
create_inps_and_base_for_deeplift_neuron_layer_testing,
create_inps_and_base_for_deepliftshap_neuron_layer_testing,
)
from tests.helpers.basic import (
from captum.testing.helpers.basic import (
assert_delta,
assertTensorAlmostEqual,
assertTensorTuplesAlmostEqual,
BaseTest,
)
from tests.helpers.basic_models import (
from captum.testing.helpers.basic_models import (
BasicModel_ConvNet,
BasicModel_ConvNet_MaxPool3d,
BasicModel_MaxPool_ReLU,
BasicModel_MultiLayer,
LinearMaxPoolLinearModel,
ReLULinearModel,
)
from packaging import version
from tests.attr.helpers.neuron_layer_testing_util import (
create_inps_and_base_for_deeplift_neuron_layer_testing,
create_inps_and_base_for_deepliftshap_neuron_layer_testing,
)
from torch import Tensor


Expand Down
6 changes: 3 additions & 3 deletions tests/attr/layer/test_layer_feature_permutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import torch
from captum.attr._core.layer.layer_feature_permutation import LayerFeaturePermutation
from tests.helpers import BaseTest
from tests.helpers.basic import assertTensorAlmostEqual
from tests.helpers.basic_models import BasicModel_MultiLayer
from captum.testing.helpers import BaseTest
from captum.testing.helpers.basic import assertTensorAlmostEqual
from captum.testing.helpers.basic_models import BasicModel_MultiLayer
from torch import Tensor


Expand Down
10 changes: 5 additions & 5 deletions tests/attr/layer/test_layer_gradient_shap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
LayerGradientShap,
LayerInputBaselineXGradient,
)
from packaging import version
from tests.attr.helpers.attribution_delta_util import assert_attribution_delta
from tests.helpers.basic import (
from captum.testing.helpers.basic import (
assertTensorAlmostEqual,
assertTensorTuplesAlmostEqual,
BaseTest,
)
from tests.helpers.basic_models import (
from captum.testing.helpers.basic_models import (
BasicModel_MultiLayer,
BasicModel_MultiLayer_MultiInput,
)
from tests.helpers.classification_models import SoftmaxModel
from captum.testing.helpers.classification_models import SoftmaxModel
from packaging import version
from tests.attr.helpers.attribution_delta_util import assert_attribution_delta
from torch import Tensor
from torch.nn import Module

Expand Down
6 changes: 3 additions & 3 deletions tests/attr/layer/test_layer_gradient_x_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from captum._utils.typing import ModuleOrModuleList
from captum.attr._core.layer.layer_activation import LayerActivation
from captum.attr._core.layer.layer_gradient_x_activation import LayerGradientXActivation
from packaging import version
from tests.helpers.basic import assertTensorTuplesAlmostEqual, BaseTest
from tests.helpers.basic_models import (
from captum.testing.helpers.basic import assertTensorTuplesAlmostEqual, BaseTest
from captum.testing.helpers.basic_models import (
BasicEmbeddingModel,
BasicModel_MultiLayer,
BasicModel_MultiLayer_MultiInput,
)
from packaging import version
from torch import Tensor
from torch.nn import Module

Expand Down
6 changes: 3 additions & 3 deletions tests/attr/layer/test_layer_integrated_gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
configure_interpretable_embedding_layer,
remove_interpretable_embedding_layer,
)
from packaging import version
from tests.helpers.basic import (
from captum.testing.helpers.basic import (
assertTensorAlmostEqual,
assertTensorTuplesAlmostEqual,
BaseTest,
)
from tests.helpers.basic_models import (
from captum.testing.helpers.basic_models import (
BasicEmbeddingModel,
BasicModel_MultiLayer,
BasicModel_MultiLayer_TrueMultiInput,
)
from packaging import version
from torch import Tensor
from torch.nn import Module

Expand Down
9 changes: 6 additions & 3 deletions tests/attr/layer/test_layer_lrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
from captum.attr import LayerLRP
from captum.attr._utils.lrp_rules import Alpha1_Beta0_Rule, EpsilonRule, GammaRule

from tests.helpers import BaseTest
from tests.helpers.basic import assertTensorAlmostEqual
from tests.helpers.basic_models import BasicModel_ConvNet_One_Conv, SimpleLRPModel
from captum.testing.helpers import BaseTest
from captum.testing.helpers.basic import assertTensorAlmostEqual
from captum.testing.helpers.basic_models import (
BasicModel_ConvNet_One_Conv,
SimpleLRPModel,
)
from torch import Tensor


Expand Down
4 changes: 2 additions & 2 deletions tests/attr/models/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
InterpretableEmbeddingBase,
remove_interpretable_embedding_layer,
)
from tests.helpers.basic import assertTensorAlmostEqual
from tests.helpers.basic_models import BasicEmbeddingModel, TextModule
from captum.testing.helpers.basic import assertTensorAlmostEqual
from captum.testing.helpers.basic_models import BasicEmbeddingModel, TextModule
from torch.nn import Embedding


Expand Down
6 changes: 3 additions & 3 deletions tests/attr/neuron/test_neuron_ablation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
TensorOrTupleOfTensorsGeneric,
)
from captum.attr._core.neuron.neuron_feature_ablation import NeuronFeatureAblation
from tests.helpers import BaseTest
from tests.helpers.basic import assertTensorAlmostEqual
from tests.helpers.basic_models import (
from captum.testing.helpers import BaseTest
from captum.testing.helpers.basic import assertTensorAlmostEqual
from captum.testing.helpers.basic_models import (
BasicModel_ConvNet_One_Conv,
BasicModel_MultiLayer,
BasicModel_MultiLayer_MultiInput,
Expand Down
10 changes: 5 additions & 5 deletions tests/attr/neuron/test_neuron_conductance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
from captum._utils.typing import BaselineType, TensorOrTupleOfTensorsGeneric
from captum.attr._core.layer.layer_conductance import LayerConductance
from captum.attr._core.neuron.neuron_conductance import NeuronConductance

from packaging import version
from tests.helpers import BaseTest
from tests.helpers.basic import assertTensorAlmostEqual
from tests.helpers.basic_models import (
from captum.testing.helpers import BaseTest
from captum.testing.helpers.basic import assertTensorAlmostEqual
from captum.testing.helpers.basic_models import (
BasicModel_ConvNet,
BasicModel_MultiLayer,
BasicModel_MultiLayer_MultiInput,
)

from packaging import version
from torch import Tensor
from torch.nn import Module

Expand Down
14 changes: 7 additions & 7 deletions tests/attr/neuron/test_neuron_deeplift.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
import torch
from captum._utils.typing import TensorOrTupleOfTensorsGeneric
from captum.attr._core.neuron.neuron_deep_lift import NeuronDeepLift, NeuronDeepLiftShap
from tests.attr.helpers.neuron_layer_testing_util import (
create_inps_and_base_for_deeplift_neuron_layer_testing,
create_inps_and_base_for_deepliftshap_neuron_layer_testing,
)
from tests.helpers import BaseTest
from tests.helpers.basic import assertTensorAlmostEqual
from tests.helpers.basic_models import (
from captum.testing.helpers import BaseTest
from captum.testing.helpers.basic import assertTensorAlmostEqual
from captum.testing.helpers.basic_models import (
BasicModel_ConvNet,
BasicModel_ConvNet_MaxPool3d,
LinearMaxPoolLinearModel,
ReLULinearModel,
)
from tests.attr.helpers.neuron_layer_testing_util import (
create_inps_and_base_for_deeplift_neuron_layer_testing,
create_inps_and_base_for_deepliftshap_neuron_layer_testing,
)
from torch import Tensor


Expand Down
4 changes: 2 additions & 2 deletions tests/attr/neuron/test_neuron_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from captum._utils.typing import TensorOrTupleOfTensorsGeneric
from captum.attr._core.neuron.neuron_gradient import NeuronGradient
from captum.attr._core.saliency import Saliency
from tests.helpers.basic import (
from captum.testing.helpers.basic import (
assertTensorAlmostEqual,
assertTensorTuplesAlmostEqual,
BaseTest,
)
from tests.helpers.basic_models import (
from captum.testing.helpers.basic_models import (
BasicModel_ConvNet,
BasicModel_MultiLayer,
BasicModel_MultiLayer_MultiInput,
Expand Down
8 changes: 4 additions & 4 deletions tests/attr/neuron/test_neuron_gradient_shap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from captum.attr._core.neuron.neuron_integrated_gradients import (
NeuronIntegratedGradients,
)
from tests.helpers import BaseTest
from tests.helpers.basic import assertTensorAlmostEqual
from tests.helpers.basic_models import BasicModel_MultiLayer
from tests.helpers.classification_models import SoftmaxModel
from captum.testing.helpers import BaseTest
from captum.testing.helpers.basic import assertTensorAlmostEqual
from captum.testing.helpers.basic_models import BasicModel_MultiLayer
from captum.testing.helpers.classification_models import SoftmaxModel
from torch import Tensor
from torch.nn import Module

Expand Down
4 changes: 2 additions & 2 deletions tests/attr/neuron/test_neuron_integrated_gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
from captum.attr._core.neuron.neuron_integrated_gradients import (
NeuronIntegratedGradients,
)
from tests.helpers.basic import (
from captum.testing.helpers.basic import (
assertTensorAlmostEqual,
assertTensorTuplesAlmostEqual,
BaseTest,
)
from tests.helpers.basic_models import (
from captum.testing.helpers.basic_models import (
BasicModel_ConvNet,
BasicModel_MultiLayer,
BasicModel_MultiLayer_MultiInput,
Expand Down
2 changes: 1 addition & 1 deletion tests/attr/test_approximation_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import torch
from captum.attr._utils.approximation_methods import Riemann, riemann_builders
from tests.helpers.basic import assertTensorAlmostEqual
from captum.testing.helpers.basic import assertTensorAlmostEqual


class Test(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/attr/test_baselines.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from captum.attr._utils.baselines import ProductBaselines

# from parameterized import parameterized
from tests.helpers import BaseTest
from captum.testing.helpers import BaseTest


class TestProductBaselines(BaseTest):
Expand Down
2 changes: 1 addition & 1 deletion tests/attr/test_class_summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import torch
from captum.attr import ClassSummarizer, CommonStats
from tests.helpers import BaseTest
from captum.testing.helpers import BaseTest


class Test(BaseTest):
Expand Down
Loading

0 comments on commit b487891

Please sign in to comment.