From fbe963ada4f42b427135fd744d3c7b01d97b84f2 Mon Sep 17 00:00:00 2001 From: anzr299 Date: Thu, 18 Jun 2026 10:18:27 +0400 Subject: [PATCH 1/5] init --- src/nncf/common/tensor_statistics/collectors.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nncf/common/tensor_statistics/collectors.py b/src/nncf/common/tensor_statistics/collectors.py index 2ee9cd362b9..8505089ce76 100644 --- a/src/nncf/common/tensor_statistics/collectors.py +++ b/src/nncf/common/tensor_statistics/collectors.py @@ -930,7 +930,9 @@ def _register_reduced_input_impl(self, x: Tensor) -> None: trace = fns.sum(fns.multiply(x, x)) # NOTE: average trace?? divide by number of diagonal elements # TODO(dlyakhov): revise this formula as possibly it is with an error; adopted from previous HAWQ implementation - self._container = (self._container + trace) / x.size + # We normalize the trace by the number of elements in the tensor so that larger matrices do not dominate + # the sensitivity scores + self._container += trace / x.size def _aggregate_impl(self) -> Tensor: return self._container * 2 / self._collected_samples From 0234de3de1481dc690a431ce6255dfcba9703a31 Mon Sep 17 00:00:00 2001 From: anzr299 Date: Thu, 18 Jun 2026 10:48:41 +0400 Subject: [PATCH 2/5] update refs --- tests/common/test_reducers_and_aggregators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/common/test_reducers_and_aggregators.py b/tests/common/test_reducers_and_aggregators.py index 53b4fa98a6f..b0912751393 100644 --- a/tests/common/test_reducers_and_aggregators.py +++ b/tests/common/test_reducers_and_aggregators.py @@ -714,8 +714,8 @@ def test_aggregators_hash(self, aggregator_cls): HAWQ_AGGREGATOR_REFERENCE_VALUES = [ ([np.arange(10)], 57.0), - ([np.arange(12).reshape((2, 6)), np.arange(24).reshape((4, 6))], 181.92361111111111), - ([np.arange(8 * i).reshape((1, 8, i)) for i in range(1, 5)], 165.61627197265625), + ([np.arange(12).reshape((2, 6)), np.arange(24).reshape((4, 6))], 222.33333333333331), + ([np.arange(8 * i).reshape((1, 8, i)) for i in range(1, 5)], 300.3333333333333), ] @pytest.mark.parametrize("inputs,reference_output", HAWQ_AGGREGATOR_REFERENCE_VALUES) From 635f434b022afbef4223f7c13e6323ec5ed03346 Mon Sep 17 00:00:00 2001 From: anzr299 Date: Thu, 18 Jun 2026 11:19:42 +0400 Subject: [PATCH 3/5] add reset in HAWQagrgegator --- src/nncf/common/tensor_statistics/collectors.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/nncf/common/tensor_statistics/collectors.py b/src/nncf/common/tensor_statistics/collectors.py index 8505089ce76..3c74d09366a 100644 --- a/src/nncf/common/tensor_statistics/collectors.py +++ b/src/nncf/common/tensor_statistics/collectors.py @@ -934,6 +934,10 @@ def _register_reduced_input_impl(self, x: Tensor) -> None: # the sensitivity scores self._container += trace / x.size + def reset(self) -> None: + self._collected_samples = 0 + self._container: Tensor = Tensor(0.0) # type: ignore[assignment] + def _aggregate_impl(self) -> Tensor: return self._container * 2 / self._collected_samples From cf95d5cbf919ad4adc9aea4a19c0518a2e107874 Mon Sep 17 00:00:00 2001 From: anzr299 Date: Thu, 18 Jun 2026 11:43:17 +0400 Subject: [PATCH 4/5] mypy --- src/nncf/common/tensor_statistics/collectors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nncf/common/tensor_statistics/collectors.py b/src/nncf/common/tensor_statistics/collectors.py index 3c74d09366a..eb49a8eba78 100644 --- a/src/nncf/common/tensor_statistics/collectors.py +++ b/src/nncf/common/tensor_statistics/collectors.py @@ -936,7 +936,7 @@ def _register_reduced_input_impl(self, x: Tensor) -> None: def reset(self) -> None: self._collected_samples = 0 - self._container: Tensor = Tensor(0.0) # type: ignore[assignment] + self._container = Tensor(0.0) def _aggregate_impl(self) -> Tensor: return self._container * 2 / self._collected_samples From a93109e32051be989f88d9f0cc7b69c7e79cc404 Mon Sep 17 00:00:00 2001 From: Aamir Nazir Date: Fri, 19 Jun 2026 12:47:07 +0400 Subject: [PATCH 5/5] Update collectors.py --- src/nncf/common/tensor_statistics/collectors.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/nncf/common/tensor_statistics/collectors.py b/src/nncf/common/tensor_statistics/collectors.py index eb49a8eba78..a3666b6718e 100644 --- a/src/nncf/common/tensor_statistics/collectors.py +++ b/src/nncf/common/tensor_statistics/collectors.py @@ -928,8 +928,6 @@ def __init__(self, num_samples: int | None = None): def _register_reduced_input_impl(self, x: Tensor) -> None: trace = fns.sum(fns.multiply(x, x)) - # NOTE: average trace?? divide by number of diagonal elements - # TODO(dlyakhov): revise this formula as possibly it is with an error; adopted from previous HAWQ implementation # We normalize the trace by the number of elements in the tensor so that larger matrices do not dominate # the sensitivity scores self._container += trace / x.size