Skip to content

Commit

Permalink
Tests adjusted
Browse files Browse the repository at this point in the history
  • Loading branch information
daniil-lyakhov committed Apr 2, 2024
1 parent 765775a commit 8ec693f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
[
[
[
-1.0
-1
]
]
],
[
[
[
-1.0
-1
]
]
]
Expand All @@ -20,14 +20,14 @@
[
[
[
1.0
1
]
]
],
[
[
[
1.0
1
]
]
]
Expand All @@ -38,7 +38,7 @@
[
[
[
-1.0
-1
]
]
]
Expand All @@ -47,18 +47,26 @@
[
[
[
1.0
1
]
]
]
]
},
"TwoConvTestModel/NNCFNetworkInterface[_nncf]/ModuleDict[external_quantizers]/SymmetricQuantizer[/nncf_model_input_0|OUTPUT]": {
"input_low": 0.0,
"input_high": 0.9800970554351807
"input_low": [
0
],
"input_high": [
0.9800970554351807
]
},
"TwoConvTestModel/NNCFNetworkInterface[_nncf]/ModuleDict[external_quantizers]/SymmetricQuantizer[TwoConvTestModel/Sequential[features]/Sequential[0]/NNCFConv2d[0]/conv2d_0|OUTPUT]": {
"input_low": -3.8243322372436523,
"input_high": 3.794454574584961
"input_low": [
-3.8243322372436523
],
"input_high": [
3.794454574584961
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
[
[
[
-2.0
-2
]
]
],
[
[
[
-2.0
-2
]
]
]
Expand All @@ -20,14 +20,14 @@
[
[
[
2.0
2
]
]
],
[
[
[
2.0
2
]
]
]
Expand All @@ -38,7 +38,7 @@
[
[
[
-2.0
-2
]
]
]
Expand All @@ -47,18 +47,26 @@
[
[
[
2.0
2
]
]
]
]
},
"TwoConvTestModel/NNCFNetworkInterface[_nncf]/ModuleDict[external_quantizers]/SymmetricQuantizer[/nncf_model_input_0|OUTPUT]": {
"input_low": 0.0,
"input_high": 0.9800970554351807
"input_low": [
0
],
"input_high": [
0.9800970554351807
]
},
"TwoConvTestModel/NNCFNetworkInterface[_nncf]/ModuleDict[external_quantizers]/SymmetricQuantizer[TwoConvTestModel/Sequential[features]/Sequential[0]/NNCFConv2d[0]/conv2d_0|OUTPUT]": {
"input_low": -3.8243322372436523,
"input_high": 3.794454574584961
"input_low": [
-3.8243322372436523
],
"input_high": [
3.794454574584961
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
[
[
[
-2.0
-2
]
]
],
[
[
[
-2.0
-2
]
]
]
Expand All @@ -20,14 +20,14 @@
[
[
[
2.0
2
]
]
],
[
[
[
2.0
2
]
]
]
Expand All @@ -38,7 +38,7 @@
[
[
[
-1.0
-1
]
]
]
Expand All @@ -47,18 +47,26 @@
[
[
[
1.0
1
]
]
]
]
},
"TwoConvTestModel/NNCFNetworkInterface[_nncf]/ModuleDict[external_quantizers]/SymmetricQuantizer[/nncf_model_input_0|OUTPUT]": {
"input_low": 0.0,
"input_high": 0.9800970554351807
"input_low": [
0
],
"input_high": [
0.9800970554351807
]
},
"TwoConvTestModel/NNCFNetworkInterface[_nncf]/ModuleDict[external_quantizers]/SymmetricQuantizer[TwoConvTestModel/Sequential[features]/Sequential[0]/NNCFConv2d[0]/conv2d_0|OUTPUT]": {
"input_low": -3.8243322372436523,
"input_high": 3.794454574584961
"input_low": [
-3.8243322372436523
],
"input_high": [
3.794454574584961
]
}
}
}
13 changes: 0 additions & 13 deletions tests/torch/ptq/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from nncf.torch.graph.operator_metatypes import PTModuleLinearMetatype
from nncf.torch.graph.operator_metatypes import PTSumMetatype
from nncf.torch.model_creation import create_nncf_network
from nncf.torch.tensor_statistics.statistics import PTMinMaxTensorStatistic
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
Expand Down Expand Up @@ -85,15 +84,3 @@ def get_nncf_network(model: torch.nn.Module, input_shape: Optional[List[int]] =
config=nncf_config,
)
return nncf_network


def mock_collect_statistics(mocker):
_ = mocker.patch(
"nncf.common.tensor_statistics.aggregator.StatisticsAggregator.collect_statistics", return_value=None
)
min_, max_ = 0.0, 1.0
min_, max_ = torch.tensor(min_), torch.tensor(max_)
_ = mocker.patch(
"nncf.experimental.common.tensor_statistics.collectors.TensorCollector.get_statistics",
return_value=PTMinMaxTensorStatistic(min_values=min_, max_values=max_),
)
11 changes: 8 additions & 3 deletions tests/torch/ptq/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pathlib import Path

import pytest
import torch

from nncf.parameters import TargetDevice
from nncf.quantization.advanced_parameters import AdvancedQuantizationParameters
Expand All @@ -23,7 +24,6 @@
from tests.post_training.test_templates.helpers import get_static_dataset
from tests.torch import test_models
from tests.torch.ptq.helpers import get_nncf_network
from tests.torch.ptq.helpers import mock_collect_statistics
from tests.torch.quantization.test_algo_quantization import SharedLayersModel
from tests.torch.test_compressed_graph import ModelDesc
from tests.torch.test_compressed_graph import check_graph
Expand Down Expand Up @@ -94,15 +94,20 @@ def get_model_name(description):
("desc", "quantization_parameters"), TEST_MODELS_DESC, ids=[get_model_name(m) for m in TEST_MODELS_DESC]
)
def test_min_max_classification_quantized_graphs(desc: ModelDesc, quantization_parameters, graph_dir, mocker):
mock_collect_statistics(mocker)
model = desc.model_builder()

nncf_network = get_nncf_network(model, desc.input_sample_sizes)
quantization_parameters["advanced_parameters"] = AdvancedQuantizationParameters(disable_bias_correction=True)
quantization_parameters["subset_size"] = 1
quantization_algorithm = PostTrainingQuantization(**quantization_parameters)

def transform_fn(input_) -> torch.Tensor:
return torch.tensor(input_[0])

quantized_model = quantization_algorithm.apply(
nncf_network, nncf_network.nncf.get_graph(), dataset=get_static_dataset(desc.input_sample_sizes, None, None)
nncf_network,
nncf_network.nncf.get_graph(),
dataset=get_static_dataset(desc.input_sample_sizes, transform_fn, None),
)

check_graph(quantized_model.nncf.get_graph(), desc.dot_filename(), graph_dir)

0 comments on commit 8ec693f

Please sign in to comment.