diff --git a/nncf/quantization/algorithms/weight_compression/algorithm.py b/nncf/quantization/algorithms/weight_compression/algorithm.py index 81bb4406f0a..99728f6ef8e 100644 --- a/nncf/quantization/algorithms/weight_compression/algorithm.py +++ b/nncf/quantization/algorithms/weight_compression/algorithm.py @@ -498,7 +498,9 @@ def apply( matmul_nodes_to_compress, graph ) if statistic_points is None: - statistic_points = self.get_statistic_points(model, graph, matmul_input_to_output_nodes_map.keys()) + statistic_points = self.get_statistic_points( + model, graph, matmul_input_to_output_nodes_map.keys(), self._subset_size + ) statistic_points = self._collect_statistics(dataset, graph, model, statistic_points) statistics = self._get_statistics_for_weights_compression( matmul_input_to_output_nodes_map, statistic_points @@ -759,7 +761,6 @@ def get_statistic_points( model: TModel, graph: NNCFGraph, nodes_and_port_ids: Iterable[Tuple[NNCFNode, int]], - subset_size: Optional[int] = None, ) -> StatisticPointsContainer: """ Returns statistic points, for which StatisticsCollector should collect statistics. @@ -767,7 +768,6 @@ def get_statistic_points( :param model: Model for statistics collection. :param graph: Model graph. :param nodes_and_port_ids: Nodes and port ids for which statistics should be collected. - :param subset_size: Number of samples to collect. :return: Statistic points, for which StatisticsCollector should collect statistics. """ statistic_container = StatisticPointsContainer() @@ -781,7 +781,7 @@ def get_statistic_points( # size dimension. n_dims = len(graph.get_output_edges_by_port_id(node, output_port_id)[0].tensor_shape) stat_collector = self._backend_entity.mean_statistic_collector( - reduction_axes=tuple(range(n_dims - 1)), subset_size=subset_size + reduction_axes=tuple(range(n_dims - 1)), subset_size=self._subset_size ) statistic_container.add_statistic_point( StatisticPoint( diff --git a/tests/openvino/native/quantization/test_weights_compression.py b/tests/openvino/native/quantization/test_weights_compression.py index db72b267698..ff52f115124 100644 --- a/tests/openvino/native/quantization/test_weights_compression.py +++ b/tests/openvino/native/quantization/test_weights_compression.py @@ -886,25 +886,34 @@ def test_compression_for_different_dtypes(activation_dtype, weight_dtype): check_compressed_matmul_subgraph(scale_multiply_node, activation_dtype, weight_dtype) -DATASET_SIZE = 129 +DATASET_SIZE = 5 @pytest.mark.parametrize( - ("subset_size", "ref_size"), + ("dataset_size", "subset_size", "ref_size"), ( - (1, 1), - (5, 5), - (130, DATASET_SIZE), + (DATASET_SIZE, 1, 1), + (DATASET_SIZE, DATASET_SIZE, DATASET_SIZE), + (DATASET_SIZE, DATASET_SIZE + 1, DATASET_SIZE), ), ) -def test_valid_subset_size(mocker, subset_size, ref_size): +@pytest.mark.parametrize( + ("compression_args", "multiplier_of_calls"), + ( + (dict(mode=CompressWeightsMode.INT4_ASYM, ratio=1), 0), # data-free, no reducers + (dict(mode=CompressWeightsMode.INT4_ASYM, ratio=0.5), 1), # 1 reducer for mixed precision + (dict(mode=CompressWeightsMode.INT4_ASYM, ratio=1, awq=True), 2), # mean & shape reducer for AWQ + (dict(mode=CompressWeightsMode.INT4_ASYM, ratio=0.5, awq=True), 3), # 2 - for AWQ + 1 - for Mixed Precision + ), +) +def test_data_aware_all_layers(mocker, dataset_size, subset_size, ref_size, compression_args, multiplier_of_calls): model = IdentityMatmul().ov_model - dataset = Dataset([ACTIVATION] * DATASET_SIZE) + dataset = Dataset([ACTIVATION] * dataset_size) stats_spy = mocker.spy(AggregatorBase, "register_reduced_input") - compress_weights(model, mode=CompressWeightsMode.INT4_ASYM, ratio=0.5, dataset=dataset, subset_size=subset_size) + compress_weights(model, dataset=dataset, subset_size=subset_size, **compression_args) - assert stats_spy.call_count == ref_size + assert stats_spy.call_count == ref_size * multiplier_of_calls def test_default_subset_value():