Skip to content

Commit

Permalink
Moving tests.attr.helpers to captum.testing.attr.helpers (#1492)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #1492

This Diff is to move the tests.attr.helpers functions away from the tests namespace and move it inside the captum library.

Reviewed By: jjuncho

Differential Revision: D68445008

fbshipit-source-id: eeeeb1211f570c5f6867db3886cf18438f6c0334
  • Loading branch information
styusuf authored and facebook-github-bot committed Jan 21, 2025
1 parent b487891 commit a255953
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 49 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/attr/layer/test_layer_conductance.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import torch
from captum._utils.typing import BaselineType
from captum.attr._core.layer.layer_conductance import LayerConductance
from captum.testing.attr.helpers.conductance_reference import ConductanceReference
from captum.testing.helpers.basic import (
assertTensorAlmostEqual,
assertTensorTuplesAlmostEqual,
Expand All @@ -19,7 +20,6 @@
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
8 changes: 4 additions & 4 deletions tests/attr/layer/test_layer_deeplift.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

import torch
from captum.attr._core.layer.layer_deep_lift import LayerDeepLift, LayerDeepLiftShap
from captum.testing.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 captum.testing.helpers.basic import (
assert_delta,
assertTensorAlmostEqual,
Expand All @@ -24,10 +28,6 @@
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
2 changes: 1 addition & 1 deletion tests/attr/layer/test_layer_gradient_shap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
LayerGradientShap,
LayerInputBaselineXGradient,
)
from captum.testing.attr.helpers.attribution_delta_util import assert_attribution_delta
from captum.testing.helpers.basic import (
assertTensorAlmostEqual,
assertTensorTuplesAlmostEqual,
Expand All @@ -24,7 +25,6 @@
)
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
8 changes: 4 additions & 4 deletions tests/attr/neuron/test_neuron_deeplift.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import torch
from captum._utils.typing import TensorOrTupleOfTensorsGeneric
from captum.attr._core.neuron.neuron_deep_lift import NeuronDeepLift, NeuronDeepLiftShap
from captum.testing.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 captum.testing.helpers import BaseTest
from captum.testing.helpers.basic import assertTensorAlmostEqual
from captum.testing.helpers.basic_models import (
Expand All @@ -17,10 +21,6 @@
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
14 changes: 7 additions & 7 deletions tests/attr/test_data_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
)
from captum.attr._core.noise_tunnel import NoiseTunnel
from captum.attr._utils.attribution import Attribution, InternalAttribution
from captum.testing.helpers.basic import (
assertTensorTuplesAlmostEqual,
BaseTest,
deep_copy_args,
)
from tests.attr.helpers.gen_test_utils import (
from captum.testing.attr.helpers.gen_test_utils import (
gen_test_name,
get_target_layer,
parse_test_config,
should_create_generated_test,
)
from tests.attr.helpers.test_config import config
from captum.testing.attr.helpers.test_config import config
from captum.testing.helpers.basic import (
assertTensorTuplesAlmostEqual,
BaseTest,
deep_copy_args,
)
from torch import Tensor
from torch.nn import Module

Expand Down
8 changes: 4 additions & 4 deletions tests/attr/test_gradient_shap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from captum._utils.typing import Tensor
from captum.attr._core.gradient_shap import GradientShap
from captum.attr._core.integrated_gradients import IntegratedGradients
from captum.testing.attr.helpers.attribution_delta_util import (
assert_attribution_delta,
assert_delta,
)
from captum.testing.helpers import BaseTest
from captum.testing.helpers.basic import assertTensorAlmostEqual
from captum.testing.helpers.basic_models import BasicLinearModel, BasicModel2
from captum.testing.helpers.classification_models import SoftmaxModel
from tests.attr.helpers.attribution_delta_util import (
assert_attribution_delta,
assert_delta,
)


class Test(BaseTest):
Expand Down
10 changes: 5 additions & 5 deletions tests/attr/test_hook_removal.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
from captum.attr._core.noise_tunnel import NoiseTunnel
from captum.attr._models.base import _set_deep_layer_value
from captum.attr._utils.attribution import Attribution, InternalAttribution
from captum.testing.helpers import BaseTest
from captum.testing.helpers.basic import deep_copy_args
from tests.attr.helpers.gen_test_utils import (
from captum.testing.attr.helpers.gen_test_utils import (
gen_test_name,
get_target_layer,
parse_test_config,
should_create_generated_test,
)
from tests.attr.helpers.test_config import config
from captum.testing.attr.helpers.test_config import config
from captum.testing.helpers import BaseTest
from captum.testing.helpers.basic import deep_copy_args
from torch.nn import Module

"""
Tests in this file are dynamically generated based on the config
defined in tests/attr/helpers/test_config.py. To add new test cases,
defined in captum/testing/attr/helpers/test_config.py. To add new test cases,
read the documentation in test_config.py and add cases based on the
schema described there.
"""
Expand Down
8 changes: 4 additions & 4 deletions tests/attr/test_input_x_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from captum._utils.typing import TensorOrTupleOfTensorsGeneric
from captum.attr._core.input_x_gradient import InputXGradient
from captum.attr._core.noise_tunnel import NoiseTunnel
from captum.testing.helpers import BaseTest
from captum.testing.helpers.basic import assertTensorAlmostEqual
from captum.testing.helpers.classification_models import SoftmaxModel
from tests.attr.helpers.get_config_util import (
from captum.testing.attr.helpers.get_config_util import (
get_basic_config,
get_multiargs_basic_config,
)
from captum.testing.helpers import BaseTest
from captum.testing.helpers.basic import assertTensorAlmostEqual
from captum.testing.helpers.classification_models import SoftmaxModel
from torch import Tensor
from torch.nn import Module

Expand Down
12 changes: 6 additions & 6 deletions tests/attr/test_jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
from captum.attr._core.saliency import Saliency
from captum.attr._core.shapley_value import ShapleyValueSampling
from captum.attr._utils.attribution import Attribution
from captum.testing.attr.helpers.gen_test_utils import (
gen_test_name,
parse_test_config,
should_create_generated_test,
)
from captum.testing.attr.helpers.test_config import config
from captum.testing.helpers.basic import (
assertTensorTuplesAlmostEqual,
BaseTest,
deep_copy_args,
)
from tests.attr.helpers.gen_test_utils import (
gen_test_name,
parse_test_config,
should_create_generated_test,
)
from tests.attr.helpers.test_config import config
from torch import Tensor
from torch.nn import Module

Expand Down
12 changes: 6 additions & 6 deletions tests/attr/test_saliency.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
from captum._utils.typing import TensorOrTupleOfTensorsGeneric
from captum.attr._core.noise_tunnel import NoiseTunnel
from captum.attr._core.saliency import Saliency

from captum.testing.attr.helpers.get_config_util import (
get_basic_config,
get_multiargs_basic_config,
get_multiargs_basic_config_large,
)
from captum.testing.helpers.basic import (
assertTensorAlmostEqual,
assertTensorTuplesAlmostEqual,
BaseTest,
)
from captum.testing.helpers.classification_models import SoftmaxModel

from tests.attr.helpers.get_config_util import (
get_basic_config,
get_multiargs_basic_config,
get_multiargs_basic_config_large,
)
from torch import Tensor
from torch.nn import Module

Expand Down
14 changes: 7 additions & 7 deletions tests/attr/test_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
from captum.attr._core.lime import Lime
from captum.attr._core.noise_tunnel import NoiseTunnel
from captum.attr._utils.attribution import Attribution, InternalAttribution
from captum.testing.attr.helpers.gen_test_utils import (
gen_test_name,
get_target_layer,
parse_test_config,
should_create_generated_test,
)
from captum.testing.attr.helpers.test_config import config
from captum.testing.helpers.basic import (
assertTensorTuplesAlmostEqual,
BaseTest,
deep_copy_args,
)
from captum.testing.helpers.basic_models import BasicModel_MultiLayer
from tests.attr.helpers.gen_test_utils import (
gen_test_name,
get_target_layer,
parse_test_config,
should_create_generated_test,
)
from tests.attr.helpers.test_config import config
from torch import Tensor
from torch.nn import Module

Expand Down

0 comments on commit a255953

Please sign in to comment.