From a347a2598d063822a0deb98fe369468792433f7d Mon Sep 17 00:00:00 2001 From: Aleksei Kashapov Date: Tue, 21 Jan 2025 14:50:20 +0100 Subject: [PATCH] upd reference --- .../template_test_weights_compression.py | 7 +-- tests/openvino/native/models.py | 6 +-- .../quantization/test_weights_compression.py | 44 +++++-------------- tests/torch/ptq/test_weights_compression.py | 42 ++++-------------- 4 files changed, 26 insertions(+), 73 deletions(-) diff --git a/tests/cross_fw/test_templates/template_test_weights_compression.py b/tests/cross_fw/test_templates/template_test_weights_compression.py index d5bdf386300..31cfa669df1 100644 --- a/tests/cross_fw/test_templates/template_test_weights_compression.py +++ b/tests/cross_fw/test_templates/template_test_weights_compression.py @@ -147,8 +147,9 @@ def test_scale_estimation(self, mocker): model = self.get_model_for_test_scale_estimation() # prepare dataset with one input tensor - input = np.arange(0, 32 * 32, dtype=np.float32).reshape(1, 32, 32) - input[0, 15] *= 100 # make one channel relatively higher. + input = np.arange(0, 8 * 8, dtype=np.float32).reshape(1, 8, 8) + input[0, 4] *= 100 # make one channel relatively higher. + input = self.to_tensor(input) dataset = Dataset([input]) @@ -156,7 +157,7 @@ def test_scale_estimation(self, mocker): model, mode=CompressWeightsMode.INT4_ASYM, ratio=1.0, - group_size=32, + group_size=4, scale_estimation=True, all_layers=True, dataset=dataset, diff --git a/tests/openvino/native/models.py b/tests/openvino/native/models.py index 56ef047f97f..c9ec2f8343d 100644 --- a/tests/openvino/native/models.py +++ b/tests/openvino/native/models.py @@ -1187,11 +1187,11 @@ def _create_ov_model(self): return model -class MLP(OVReferenceModel): +class MatMul(OVReferenceModel): def _create_ov_model(self): - input_node = opset.parameter([1, 32, 32], name="Input") + input_node = opset.parameter([1, 8, 8], name="Input") - weights_data = np.arange(0, 32 * 32, dtype=np.float32).reshape(32, 32) + weights_data = np.arange(0, 8 * 8, dtype=np.float32).reshape(8, 8) weights_node = opset.constant(weights_data, dtype=np.float32, name="Weights") matmul_node = opset.matmul(input_node, weights_node, transpose_a=False, transpose_b=True, name="MatMul") diff --git a/tests/openvino/native/quantization/test_weights_compression.py b/tests/openvino/native/quantization/test_weights_compression.py index e0d072cb04a..6128b2d7829 100644 --- a/tests/openvino/native/quantization/test_weights_compression.py +++ b/tests/openvino/native/quantization/test_weights_compression.py @@ -50,13 +50,13 @@ from tests.cross_fw.test_templates.template_test_weights_compression import ACTIVATION from tests.cross_fw.test_templates.template_test_weights_compression import TemplateWeightCompression from tests.openvino.native.common import get_actual_reference_for_current_openvino -from tests.openvino.native.models import MLP from tests.openvino.native.models import AWQActMatmulModel from tests.openvino.native.models import AWQMatmulModel from tests.openvino.native.models import GatherAndMatmulShareData from tests.openvino.native.models import GatherWithTwoReductionAxes from tests.openvino.native.models import IdentityMatmul from tests.openvino.native.models import IntegerModel +from tests.openvino.native.models import MatMul from tests.openvino.native.models import ModelNamedConsts from tests.openvino.native.models import OVReferenceModel from tests.openvino.native.models import SequentialMatmulModel @@ -1550,43 +1550,19 @@ def check_weights(model: ov.Model, ref_ids: List[int]) -> None: @staticmethod def get_model_for_test_scale_estimation(): - return MLP().ov_model + return MatMul().ov_model @staticmethod def get_scale_estimation_ref(): return np.array( [ - [[2.0666666]], - [[3.7624273]], - [[5.884783]], - [[8.03606]], - [[10.136832]], - [[12.291862]], - [[14.34415]], - [[16.449669]], - [[18.608639]], - [[20.802698]], - [[22.9477]], - [[25.083504]], - [[27.152409]], - [[29.141987]], - [[31.171442]], - [[33.044716]], - [[35.178047]], - [[37.31138]], - [[39.444714]], - [[41.578045]], - [[43.71138]], - [[45.844715]], - [[47.978046]], - [[50.11138]], - [[52.244713]], - [[54.378044]], - [[56.511383]], - [[58.644714]], - [[60.77805]], - [[62.91138]], - [[65.044716]], - [[67.17805]], + [[0.2], [0.41354424]], + [[0.6782236], [0.9470368]], + [[1.1691767], [1.4355733]], + [[1.7025099], [1.9689066]], + [[2.2722175], [2.543369]], + [[2.8146443], [3.0858421]], + [[3.3025098], [3.5689068]], + [[3.8358433], [4.1022396]], ] ) diff --git a/tests/torch/ptq/test_weights_compression.py b/tests/torch/ptq/test_weights_compression.py index cee43f783d0..92f90190a0d 100644 --- a/tests/torch/ptq/test_weights_compression.py +++ b/tests/torch/ptq/test_weights_compression.py @@ -383,43 +383,19 @@ def check_weights(model: torch.nn.Module, ref_ids: List[int]) -> None: @staticmethod def get_model_for_test_scale_estimation(): - return LinearModel(torch.arange(0, 32 * 32, dtype=torch.float32).reshape(32, 32)) + return LinearModel(torch.arange(0, 8 * 8, dtype=torch.float32).reshape(8, 8)) @staticmethod def get_scale_estimation_ref(): return torch.tensor( [ - [[2.0666666]], - [[3.7624271]], - [[5.8847833]], - [[8.0360603]], - [[10.1368332]], - [[12.2918606]], - [[14.3441496]], - [[16.4496689]], - [[18.6086369]], - [[20.8027000]], - [[22.9477024]], - [[25.0835018]], - [[27.1524105]], - [[29.1419849]], - [[31.1714401]], - [[33.0447121]], - [[35.1780472]], - [[37.3113823]], - [[39.4447136]], - [[41.5780487]], - [[43.7113838]], - [[45.8447189]], - [[47.9780464]], - [[50.1113815]], - [[52.2447128]], - [[54.3780441]], - [[56.5113831]], - [[58.6447144]], - [[60.7780533]], - [[62.9113808]], - [[65.0447083]], - [[67.1780548]], + [[0.200000], [0.413544]], + [[0.678224], [0.947037]], + [[1.169177], [1.435573]], + [[1.702510], [1.968907]], + [[2.272218], [2.543369]], + [[2.814644], [3.085842]], + [[3.302510], [3.568907]], + [[3.835843], [4.102240]], ] )