Skip to content

Commit

Permalink
Move test_templates to cross_fw directory (#2887)
Browse files Browse the repository at this point in the history
### Changes

Move all templates classes to separate directory.

### Reason

Improve organization of test files and maintainability
  • Loading branch information
AlexanderDokuchaev authored Aug 28, 2024
1 parent 23ca5e8 commit b4e216d
Show file tree
Hide file tree
Showing 43 changed files with 93 additions and 96 deletions.
2 changes: 1 addition & 1 deletion tests/common/quantization/test_layerwise_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import pytest

from nncf.quantization.algorithms.layerwise.scheduler import LayerwiseScheduler
from tests.post_training.test_templates.models import NNCFGraphCAWithBias
from tests.cross_fw.test_templates.models import NNCFGraphCAWithBias


@pytest.mark.parametrize("add_additional_outputs", [False, True])
Expand Down
4 changes: 2 additions & 2 deletions tests/common/quantization/test_passes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from nncf.common.graph.operator_metatypes import OperatorMetatype
from nncf.quantization.passes import filter_constant_nodes
from nncf.quantization.passes import remove_nodes_and_reconnect_graph
from tests.post_training.test_templates.models import NNCFGraphDropoutRemovingCase
from tests.post_training.test_templates.models import NNCFGraphToTestConstantFiltering
from tests.cross_fw.test_templates.models import NNCFGraphDropoutRemovingCase
from tests.cross_fw.test_templates.models import NNCFGraphToTestConstantFiltering
from tests.shared.nx_graph import compare_nx_graph_with_reference
from tests.shared.paths import TEST_ROOT

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
from nncf.quantization.algorithms.bias_correction.algorithm import BiasCorrection
from nncf.quantization.algorithms.bias_correction.backend import BiasCorrectionAlgoBackend
from nncf.quantization.algorithms.post_training.algorithm import PostTrainingQuantization
from tests.post_training.test_templates.helpers import ConvTestModel
from tests.post_training.test_templates.helpers import MultipleConvTestModel
from tests.post_training.test_templates.helpers import SplittedModel
from tests.post_training.test_templates.helpers import StaticDatasetMock
from tests.cross_fw.test_templates.helpers import ConvTestModel
from tests.cross_fw.test_templates.helpers import MultipleConvTestModel
from tests.cross_fw.test_templates.helpers import SplittedModel
from tests.cross_fw.test_templates.helpers import StaticDatasetMock

TModel = TypeVar("TModel")
TTensor = TypeVar("TTensor")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from abc import ABC
from abc import abstractmethod
from dataclasses import dataclass
from pathlib import Path

import numpy as np
import pytest
Expand All @@ -24,10 +25,11 @@
from nncf.quantization.fake_quantize import FakeQuantizeParameters
from nncf.quantization.fake_quantize import calculate_quantizer_parameters
from nncf.tensor import functions as fns
from tests.post_training.conftest import FQ_CALCULATED_PARAMETERS_PATH
from tests.shared.helpers import dump_to_json
from tests.shared.helpers import load_json

FQ_CALCULATED_PARAMETERS_PATH = Path(__file__).parent / "fq_params" / "fq_params.json"


def compare_fq_parameters(ref_params, params):
assert ref_params.levels == params.levels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
from nncf.quantization.algorithms.channel_alignment.algorithm import ChannelAlignment
from nncf.quantization.algorithms.channel_alignment.backend import ChannelAlignmentAlgoBackend
from nncf.quantization.algorithms.channel_alignment.backend import LayoutDescriptor
from tests.post_training.test_templates.models import NNCFGraphCA
from tests.post_training.test_templates.models import NNCFGraphCAWithBias
from tests.cross_fw.test_templates.models import NNCFGraphCA
from tests.cross_fw.test_templates.models import NNCFGraphCAWithBias

EPS = 1e-3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from nncf.quantization.algorithms.fast_bias_correction.algorithm import FastBiasCorrection
from nncf.quantization.algorithms.fast_bias_correction.backend import FastBiasCorrectionAlgoBackend
from nncf.quantization.algorithms.post_training.algorithm import PostTrainingQuantization
from tests.post_training.test_templates.helpers import ConvBNTestModel
from tests.post_training.test_templates.helpers import ConvTestModel
from tests.post_training.test_templates.helpers import get_static_dataset
from tests.cross_fw.test_templates.helpers import ConvBNTestModel
from tests.cross_fw.test_templates.helpers import ConvTestModel
from tests.cross_fw.test_templates.helpers import get_static_dataset

TModel = TypeVar("TModel")
TTensor = TypeVar("TTensor")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from nncf.common.factory import StatisticsAggregatorFactory
from nncf.quantization.algorithms.layerwise.engine import LayerwiseEngine
from nncf.tensor import functions as fns
from tests.post_training.test_templates.helpers import ConvTestModel
from tests.post_training.test_templates.helpers import get_static_dataset
from tests.cross_fw.test_templates.helpers import ConvTestModel
from tests.cross_fw.test_templates.helpers import get_static_dataset

TModel = TypeVar("TModel")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
from nncf.quantization.algorithms.min_max.algorithm import MinMaxQuantization
from nncf.quantization.passes import transform_to_inference_graph
from nncf.quantization.range_estimator import RangeEstimatorParametersSet
from tests.post_training.test_templates.models import NNCFGraphToTest
from tests.post_training.test_templates.models import NNCFGraphToTestDepthwiseConv
from tests.post_training.test_templates.models import NNCFGraphToTestSumAggregation
from tests.cross_fw.test_templates.models import NNCFGraphToTest
from tests.cross_fw.test_templates.models import NNCFGraphToTestDepthwiseConv
from tests.cross_fw.test_templates.models import NNCFGraphToTestSumAggregation


class TemplateTestQuantizerConfig:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
from nncf.quantization.algorithms.post_training.algorithm import PostTrainingQuantization
from nncf.quantization.algorithms.smooth_quant.algorithm import SmoothQuant
from nncf.quantization.algorithms.smooth_quant.backend import SmoothQuantAlgoBackend
from tests.post_training.test_templates.helpers import ConvTestModel
from tests.post_training.test_templates.helpers import LinearMultiShapeModel
from tests.post_training.test_templates.helpers import NonZeroLinearModel
from tests.post_training.test_templates.helpers import ShareWeghtsConvAndShareLinearModel
from tests.post_training.test_templates.helpers import get_static_dataset
from tests.cross_fw.test_templates.helpers import ConvTestModel
from tests.cross_fw.test_templates.helpers import LinearMultiShapeModel
from tests.cross_fw.test_templates.helpers import NonZeroLinearModel
from tests.cross_fw.test_templates.helpers import ShareWeghtsConvAndShareLinearModel
from tests.cross_fw.test_templates.helpers import get_static_dataset

TModel = TypeVar("TModel")
TTensor = TypeVar("TTensor")
Expand Down
8 changes: 4 additions & 4 deletions tests/onnx/quantization/test_bias_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
from nncf.onnx.graph.nncf_graph_builder import GraphConverter
from nncf.onnx.graph.node_utils import get_bias_value
from nncf.quantization.algorithms.bias_correction.onnx_backend import ONNXBiasCorrectionAlgoBackend
from tests.cross_fw.test_templates.helpers import ConvTestModel
from tests.cross_fw.test_templates.helpers import MultipleConvTestModel
from tests.cross_fw.test_templates.helpers import SplittedModel
from tests.cross_fw.test_templates.test_bias_correction import TemplateTestBCAlgorithm
from tests.onnx.quantization.common import compare_nncf_graph
from tests.post_training.test_templates.helpers import ConvTestModel
from tests.post_training.test_templates.helpers import MultipleConvTestModel
from tests.post_training.test_templates.helpers import SplittedModel
from tests.post_training.test_templates.test_bias_correction import TemplateTestBCAlgorithm
from tests.shared.paths import TEST_ROOT


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from nncf.onnx.quantization.quantizer_parameters import get_level_low_level_high
from nncf.quantization.fake_quantize import calculate_scale_zero_point
from nncf.tensor import Tensor
from tests.post_training.test_templates.test_calculate_quantizer_parameters import TemplateTestFQParams
from tests.cross_fw.test_templates.test_calculate_quantizer_parameters import TemplateTestFQParams

EPS = np.finfo(np.float32).eps

Expand Down
2 changes: 1 addition & 1 deletion tests/onnx/quantization/test_fast_bias_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from nncf.onnx.graph.node_utils import get_bias_value
from nncf.onnx.graph.node_utils import is_node_with_bias
from nncf.quantization.algorithms.fast_bias_correction.onnx_backend import ONNXFastBiasCorrectionAlgoBackend
from tests.post_training.test_templates.test_fast_bias_correction import TemplateTestFBCAlgorithm
from tests.cross_fw.test_templates.test_fast_bias_correction import TemplateTestFBCAlgorithm


def get_data_from_node(model: onnx.ModelProto, node_name: str):
Expand Down
10 changes: 5 additions & 5 deletions tests/onnx/quantization/test_min_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
from nncf.onnx.graph.transformations.commands import ONNXTargetPoint
from nncf.quantization.algorithms.min_max.backend import MinMaxAlgoBackend
from nncf.quantization.algorithms.min_max.onnx_backend import ONNXMinMaxAlgoBackend
from tests.post_training.test_templates.models import NNCFGraphToTest
from tests.post_training.test_templates.test_min_max import MATMUL_WEIGHT_SHAPE
from tests.post_training.test_templates.test_min_max import TemplateTestGetChannelAxes
from tests.post_training.test_templates.test_min_max import TemplateTestGetTargetPointShape
from tests.post_training.test_templates.test_min_max import TemplateTestMinMaxAlgorithm
from tests.cross_fw.test_templates.models import NNCFGraphToTest
from tests.cross_fw.test_templates.test_min_max import MATMUL_WEIGHT_SHAPE
from tests.cross_fw.test_templates.test_min_max import TemplateTestGetChannelAxes
from tests.cross_fw.test_templates.test_min_max import TemplateTestGetTargetPointShape
from tests.cross_fw.test_templates.test_min_max import TemplateTestMinMaxAlgorithm


class TestONNXMinMaxAlgorithm(TemplateTestMinMaxAlgorithm):
Expand Down
6 changes: 3 additions & 3 deletions tests/onnx/quantization/test_ptq_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
from tests.common.quantization.metatypes import Conv2dTestMetatype
from tests.common.quantization.metatypes import LinearTestMetatype
from tests.common.quantization.metatypes import SoftmaxTestMetatype
from tests.cross_fw.test_templates.models import NNCFGraphToTest
from tests.cross_fw.test_templates.models import NNCFGraphToTestMatMul
from tests.cross_fw.test_templates.test_ptq_params import TemplateTestPTQParams
from tests.onnx.models import LinearModel
from tests.onnx.models import OneDepthwiseConvolutionalModel
from tests.post_training.test_templates.models import NNCFGraphToTest
from tests.post_training.test_templates.models import NNCFGraphToTestMatMul
from tests.post_training.test_templates.test_ptq_params import TemplateTestPTQParams


def get_hw_patterns(device: TargetDevice = TargetDevice.ANY) -> GraphPattern:
Expand Down
8 changes: 4 additions & 4 deletions tests/onnx/quantization/test_quantizer_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from nncf.onnx.graph.metatypes.onnx_metatypes import ONNXDepthwiseConvolutionMetatype
from nncf.onnx.graph.nncf_graph_builder import ONNXLayerAttributes
from nncf.quantization.algorithms.min_max.onnx_backend import ONNXMinMaxAlgoBackend
from tests.post_training.test_templates.models import NNCFGraphToTest
from tests.post_training.test_templates.models import NNCFGraphToTestDepthwiseConv
from tests.post_training.test_templates.models import NNCFGraphToTestSumAggregation
from tests.post_training.test_templates.test_quantizer_config import TemplateTestQuantizerConfig
from tests.cross_fw.test_templates.models import NNCFGraphToTest
from tests.cross_fw.test_templates.models import NNCFGraphToTestDepthwiseConv
from tests.cross_fw.test_templates.models import NNCFGraphToTestSumAggregation
from tests.cross_fw.test_templates.test_quantizer_config import TemplateTestQuantizerConfig


class TestQuantizerConfig(TemplateTestQuantizerConfig):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from nncf.tensor import Tensor
from tests.post_training.test_templates.test_calculate_quantizer_parameters import TemplateTestFQParams
from tests.cross_fw.test_templates.test_calculate_quantizer_parameters import TemplateTestFQParams


class TestFQParams(TemplateTestFQParams):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from nncf.openvino.graph.transformations.commands import OVWeightUpdateCommand
from nncf.quantization.algorithms.channel_alignment.backend import LayoutDescriptor
from nncf.quantization.algorithms.channel_alignment.openvino_backend import OVChannelAlignmentAlgoBackend
from tests.post_training.test_templates.test_channel_alignment import TemplateTestChannelAlignment
from tests.cross_fw.test_templates.test_channel_alignment import TemplateTestChannelAlignment


class TestOVChannelAlignment(TemplateTestChannelAlignment):
Expand Down
8 changes: 4 additions & 4 deletions tests/openvino/native/quantization/test_min_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
from nncf.openvino.graph.transformations.commands import OVTargetPoint
from nncf.quantization.algorithms.min_max.backend import MinMaxAlgoBackend
from nncf.quantization.algorithms.min_max.openvino_backend import OVMinMaxAlgoBackend
from tests.post_training.test_templates.models import NNCFGraphToTest
from tests.post_training.test_templates.test_min_max import TemplateTestGetChannelAxes
from tests.post_training.test_templates.test_min_max import TemplateTestGetTargetPointShape
from tests.post_training.test_templates.test_min_max import TemplateTestMinMaxAlgorithm
from tests.cross_fw.test_templates.models import NNCFGraphToTest
from tests.cross_fw.test_templates.test_min_max import TemplateTestGetChannelAxes
from tests.cross_fw.test_templates.test_min_max import TemplateTestGetTargetPointShape
from tests.cross_fw.test_templates.test_min_max import TemplateTestMinMaxAlgorithm


class TestOVMinMaxAlgorithm(TemplateTestMinMaxAlgorithm):
Expand Down
4 changes: 2 additions & 2 deletions tests/openvino/native/quantization/test_ptq_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
from tests.common.quantization.metatypes import Conv2dTestMetatype
from tests.common.quantization.metatypes import LinearTestMetatype
from tests.common.quantization.metatypes import SoftmaxTestMetatype
from tests.cross_fw.test_templates.models import NNCFGraphToTestMatMul
from tests.cross_fw.test_templates.test_ptq_params import TemplateTestPTQParams
from tests.openvino.native.models import DepthwiseConv4DModel
from tests.openvino.native.models import LinearModel
from tests.post_training.test_templates.models import NNCFGraphToTestMatMul
from tests.post_training.test_templates.test_ptq_params import TemplateTestPTQParams


def get_hw_patterns(device: TargetDevice = TargetDevice.ANY) -> GraphPattern:
Expand Down
8 changes: 4 additions & 4 deletions tests/openvino/native/quantization/test_quantizer_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from nncf.openvino.graph.metatypes.openvino_metatypes import OVDepthwiseConvolutionMetatype
from nncf.openvino.graph.metatypes.openvino_metatypes import OVSumMetatype
from nncf.quantization.algorithms.min_max.openvino_backend import OVMinMaxAlgoBackend
from tests.post_training.test_templates.models import NNCFGraphToTest
from tests.post_training.test_templates.models import NNCFGraphToTestDepthwiseConv
from tests.post_training.test_templates.models import NNCFGraphToTestSumAggregation
from tests.post_training.test_templates.test_quantizer_config import TemplateTestQuantizerConfig
from tests.cross_fw.test_templates.models import NNCFGraphToTest
from tests.cross_fw.test_templates.models import NNCFGraphToTestDepthwiseConv
from tests.cross_fw.test_templates.models import NNCFGraphToTestSumAggregation
from tests.cross_fw.test_templates.test_quantizer_config import TemplateTestQuantizerConfig


class TestQuantizerConfig(TemplateTestQuantizerConfig):
Expand Down
8 changes: 4 additions & 4 deletions tests/openvino/native/test_bias_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
from nncf.openvino.graph.nncf_graph_builder import GraphConverter
from nncf.openvino.graph.node_utils import get_bias_value
from nncf.quantization.algorithms.bias_correction.openvino_backend import OVBiasCorrectionAlgoBackend
from tests.cross_fw.test_templates.helpers import ConvTestModel
from tests.cross_fw.test_templates.helpers import MultipleConvTestModel
from tests.cross_fw.test_templates.helpers import SplittedModel
from tests.cross_fw.test_templates.test_bias_correction import TemplateTestBCAlgorithm
from tests.openvino.native.common import compare_nncf_graphs
from tests.openvino.native.common import get_actual_reference_for_current_openvino
from tests.post_training.test_templates.helpers import ConvTestModel
from tests.post_training.test_templates.helpers import MultipleConvTestModel
from tests.post_training.test_templates.helpers import SplittedModel
from tests.post_training.test_templates.test_bias_correction import TemplateTestBCAlgorithm


class TestOVBCAlgorithm(TemplateTestBCAlgorithm):
Expand Down
2 changes: 1 addition & 1 deletion tests/openvino/native/test_fast_bias_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from nncf.openvino.graph.node_utils import get_bias_value
from nncf.openvino.graph.node_utils import is_node_with_bias
from nncf.quantization.algorithms.fast_bias_correction.openvino_backend import OVFastBiasCorrectionAlgoBackend
from tests.post_training.test_templates.test_fast_bias_correction import TemplateTestFBCAlgorithm
from tests.cross_fw.test_templates.test_fast_bias_correction import TemplateTestFBCAlgorithm


class TestOVFBCAlgorithm(TemplateTestFBCAlgorithm):
Expand Down
2 changes: 1 addition & 1 deletion tests/openvino/native/test_layerwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from nncf.quantization.algorithms.layerwise.scheduler import LayerwiseStep
from nncf.quantization.algorithms.layerwise.scheduler import NodeOutputPort
from nncf.tensor import Tensor
from tests.post_training.test_templates.test_layerwise import TemplateTestLayerwiseEngine
from tests.cross_fw.test_templates.test_layerwise import TemplateTestLayerwiseEngine


class TestOVLayerwiseEngine(TemplateTestLayerwiseEngine):
Expand Down
8 changes: 4 additions & 4 deletions tests/openvino/native/test_smooth_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
from nncf.openvino.graph.metatypes.openvino_metatypes import OVConvolutionMetatype
from nncf.openvino.graph.metatypes.openvino_metatypes import OVMatMulMetatype
from nncf.quantization.algorithms.smooth_quant.openvino_backend import OVSmoothQuantAlgoBackend
from tests.post_training.test_templates.helpers import ConvTestModel
from tests.post_training.test_templates.helpers import LinearMultiShapeModel
from tests.post_training.test_templates.helpers import ShareWeghtsConvAndShareLinearModel
from tests.post_training.test_templates.test_smooth_quant import TemplateTestSQAlgorithm
from tests.cross_fw.test_templates.helpers import ConvTestModel
from tests.cross_fw.test_templates.helpers import LinearMultiShapeModel
from tests.cross_fw.test_templates.helpers import ShareWeghtsConvAndShareLinearModel
from tests.cross_fw.test_templates.test_smooth_quant import TemplateTestSQAlgorithm

OV_LINEAR_MODEL_MM_OP_MAP = {
"MatMul1": "aten::matmul/MatMul",
Expand Down
5 changes: 0 additions & 5 deletions tests/post_training/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from tests.shared.paths import TEST_ROOT

PTQ_TEST_ROOT = TEST_ROOT / "post_training"
FQ_CALCULATED_PARAMETERS_PATH = PTQ_TEST_ROOT / "data" / "fq_params" / "fq_params.json"


def pytest_addoption(parser):
parser.addoption("--data", action="store", help="Data directory")
Expand Down
2 changes: 1 addition & 1 deletion tests/torch/fx/test_fast_bias_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from nncf.quantization.algorithms.fast_bias_correction.torch_fx_backend import FXFastBiasCorrectionAlgoBackend
from nncf.torch.dynamic_graph.patch_pytorch import disable_patching
from nncf.torch.model_graph_manager import OPERATORS_WITH_BIAS_METATYPES
from tests.post_training.test_templates.test_fast_bias_correction import TemplateTestFBCAlgorithm
from tests.cross_fw.test_templates.test_fast_bias_correction import TemplateTestFBCAlgorithm


class TestTorchFXFBCAlgorithm(TemplateTestFBCAlgorithm):
Expand Down
8 changes: 4 additions & 4 deletions tests/torch/fx/test_smooth_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
from nncf.torch import disable_patching
from nncf.torch.graph.operator_metatypes import PTConv2dMetatype
from nncf.torch.graph.operator_metatypes import PTLinearMetatype
from tests.post_training.test_templates.helpers import ConvTestModel
from tests.post_training.test_templates.helpers import LinearMultiShapeModel
from tests.post_training.test_templates.helpers import ShareWeghtsConvAndShareLinearModel
from tests.post_training.test_templates.test_smooth_quant import TemplateTestSQAlgorithm
from tests.cross_fw.test_templates.helpers import ConvTestModel
from tests.cross_fw.test_templates.helpers import LinearMultiShapeModel
from tests.cross_fw.test_templates.helpers import ShareWeghtsConvAndShareLinearModel
from tests.cross_fw.test_templates.test_smooth_quant import TemplateTestSQAlgorithm

PT_LINEAR_MODEL_MM_MAP = {"Linear1": "linear_3", "Linear2": "linear_2", "Linear3": "linear", "Linear4": "linear_1"}

Expand Down
Loading

0 comments on commit b4e216d

Please sign in to comment.