Skip to content

Commit

Permalink
Fix pytest collection warnings (openvinotoolkit#1097)
Browse files Browse the repository at this point in the history
  • Loading branch information
vshampor authored Feb 8, 2022
1 parent 9cc50b2 commit b07ca14
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 158 deletions.
4 changes: 2 additions & 2 deletions tests/torch/pruning/filter_pruning/test_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from tests.torch.pruning.helpers import get_basic_pruning_config
from tests.torch.pruning.helpers import PruningTestModel
from tests.torch.pruning.helpers import BigPruningTestModel
from tests.torch.pruning.helpers import TestModelMultipleForward
from tests.torch.pruning.helpers import MultipleForwardModel
from tests.torch.pruning.helpers import PruningTestModelConcatBN
from tests.torch.pruning.helpers import DisconectedGraphModel

Expand Down Expand Up @@ -415,7 +415,7 @@ def test_clusters_for_multiple_forward(repeat_seq_of_shared_convs,
config['compression']['params']['all_weights'] = False
config['compression']['params']['prune_first_conv'] = True
config['compression']['pruning_init'] = 0.5
model = TestModelMultipleForward(repeat_seq_of_shared_convs, additional_last_shared_layers)
model = MultipleForwardModel(repeat_seq_of_shared_convs, additional_last_shared_layers)
_, pruning_algo = create_compressed_model_and_algo_for_test(model, config)

clusters = pruning_algo.pruned_module_groups_info.clusters
Expand Down
4 changes: 2 additions & 2 deletions tests/torch/pruning/filter_pruning/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from tests.torch.helpers import fill_conv_weight, fill_bias


class TestFilterPruningBlockModel(nn.Module):
class FilterPruningBlockModel(nn.Module):
def __init__(self, layer):
super().__init__()
self.layer = layer
Expand Down Expand Up @@ -55,7 +55,7 @@ def test_can_infer_magnitude_pruned_conv(weights_val, bias_val):
nncf_module = NNCFConv2d(1, 1, 2)
pytorch_module = nn.Conv2d(1, 1, 2)

sparse_model = TestFilterPruningBlockModel(nncf_module)
sparse_model = FilterPruningBlockModel(nncf_module)

fill_conv_weight(nncf_module, weights_val)
fill_bias(nncf_module, bias_val)
Expand Down
16 changes: 8 additions & 8 deletions tests/torch/pruning/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def forward(self, x):
return x


class TestModelDiffConvs(nn.Module):
class DiffConvsModel(nn.Module):
def __init__(self):
super().__init__()
# Usual conv
Expand All @@ -67,7 +67,7 @@ def forward(self, x):
return x


class TestModelBranching(nn.Module):
class BranchingModel(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = create_conv(1, 3, 2, 1, -2)
Expand All @@ -84,7 +84,7 @@ def forward(self, x):
return x


class TestModelResidualConnection(nn.Module):
class ResidualConnectionModel(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = create_conv(1, 8, 3, 1, -2, padding=1)
Expand All @@ -105,7 +105,7 @@ def forward(self, x):
return x


class TestModelEltwiseCombination(nn.Module):
class EltwiseCombinationModel(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = create_conv(1, 8, 3, 1, -2, padding=1)
Expand Down Expand Up @@ -290,7 +290,7 @@ def forward(self, x):
return x


class TestModelShuffleNetUnit(nn.Module):
class ShuffleNetUnitModel(nn.Module):
def __init__(self):
super().__init__()
self.conv = create_conv(1, 16, 1, 1, -2)
Expand All @@ -302,7 +302,7 @@ def forward(self, x):
return x


class TestModelShuffleNetUnitDW(nn.Module):
class ShuffleNetUnitModelDW(nn.Module):
def __init__(self):
super().__init__()
self.conv = create_conv(1, 16, 1, 1, -2)
Expand All @@ -314,7 +314,7 @@ def forward(self, x):
return x


class TestModelMultipleForward(nn.Module):
class MultipleForwardModel(nn.Module):
def __init__(self, repeat_seq_of_shared_convs=False, additional_last_shared_layers=False):
super().__init__()
self.num_iter_shared_convs = 2 if repeat_seq_of_shared_convs else 1
Expand Down Expand Up @@ -351,7 +351,7 @@ def forward(self, x):
return x1, x2, x3


class TestModelGroupNorm(nn.Module):
class GroupNormModel(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = create_conv(1, 16, 1, 1, -2)
Expand Down
164 changes: 82 additions & 82 deletions tests/torch/pruning/test_model_pruning_analysis.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions tests/torch/pruning/test_onnx_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import pytest

from tests.torch.pruning.helpers import BigPruningTestModel, get_basic_pruning_config, \
PruningTestModelConcat, PruningTestModelEltwise, TestModelDiffConvs, TestModelGroupNorm
PruningTestModelConcat, PruningTestModelEltwise, DiffConvsModel, GroupNormModel
from tests.torch.helpers import load_exported_onnx_version

pytestmark = pytest.mark.skip(reason="Export as actually deleting filters from the model is currently disabled.")
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_pruning_export_eltwise_model(tmp_path, prune_first, ref_shapes):
(True, [[[16, 1, 2, 2], [16]], [[16, 1, 1, 1], [16]], [[32, 16, 3, 3], [32]],
[[16, 4, 1, 1], [16]]])])
def test_pruning_export_diffconvs_model(tmp_path, prune_first, ref_shapes):
model = TestModelDiffConvs()
model = DiffConvsModel()
nncf_config = get_basic_pruning_config(input_sample_size=[1, 1, 8, 8])
nncf_config['compression']['algorithm'] = 'filter_pruning'

Expand All @@ -113,7 +113,7 @@ def test_pruning_export_diffconvs_model(tmp_path, prune_first, ref_shapes):


def test_pruning_export_groupnorm_model(tmp_path):
model = TestModelGroupNorm()
model = GroupNormModel()
nncf_config = get_basic_pruning_config(input_sample_size=[1, 1, 8, 8])
nncf_config['compression']['algorithm'] = 'filter_pruning'

Expand Down
6 changes: 3 additions & 3 deletions tests/torch/pruning/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from nncf.common.pruning.utils import get_last_nodes_of_type
from nncf.torch.pruning.utils import get_bn_for_conv_node_by_name
from tests.torch.pruning.helpers import get_basic_pruning_config, BigPruningTestModel, \
TestModelBranching
BranchingModel
from tests.torch.helpers import create_compressed_model_and_algo_for_test


Expand Down Expand Up @@ -65,7 +65,7 @@ def test_get_bn_for_conv_node():

@pytest.mark.parametrize(('model', 'ref_first_module_names'),
[(BigPruningTestModel, ['conv1']),
(TestModelBranching, ['conv1', 'conv2', 'conv3']),
(BranchingModel, ['conv1', 'conv2', 'conv3']),
],
)
def test_get_first_pruned_layers(model, ref_first_module_names):
Expand All @@ -83,7 +83,7 @@ def test_get_first_pruned_layers(model, ref_first_module_names):

@pytest.mark.parametrize(('model', 'ref_last_module_names'),
[(BigPruningTestModel, ['conv3']),
(TestModelBranching, ['conv4', 'conv5']
(BranchingModel, ['conv4', 'conv5']
),
],
)
Expand Down
6 changes: 6 additions & 0 deletions tests/torch/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[pytest]
markers =
oveval
eval
convert
train
4 changes: 2 additions & 2 deletions tests/torch/quantization/test_manual_precision_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_manual_single_conv(params):
check_bitwidth_graph(ctrl, model, path_to_dot, graph_dir)


class TestPrecisionInitDesc:
class PrecisionInitTestDesc:
def __init__(self):
self.model_creator = AddTwoConv
config = get_quantization_config_without_range_init()
Expand Down Expand Up @@ -251,7 +251,7 @@ def check_precision_init(self, compression_ctrl: QuantizationController):


def test_quantization_configs__with_precisions_list():
desc = TestPrecisionInitDesc()
desc = PrecisionInitTestDesc()
model = desc.model_creator()
config = desc.config
register_bn_adaptation_init_args(config)
Expand Down
18 changes: 9 additions & 9 deletions tests/torch/quantization/test_quantization_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ def as_dict(obj):
return obj


TestStruct = namedtuple(
'TestStruct', ('initializers', 'activations', 'weights', 'ignored_scopes', 'target_device', 'expected'))
CaseStruct = namedtuple(
'CaseStruct', ('initializers', 'activations', 'weights', 'ignored_scopes', 'target_device', 'expected'))


QUANTIZATION_SHARE_AND_BITWIDTH_DISTR_STATS_TEST_CASES = [
TestStruct(
CaseStruct(
initializers={},
activations={},
weights={},
Expand Down Expand Up @@ -95,7 +95,7 @@ def as_dict(obj):
}
}
),
TestStruct(
CaseStruct(
initializers={},
activations={},
weights={},
Expand Down Expand Up @@ -152,7 +152,7 @@ def test_quantization_share_and_bitwidth_distribution_stats(data):


MEMORY_CONSUMPTION_STATS_TEST_CASES = [
TestStruct(
CaseStruct(
initializers={},
activations={},
weights={},
Expand All @@ -166,7 +166,7 @@ def test_quantization_share_and_bitwidth_distribution_stats(data):
'weight_memory_consumption_decrease': 4.0
}
),
TestStruct(
CaseStruct(
initializers={
'precision': {
'bitwidth_per_scope': [
Expand All @@ -189,7 +189,7 @@ def test_quantization_share_and_bitwidth_distribution_stats(data):
'weight_memory_consumption_decrease': 4.05
}
),
TestStruct(
CaseStruct(
initializers={},
activations={},
weights={},
Expand Down Expand Up @@ -227,7 +227,7 @@ def test_memory_consumption_stats(data):


QUANTIZATION_CONFIGURATION_STATS_TEST_CASES = [
TestStruct(
CaseStruct(
initializers={},
activations={},
weights={},
Expand All @@ -238,7 +238,7 @@ def test_memory_consumption_stats(data):
'total_edges_in_cfg': 177
}
),
TestStruct(
CaseStruct(
initializers={},
activations={},
weights={},
Expand Down
6 changes: 3 additions & 3 deletions tests/torch/sparsity/magnitude/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from tests.torch.helpers import fill_conv_weight, fill_linear_weight, fill_bias


class TestModel(nn.Module):
class SingleLayerModel(nn.Module):
def __init__(self, layer):
super().__init__()
self.layer = layer
Expand Down Expand Up @@ -53,7 +53,7 @@ def forward(self, x):
)
def test_can_infer_magnitude_sparse_conv(weight_importance, threshold, ref_output):
nncf_module = NNCFConv2d(1, 1, 2)
sparse_model = TestModel(nncf_module)
sparse_model = SingleLayerModel(nncf_module)
sparsifier = sparse_model.sparsifier
fill_conv_weight(nncf_module, 9)
fill_bias(nncf_module, 0)
Expand Down Expand Up @@ -83,7 +83,7 @@ def test_can_infer_magnitude_sparse_conv(weight_importance, threshold, ref_outpu
)
def test_can_infer_magnitude_sparse_linear(weight_importance, threshold, ref_output):
nncf_module = NNCFLinear(4, 1)
sparse_model = TestModel(nncf_module)
sparse_model = SingleLayerModel(nncf_module)
sparsifier = sparse_model.sparsifier
fill_linear_weight(nncf_module, 9)
fill_bias(nncf_module, 0)
Expand Down
4 changes: 2 additions & 2 deletions tests/torch/sparsity/rb/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from nncf.torch.sparsity.rb.loss import SparseLoss


class TestModel(nn.Module):
class SingleLayerModel(nn.Module):
def __init__(self, layer, frozen, size=1):
super().__init__()
self.size = size
Expand All @@ -42,7 +42,7 @@ def forward(self, x):

def sparse_model(module, frozen, size=1):
layer = module(size, size, size)
return TestModel(layer, frozen, size)
return SingleLayerModel(layer, frozen, size)


@pytest.mark.parametrize('module',
Expand Down
8 changes: 4 additions & 4 deletions tests/torch/sparsity/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,14 @@ def test_adaptive_scheduler_per_epoch_step(self, rb_algo_mock, ref_sparsity_leve
}


class TestLoss:
class MockLoss:
def __init__(self):
self.current_sparsity = 0.5


class TestCompressionController:
class MockCompressionController:
def __init__(self):
self.loss = TestLoss()
self.loss = MockLoss()

def set_sparsity_level(self, level):
pass
Expand All @@ -334,7 +334,7 @@ def set_sparsity_level(self, level):
MultiStepSparsityScheduler, AdaptiveSparsityScheduler],
ids=['Polynomial', 'Exponential', 'Multistep', 'Adaptive'])
def test_scheduler_get_state(scheduler_cls):
args = (TestCompressionController(), {'sparsity_init': 0.3, 'update_per_optimizer_step': True, 'patience': 2})
args = (MockCompressionController(), {'sparsity_init': 0.3, 'update_per_optimizer_step': True, 'patience': 2})
scheduler = scheduler_cls(*args)

# Test init state
Expand Down
Loading

0 comments on commit b07ca14

Please sign in to comment.