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 25, 2024
1 parent 66c80bd commit 808d068
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
[
[
[
-1.0
-1
]
]
],
[
[
[
-1.0
-1
]
]
]
Expand All @@ -28,14 +28,14 @@
[
[
[
1.0
1
]
]
],
[
[
[
1.0
1
]
]
]
Expand All @@ -46,7 +46,7 @@
[
[
[
-1.0
-1
]
]
]
Expand All @@ -55,10 +55,26 @@
[
[
[
1.0
1
]
]
]
]
},
"TwoConvTestModel/NNCFNetworkInterface[_nncf]/ModuleDict[external_quantizers]/SymmetricQuantizer[/nncf_model_input_0|OUTPUT]": {
"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
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
[
[
[
-2.0
-2
]
]
],
[
[
[
-2.0
-2
]
]
]
Expand All @@ -28,14 +28,14 @@
[
[
[
2.0
2
]
]
],
[
[
[
2.0
2
]
]
]
Expand All @@ -46,7 +46,7 @@
[
[
[
-2.0
-2
]
]
]
Expand All @@ -55,10 +55,26 @@
[
[
[
2.0
2
]
]
]
]
},
"TwoConvTestModel/NNCFNetworkInterface[_nncf]/ModuleDict[external_quantizers]/SymmetricQuantizer[/nncf_model_input_0|OUTPUT]": {
"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
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
[
[
[
-2.0
-2
]
]
],
[
[
[
-2.0
-2
]
]
]
Expand All @@ -28,14 +28,14 @@
[
[
[
2.0
2
]
]
],
[
[
[
2.0
2
]
]
]
Expand All @@ -46,7 +46,7 @@
[
[
[
-1.0
-1
]
]
]
Expand All @@ -55,10 +55,26 @@
[
[
[
1.0
1
]
]
]
]
},
"TwoConvTestModel/NNCFNetworkInterface[_nncf]/ModuleDict[external_quantizers]/SymmetricQuantizer[/nncf_model_input_0|OUTPUT]": {
"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
]
}
}
}
13 changes: 0 additions & 13 deletions tests/torch/ptq/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from nncf.torch.graph.operator_metatypes import PTModuleDepthwiseConv2dSubtype
from nncf.torch.graph.operator_metatypes import PTModuleLinearMetatype
from nncf.torch.graph.operator_metatypes import PTSumMetatype
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 @@ -81,15 +80,3 @@ def get_nncf_network(model: torch.nn.Module, input_shape: Optional[List[int]] =
model = model.eval()
device = next(model.named_parameters())[1].device
return wrap_model(model, torch.ones(input_shape).to(device=device), trace_parameters=True)


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_),
)
10 changes: 7 additions & 3 deletions tests/torch/ptq/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from tests.post_training.test_templates.helpers import EmbeddingModel
from tests.post_training.test_templates.helpers import get_static_dataset
from tests.torch import test_models
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 @@ -95,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 = wrap_model(model, torch.ones(desc.input_sample_sizes), trace_parameters=True)
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 808d068

Please sign in to comment.