Skip to content

Commit

Permalink
upd reference
Browse files Browse the repository at this point in the history
  • Loading branch information
kshpv committed Jan 21, 2025
1 parent e3f12c2 commit a347a25
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,17 @@ 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])

_ = compress_weights(
model,
mode=CompressWeightsMode.INT4_ASYM,
ratio=1.0,
group_size=32,
group_size=4,
scale_estimation=True,
all_layers=True,
dataset=dataset,
Expand Down
6 changes: 3 additions & 3 deletions tests/openvino/native/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
44 changes: 10 additions & 34 deletions tests/openvino/native/quantization/test_weights_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]],
]
)
42 changes: 9 additions & 33 deletions tests/torch/ptq/test_weights_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
]
)

0 comments on commit a347a25

Please sign in to comment.