forked from openvinotoolkit/nncf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0de0502
commit adf0070
Showing
2 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright (c) 2023 Intel Corporation | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import numpy as np | ||
import pytest | ||
import torch | ||
|
||
from nncf.torch.tensor import PTNNCFTensor | ||
from nncf.torch.tensor_statistics.collectors import PTAbsMaxReducer | ||
from nncf.torch.tensor_statistics.collectors import PTAbsQuantileReducer | ||
from nncf.torch.tensor_statistics.collectors import PTBatchMeanReducer | ||
from nncf.torch.tensor_statistics.collectors import PTMaxReducer | ||
from nncf.torch.tensor_statistics.collectors import PTMeanPerChanelReducer | ||
from nncf.torch.tensor_statistics.collectors import PTMeanReducer | ||
from nncf.torch.tensor_statistics.collectors import PTMinReducer | ||
from nncf.torch.tensor_statistics.collectors import PTNNCFCollectorTensorProcessor | ||
from nncf.torch.tensor_statistics.collectors import PTNoopReducer | ||
from nncf.torch.tensor_statistics.collectors import PTQuantileReducer | ||
from tests.experimental.common.test_reducers_and_aggregators import TemplateTestReducersAggreagtors | ||
|
||
|
||
class TestReducersAggregators(TemplateTestReducersAggreagtors): | ||
@pytest.fixture | ||
def tensor_processor(self): | ||
return PTNNCFCollectorTensorProcessor | ||
|
||
def get_nncf_tensor(self, x: torch.Tensor): | ||
return PTNNCFTensor(x) | ||
|
||
@pytest.fixture(scope="module") | ||
def reducers(self): | ||
return { | ||
"noop": PTNoopReducer, | ||
"min": PTMinReducer, | ||
"max": PTMaxReducer, | ||
"abs_max": PTAbsMaxReducer, | ||
"mean": PTMeanReducer, | ||
"quantile": PTQuantileReducer, | ||
"abs_quantile": PTAbsQuantileReducer, | ||
"batch_mean": PTBatchMeanReducer, | ||
"mean_per_ch": PTMeanPerChanelReducer, | ||
} | ||
|
||
def all_close(self, val, ref) -> bool: | ||
val_ = torch.tensor(val) | ||
ref_ = torch.tensor(ref) | ||
return torch.allclose(val_, ref_) and val_.shape == ref_.shape |