From 36f45a256d707abda855e2b1ac27cf80f677aad2 Mon Sep 17 00:00:00 2001 From: Lyalyushkin Nikolay Date: Tue, 26 Sep 2023 13:12:01 +0200 Subject: [PATCH 1/5] More correct hessian trace calculation (#2159) ### Changes Use absolute value of avg_total_trace in denominator, as done in [PyHessian:](https://github.com/amirgholami/PyHessian/blob/master/pyhessian/hessian.py#L186C22-L186C22) ### Reason for changes more robust mixed precision algo ### Related tickets resolves #2155 ### Tests hawq-related tests --- nncf/torch/quantization/hessian_trace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nncf/torch/quantization/hessian_trace.py b/nncf/torch/quantization/hessian_trace.py index 20e0ce1cc52..43c5c67982a 100644 --- a/nncf/torch/quantization/hessian_trace.py +++ b/nncf/torch/quantization/hessian_trace.py @@ -141,7 +141,7 @@ def get_average_traces(self, max_iter=500, tolerance=1e-5) -> Tensor: mean_avg_traces_per_param = self._get_mean(avg_traces_per_iter) mean_avg_total_trace = torch.sum(mean_avg_traces_per_param) - diff_avg = abs(mean_avg_total_trace - avg_total_trace) / (avg_total_trace + self._diff_eps) + diff_avg = abs(mean_avg_total_trace - avg_total_trace) / (abs(avg_total_trace) + self._diff_eps) if diff_avg < tolerance: return mean_avg_traces_per_param avg_total_trace = mean_avg_total_trace From 3b4ba6a8140cf08457df6ed8adc4b1305dee6028 Mon Sep 17 00:00:00 2001 From: Nikita Malinin Date: Tue, 26 Sep 2023 17:41:07 +0200 Subject: [PATCH 2/5] Update Python version (#2158) ### Changes - Updated base Python version ### Reason for changes - Drop Python 3.7 support ### Related tickets - 118798 --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 4cbc92c564c..4807a483c15 100644 --- a/setup.py +++ b/setup.py @@ -57,8 +57,8 @@ ) python_version = sys.version_info -if python_version < (3, 7, 0): - print("Only Python >= 3.7.0 is supported") +if python_version < (3, 8, 0): + print("Only Python >= 3.8.0 is supported") sys.exit(0) version_string = "{}{}".format(sys.version_info[0], sys.version_info[1]) From b6018f2cc85cc1ac0dd01db121bfa50aaa290b02 Mon Sep 17 00:00:00 2001 From: Nikita Malinin Date: Wed, 27 Sep 2023 13:16:33 +0200 Subject: [PATCH 3/5] Fix docs deps version (#2164) ### Changes - Fixed the `astroid` version (`shpinx-autoapi` dependence) ### Reason for changes - The 3.0.0 version breaks our pipeline --- docs/api/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api/requirements.txt b/docs/api/requirements.txt index ce18644fc8f..094025508f1 100644 --- a/docs/api/requirements.txt +++ b/docs/api/requirements.txt @@ -1,3 +1,4 @@ +astroid==2.15.8 Sphinx==6.1.3 sphinx-autoapi==2.1.0 furo==2023.3.27 \ No newline at end of file From 304bd1dddde9e224fccad2af1acfbcdb28c42428 Mon Sep 17 00:00:00 2001 From: Vasily Shamporov Date: Wed, 27 Sep 2023 13:20:39 +0200 Subject: [PATCH 4/5] Remove legacy external quantizer storage names (#2163) ### Changes Legacy quantizer storage names in checkpoints were removed ### Reason for changes The format had changed after the NNCFNetwork rework, and the deprecation warning has been in place for two releases now. ### Related tickets 121535 ### Tests test_load_model_state --- nncf/torch/checkpoint_loading.py | 43 +---- nncf/torch/nncf_network.py | 5 +- tests/torch/test_backward_compat.py | 107 ++++-------- tests/torch/test_load_model_state.py | 233 ++++++++++----------------- 4 files changed, 130 insertions(+), 258 deletions(-) diff --git a/nncf/torch/checkpoint_loading.py b/nncf/torch/checkpoint_loading.py index ad7cde66599..58c3c1567a4 100644 --- a/nncf/torch/checkpoint_loading.py +++ b/nncf/torch/checkpoint_loading.py @@ -154,7 +154,6 @@ class NormalizedKeys: def __init__(self, keys: List[str], keys_to_ignore: List[str]): self._unique_normalized_key_vs_orig_key_map = {} self.is_unified_group_detected = False - self.has_legacy_storage_keys = False unique_clipped_key_vs_orig_key_map, ignored_keys = self._clip_keys_without_collisions(keys, keys_to_ignore) self.ignored_orig_keys = ignored_keys ignored_keys = self._normalize_keys_without_collisions(unique_clipped_key_vs_orig_key_map, keys_to_ignore) @@ -228,9 +227,8 @@ def _clip_keys_without_collisions(keys: List[str], keys_to_ignore: List[str]) -> @staticmethod def _key_clipper(key: str) -> str: new_key = key - from nncf.torch.nncf_network import LEGACY_MODEL_WRAPPED_BY_NNCF_ATTR_NAME # pylint: disable=cyclic-import - clip_patterns = [LEGACY_MODEL_WRAPPED_BY_NNCF_ATTR_NAME + ".", "module.", "|OUTPUT", "|INPUT", "_nncf."] + clip_patterns = ["module.", "|OUTPUT", "|INPUT"] for pattern in clip_patterns: new_key = new_key.replace(pattern, "") return new_key @@ -240,11 +238,6 @@ def _key_replacer(self, key: str) -> List[str]: match = re.search("(pre_ops|post_ops)\\.(\\d+?)\\.op", key) new_key = new_key if not match else new_key.replace(match.group(), "operation") - - new_key, did_replace = self._replace_legacy_act_quantizer_storage_name(new_key) - if did_replace: - self.has_legacy_storage_keys = True - result = self._split_unified_parameters(new_key) if len(result) > 1: self.is_unified_group_detected = True @@ -263,30 +256,17 @@ def _split_unified_parameters(new_key: str) -> List[str]: Returns original key if there's no ';' and operation doesn't start with EXTERNAL_QUANTIZERS_STORAGE_NAME """ result = [new_key] - from nncf.torch.nncf_network import CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX # pylint: disable=cyclic-import + from nncf.torch.nncf_network import EXTERNAL_QUANTIZERS_STORAGE_PREFIX # pylint: disable=cyclic-import - if ";" in new_key and new_key.startswith(CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX): + if ";" in new_key and new_key.startswith(EXTERNAL_QUANTIZERS_STORAGE_PREFIX): group_of_keys = new_key.split(";") last_key = group_of_keys[-1] common_op = last_key.split(".")[-1] - result = [group_of_keys[0] + "." + common_op, CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + "." + last_key] + result = [group_of_keys[0] + "." + common_op, EXTERNAL_QUANTIZERS_STORAGE_PREFIX + "." + last_key] for key in group_of_keys[1:-1]: - result.append(CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + "." + key + "." + common_op) + result.append(EXTERNAL_QUANTIZERS_STORAGE_PREFIX + "." + key + "." + common_op) return result - @staticmethod - def _replace_legacy_act_quantizer_storage_name(checkpoint_key: str) -> Tuple[str, bool]: - did_replace = False - splits = checkpoint_key.split(".") - from nncf.torch.nncf_network import CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX # pylint: disable=cyclic-import - from nncf.torch.nncf_network import LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX # pylint: disable=cyclic-import - - if splits[0] == LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX: - did_replace = True - splits[0] = CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX - reconstructed_key = ".".join(splits) - return reconstructed_key, did_replace - class KeyMatcher: """ @@ -341,19 +321,6 @@ def run(self) -> Dict[str, torch.Tensor]: "names. The newly exported checkpoints will be adjusted to the new format." ) - if normalized_keys_to_load.has_legacy_storage_keys: - from nncf.torch.nncf_network import CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX - from nncf.torch.nncf_network import LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX - - warning_deprecated( - f"Legacy NNCF-enabled .pth checkpoint has been loaded! " - f"The {LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX} storage key is replaced with " - f"{CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX} in newer versions of NNCF, and support " - f"for the legacy storage key will be dropped in a future release. " - f"This checkpoint will be loaded; update your checkpoint file by saving this model's" - f"checkpoint file again." - ) - if normalized_model_keys.is_unified_group_detected and not normalized_keys_to_load.is_unified_group_detected: nncf_logger.warning( "Unified parameters are detected in the compressed model, but all parameters are independent " diff --git a/nncf/torch/nncf_network.py b/nncf/torch/nncf_network.py index 3ce64514848..777d45bea35 100644 --- a/nncf/torch/nncf_network.py +++ b/nncf/torch/nncf_network.py @@ -65,11 +65,8 @@ from nncf.torch.utils import get_model_device from nncf.torch.utils import training_mode_switcher -LEGACY_MODEL_WRAPPED_BY_NNCF_ATTR_NAME = "nncf_module" -LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX = "external_quantizers" - EXTERNAL_QUANTIZERS_STORAGE_NAME = "external_quantizers" -CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX = "_nncf." + EXTERNAL_QUANTIZERS_STORAGE_NAME +EXTERNAL_QUANTIZERS_STORAGE_PREFIX = "_nncf." + EXTERNAL_QUANTIZERS_STORAGE_NAME Module = TypeVar("Module", bound=nn.Module) diff --git a/tests/torch/test_backward_compat.py b/tests/torch/test_backward_compat.py index faebe58f4b4..4b74178fb08 100644 --- a/tests/torch/test_backward_compat.py +++ b/tests/torch/test_backward_compat.py @@ -21,13 +21,11 @@ from examples.torch.common.execution import prepare_model_for_execution from examples.torch.common.model_loader import load_model from nncf.api.compression import CompressionStage -from nncf.common.graph.definitions import MODEL_INPUT_OP_NAME from nncf.common.logging.logger import NNCFDeprecationWarning from nncf.config import NNCFConfig from nncf.torch import register_default_init_args from nncf.torch.checkpoint_loading import load_state -from nncf.torch.nncf_network import LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX -from nncf.torch.nncf_network import LEGACY_MODEL_WRAPPED_BY_NNCF_ATTR_NAME +from nncf.torch.nncf_network import EXTERNAL_QUANTIZERS_STORAGE_PREFIX from nncf.torch.quantization.algo import QUANTIZER_BUILDER_STATE_VERSION_SAVE_NAME from nncf.torch.quantization.algo import QuantizerBuilderStateVersion from tests.shared.helpers import get_cli_dict_args @@ -37,7 +35,6 @@ from tests.torch.helpers import create_compressed_model_and_algo_for_test from tests.torch.helpers import create_ones_mock_dataloader from tests.torch.helpers import register_bn_adaptation_init_args -from tests.torch.quantization.test_range_init import SingleConv2dIdentityModel from tests.torch.test_compressed_graph import get_basic_quantization_config from tests.torch.test_sanity_sample import create_command_line @@ -164,42 +161,6 @@ def test_loaded_model_evals_according_to_saved_acc(_params, tmp_path, dataset_di assert torch.load(checkpoint_path)["best_acc1"] == pytest.approx(metrics["Accuracy"], abs=1e-2) -old_style_sd = { - f"{LEGACY_MODEL_WRAPPED_BY_NNCF_ATTR_NAME}.conv2d.weight": torch.ones([3, 3, 1, 1]), - f"{LEGACY_MODEL_WRAPPED_BY_NNCF_ATTR_NAME}.conv2d.bias": torch.ones([3]), - f"{LEGACY_MODEL_WRAPPED_BY_NNCF_ATTR_NAME}.conv2d.pre_ops.0.op._num_bits": 8 * torch.ones([1], dtype=torch.int32), - f"{LEGACY_MODEL_WRAPPED_BY_NNCF_ATTR_NAME}.conv2d.pre_ops.0.op.signed_tensor": torch.ones([1], dtype=torch.int32), - f"{LEGACY_MODEL_WRAPPED_BY_NNCF_ATTR_NAME}.conv2d.pre_ops.0.op.enabled": torch.ones([1], dtype=torch.int32), - f"{LEGACY_MODEL_WRAPPED_BY_NNCF_ATTR_NAME}.conv2d.pre_ops.0.op.scale": torch.ones([3, 1, 1, 1]), - f"{LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX}./{MODEL_INPUT_OP_NAME}_0|OUTPUT._num_bits": 8 - * torch.ones([1], dtype=torch.int32), - f"{LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX}./{MODEL_INPUT_OP_NAME}_0|OUTPUT.signed_tensor": torch.zeros( - [1], dtype=torch.int32 - ), - f"{LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX}./{MODEL_INPUT_OP_NAME}_0|OUTPUT.enabled": torch.ones( - [1], dtype=torch.int32 - ), - f"{LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX}./{MODEL_INPUT_OP_NAME}_0|OUTPUT.scale": torch.ones([1]), -} - - -def test_renamed_activation_quantizer_storage_in_state_dict(): - model = SingleConv2dIdentityModel() - config = get_basic_quantization_config(input_info={"sample_size": [1, 3, 100, 100]}) - register_bn_adaptation_init_args(config) - compressed_model, _ = create_compressed_model_and_algo_for_test(model, config) - - with pytest.warns(NNCFDeprecationWarning): - _ = load_state(compressed_model, old_style_sd, is_resume=True) - - -def test_can_compress_with_config_and_resume_of_old_checkpoint(): - model = SingleConv2dIdentityModel() - config = get_basic_quantization_config(input_info={"sample_size": [1, 3, 100, 100]}) - register_bn_adaptation_init_args(config) - create_compressed_model_and_algo_for_test(model, config, compression_state=old_style_sd) - - # BN Wrapping backward compatibility test @@ -217,39 +178,41 @@ def forward(self, x): sd_without_nncf_bn_wrapping = { - "nncf_module.conv.weight": torch.ones([9, 3, 3, 3]), - "nncf_module.conv.bias": torch.ones([9]), - "nncf_module.conv.nncf_padding_value": torch.ones([1]), - "nncf_module.conv.pre_ops.0.op._num_bits": torch.ones([1]), - "nncf_module.conv.pre_ops.0.op.signed_tensor": torch.ones([1]), - "nncf_module.conv.pre_ops.0.op.enabled": torch.ones([1]), - "nncf_module.conv.pre_ops.0.op.scale": torch.ones([9, 1, 1, 1]), - "nncf_module.bn.weight": torch.ones([9]), - "nncf_module.bn.bias": torch.ones([9]), - "nncf_module.bn.running_mean": torch.ones([9]), - "nncf_module.bn.running_var": torch.ones([9]), - "nncf_module.bn.num_batches_tracked": torch.ones([]), - "nncf_module.conv1.weight": torch.ones([3, 9, 3, 3]), - "nncf_module.conv1.bias": torch.ones([3]), - "nncf_module.conv1.nncf_padding_value": torch.ones([1]), - "nncf_module.conv1.pre_ops.0.op._num_bits": torch.ones([1]), - "nncf_module.conv1.pre_ops.0.op.signed_tensor": torch.ones([1]), - "nncf_module.conv1.pre_ops.0.op.enabled": torch.ones([1]), - "nncf_module.conv1.pre_ops.0.op.scale": torch.ones([3, 1, 1, 1]), - "nncf_module.bn1.weight": torch.ones([3]), - "nncf_module.bn1.bias": torch.ones([3]), - "nncf_module.bn1.running_mean": torch.ones([3]), - "nncf_module.bn1.running_var": torch.ones([3]), - "nncf_module.bn1.num_batches_tracked": torch.ones([]), - "external_quantizers./nncf_model_input_0|OUTPUT._num_bits": torch.ones([1]), - "external_quantizers./nncf_model_input_0|OUTPUT.signed_tensor": torch.ones([1]), - "external_quantizers./nncf_model_input_0|OUTPUT.enabled": torch.ones([1]), - "external_quantizers./nncf_model_input_0|OUTPUT.scale": torch.ones([1]), + "conv.weight": torch.ones([9, 3, 3, 3]), + "conv.bias": torch.ones([9]), + "conv.nncf_padding_value": torch.ones([1]), + "conv.pre_ops.0.op._num_bits": torch.ones([1]), + "conv.pre_ops.0.op.signed_tensor": torch.ones([1]), + "conv.pre_ops.0.op.enabled": torch.ones([1]), + "conv.pre_ops.0.op.scale": torch.ones([9, 1, 1, 1]), + "bn.weight": torch.ones([9]), + "bn.bias": torch.ones([9]), + "bn.running_mean": torch.ones([9]), + "bn.running_var": torch.ones([9]), + "bn.num_batches_tracked": torch.ones([]), + "conv1.weight": torch.ones([3, 9, 3, 3]), + "conv1.bias": torch.ones([3]), + "conv1.nncf_padding_value": torch.ones([1]), + "conv1.pre_ops.0.op._num_bits": torch.ones([1]), + "conv1.pre_ops.0.op.signed_tensor": torch.ones([1]), + "conv1.pre_ops.0.op.enabled": torch.ones([1]), + "conv1.pre_ops.0.op.scale": torch.ones([3, 1, 1, 1]), + "bn1.weight": torch.ones([3]), + "bn1.bias": torch.ones([3]), + "bn1.running_mean": torch.ones([3]), + "bn1.running_var": torch.ones([3]), + "bn1.num_batches_tracked": torch.ones([]), + f"{EXTERNAL_QUANTIZERS_STORAGE_PREFIX}./nncf_model_input_0|OUTPUT._num_bits": torch.ones([1]), + f"{EXTERNAL_QUANTIZERS_STORAGE_PREFIX}./nncf_model_input_0|OUTPUT.signed_tensor": torch.ones([1]), + f"{EXTERNAL_QUANTIZERS_STORAGE_PREFIX}./nncf_model_input_0|OUTPUT.enabled": torch.ones([1]), + f"{EXTERNAL_QUANTIZERS_STORAGE_PREFIX}./nncf_model_input_0|OUTPUT.scale": torch.ones([1]), # Old bn layer names: ||||||||||| - "external_quantizers.ConvBNLayer/BatchNorm2d[bn]/batch_norm_0|OUTPUT._num_bits": torch.ones([1]), - "external_quantizers.ConvBNLayer/BatchNorm2d[bn]/batch_norm_0|OUTPUT.signed_tensor": torch.ones([1]), - "external_quantizers.ConvBNLayer/BatchNorm2d[bn]/batch_norm_0|OUTPUT.enabled": torch.ones([1]), - "external_quantizers.ConvBNLayer/BatchNorm2d[bn]/batch_norm_0|OUTPUT.scale": torch.ones([1]), + f"{EXTERNAL_QUANTIZERS_STORAGE_PREFIX}.ConvBNLayer/BatchNorm2d[bn]/batch_norm_0|OUTPUT._num_bits": torch.ones([1]), + f"{EXTERNAL_QUANTIZERS_STORAGE_PREFIX}.ConvBNLayer/BatchNorm2d[bn]/batch_norm_0|OUTPUT.signed_tensor": torch.ones( + [1] + ), + f"{EXTERNAL_QUANTIZERS_STORAGE_PREFIX}.ConvBNLayer/BatchNorm2d[bn]/batch_norm_0|OUTPUT.enabled": torch.ones([1]), + f"{EXTERNAL_QUANTIZERS_STORAGE_PREFIX}.ConvBNLayer/BatchNorm2d[bn]/batch_norm_0|OUTPUT.scale": torch.ones([1]), } compression_state_without_bn_wrapping = { diff --git a/tests/torch/test_load_model_state.py b/tests/torch/test_load_model_state.py index d4599ca7f73..cdd0e39a45e 100644 --- a/tests/torch/test_load_model_state.py +++ b/tests/torch/test_load_model_state.py @@ -25,8 +25,7 @@ from nncf.torch.checkpoint_loading import load_state from nncf.torch.layers import NNCF_PADDING_VALUE_ATTR_NAME from nncf.torch.nncf_module_replacement import replace_modules_by_nncf_modules -from nncf.torch.nncf_network import CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX -from nncf.torch.nncf_network import LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX +from nncf.torch.nncf_network import EXTERNAL_QUANTIZERS_STORAGE_PREFIX from tests.torch.helpers import BasicConvTestModel from tests.torch.helpers import PTTensorListComparator @@ -230,14 +229,12 @@ def fn() -> Set["str"]: .missing(['2']).matched(['1']), # wrapping by NNCFNetwork and DataParallel & DistributedDataParallel - MatchKeyDesc(num_loaded=2).keys_to_load(['module.1', 'nncf_module.2']).model_keys(['1', '2']) + MatchKeyDesc(num_loaded=2).keys_to_load(['1', '2']).model_keys(['module.1', 'module.2']) .all_matched(), - MatchKeyDesc(num_loaded=2).keys_to_load(['1', '2']).model_keys(['module.1', 'nncf_module.2']) - .all_matched(), - MatchKeyDesc(num_loaded=2).keys_to_load(['module.nncf_module.1', 'module.2']).model_keys(['1', 'nncf_module.2']) + MatchKeyDesc(num_loaded=2).keys_to_load(['module.1', 'module.2']).model_keys(['1', 'module.2']) .all_matched(), MatchKeyDesc(num_loaded=0, expects_error=True) - .keys_to_load(['module.nncf_module.1.1', 'module.2']).model_keys(['1', '2.2']) + .keys_to_load(['module.1.1', 'module.2']).model_keys(['1', '2.2']) .all_not_matched(), # collisions after normalization of keys @@ -253,8 +250,8 @@ def fn() -> Set["str"]: .model_keys(['pre_ops.0.op.1', 'pre_ops.1.op.1']) .all_matched(), MatchKeyDesc(num_loaded=2) - .keys_to_load(['nncf_module.pre_ops.1.op.1', 'nncf_module.pre_ops.0.op.1']) - .model_keys(['module.nncf_module.pre_ops.1.op.1', 'module.nncf_module.pre_ops.0.op.1']) + .keys_to_load(['module.pre_ops.1.op.1', 'module.pre_ops.0.op.1']) + .model_keys(['module.module.pre_ops.1.op.1', 'module.module.pre_ops.0.op.1']) .all_matched(), # quantization -> quantization + sparsity: op.1 was first, than MatchKeyDesc(num_loaded=2) @@ -286,98 +283,70 @@ def fn() -> Set["str"]: .keys_to_load(['relu_0.' + OP1, 'relu_0.' + OP2]).model_keys(['relu_0|OUTPUT.' + OP1, 'relu_0|INPUT.' + OP2]) .all_matched(), - # can match legacy activation quantizer + new format with |INPUT and |OUTPUT - MatchKeyDesc(num_loaded=2) - .keys_to_load([LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP1, - LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP2]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT.' + OP1, - CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|INPUT.' + OP2]) - .all_matched() - .with_deprecation_warning(), - # can match version agnostic format with the version_specific format MatchKeyDesc(num_loaded=4) .keys_to_load(["conv2d.weight", "RELUModule.weight", - CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, - CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP2]) - .model_keys(["conv2d.weight", - "RELUModule.weight", - CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT.' + OP1, - CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|INPUT.' + OP2]) - .all_matched() - .with_deprecation_warning(), - - # can match version agnostic format with the version_specific format + legacy act quant - MatchKeyDesc(num_loaded=4) - .keys_to_load(["conv2d.weight", - "RELUModule.weight", - LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, - LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP2]) + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP2]) .model_keys(["conv2d.weight", "RELUModule.weight", - CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu__0|OUTPUT.' + OP1, - CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu__0|INPUT.' + OP2]) + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT.' + OP1, + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|INPUT.' + OP2]) .all_matched() .with_deprecation_warning(), # can match unified FQ - MatchKeyDesc(num_loaded=1) - .keys_to_load(['module.' + LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP1, - 'module.' + LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_1.' + OP1]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT;relu_1|OUTPUT.' + OP1]) - .all_matched() - .with_warning(r".*Unified parameters.*"), MatchKeyDesc(num_loaded=1) - .keys_to_load(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_1.' + OP1]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT;relu_1|OUTPUT.' + OP1]) + .keys_to_load(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_1.' + OP1]) + .model_keys([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT;relu_1|OUTPUT.' + OP1]) .all_matched() .with_warning(r".*Unified parameters.*"), MatchKeyDesc(num_loaded=1) - .keys_to_load(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_1.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_2.' + OP1]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT;relu_2|OUTPUT;relu_1|OUTPUT.' + OP1]) + .keys_to_load(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_1.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_2.' + OP1]) + .model_keys([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT;relu_2|OUTPUT;relu_1|OUTPUT.' + OP1]) .all_matched() .with_warning(r".*Unified parameters.*"), # not matched common operation MatchKeyDesc(num_loaded=1, expects_error=True) - .keys_to_load(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_1.' + OP2, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_2.' + OP1_NOT_PARAM]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT;relu_2|OUTPUT;relu_1|OUTPUT.' + OP1]) - .matched([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT;relu_2|OUTPUT;relu_1|OUTPUT.' + OP1]) - .unexpected(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_1.' + OP2, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_2.' + OP1_NOT_PARAM]), + .keys_to_load(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_1.' + OP2, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_2.' + OP1_NOT_PARAM]) + .model_keys([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT;relu_2|OUTPUT;relu_1|OUTPUT.' + OP1]) + .matched([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT;relu_2|OUTPUT;relu_1|OUTPUT.' + OP1]) + .unexpected(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_1.' + OP2, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_2.' + OP1_NOT_PARAM]), # not all unified scopes are matched: relu_3 vs relu_1 MatchKeyDesc(num_loaded=1, expects_error=True) - .keys_to_load(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_3.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_2.' + OP1]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT;relu_2|OUTPUT;relu_1|OUTPUT.' + OP1]) - .matched([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT;relu_2|OUTPUT;relu_1|OUTPUT.' + OP1]) - .unexpected(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_3.' + OP1]), + .keys_to_load(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_3.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_2.' + OP1]) + .model_keys([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT;relu_2|OUTPUT;relu_1|OUTPUT.' + OP1]) + .matched([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0|OUTPUT;relu_2|OUTPUT;relu_1|OUTPUT.' + OP1]) + .unexpected(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_3.' + OP1]), # won't match relu_ and relu MatchKeyDesc(num_loaded=2, expects_error=True) .keys_to_load(["conv2d.weight", "RELUModule.weight", - CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP1, - CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP2]) + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP1, + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP2]) .model_keys(["conv2d.weight", "RELUModule.weight", - CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu__0|OUTPUT.' + OP1, - CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu__0|INPUT.' + OP2]) + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu__0|OUTPUT.' + OP1, + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu__0|INPUT.' + OP2]) .matched(["conv2d.weight", "RELUModule.weight"]) - .unexpected([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP1, - CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP2]) - .missing([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu__0|OUTPUT.' + OP1, - CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu__0|INPUT.' + OP2]), + .unexpected([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP1, + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu_0.' + OP2]) + .missing([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu__0|OUTPUT.' + OP1, + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.relu__0|INPUT.' + OP2]), # can skip ignored parameters MatchKeyDesc(num_loaded=1).keys_to_load(['1']).model_keys(['1', '2']) @@ -390,61 +359,52 @@ def fn() -> Set["str"]: .keys_to_ignore(['1']) .skipped(['1']), MatchKeyDesc(num_loaded=0, expects_error=True) - .keys_to_load(['module.nncf_module.1.1', '2.2']).model_keys(['module.1', 'module.2']) + .keys_to_load(['module.1.1', '2.2']).model_keys(['module.1', 'module.2']) .keys_to_ignore(['1', '2.2']) - .skipped(['module.1', '2.2']).missing(['module.2']).unexpected(['module.nncf_module.1.1']), + .skipped(['module.1', '2.2']).missing(['module.2']).unexpected(['module.1.1']), # optional parameter - not necessary in checkpoint can be initialized by default in the model - # can match legacy activation quantizer + new format with |INPUT and |OUTPUT - MatchKeyDesc(num_loaded=2) - .keys_to_load([LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, - LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP2]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT.' + OP1, - CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|INPUT.' + OP2]) - .all_matched() - .with_deprecation_warning(), - # can match unified FQ MatchKeyDesc(num_loaded=1) - .keys_to_load(['module.' + LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, - 'module.' + LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP1]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_1|OUTPUT.' + OP1]) + .keys_to_load(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP1]) + .model_keys([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_1|OUTPUT.' + OP1]) .all_matched() .with_warning(r".*Unified parameters.*"), MatchKeyDesc(num_loaded=1) - .keys_to_load(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP1]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_1|OUTPUT.' + OP1]) + .keys_to_load(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP1]) + .model_keys([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_1|OUTPUT.' + OP1]) .all_matched() .with_warning(r".*Unified parameters.*"), MatchKeyDesc(num_loaded=1) - .keys_to_load(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) + .keys_to_load(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1]) + .model_keys([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) .all_matched() .with_warning(r".*Unified parameters.*"), # not matched common operation MatchKeyDesc(num_loaded=1, expects_error=True) - .keys_to_load(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP2, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1_NOT_PARAM]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) - .matched([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) - .unexpected(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP2, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1_NOT_PARAM]), + .keys_to_load(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP2, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1_NOT_PARAM]) + .model_keys([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) + .matched([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) + .unexpected(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP2, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1_NOT_PARAM]), # not all unified scopes are matched: RELU_3 vs RELU_1 MatchKeyDesc(num_loaded=1, expects_error=True) - .keys_to_load(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_3.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) - .matched([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) - .unexpected(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_3.' + OP1]), + .keys_to_load(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_3.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1]) + .model_keys([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) + .matched([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) + .unexpected(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_3.' + OP1]), # can skip ignored parameters MatchKeyDesc(num_loaded=1).keys_to_load(['1']).model_keys(['1', '2']) @@ -457,68 +417,53 @@ def fn() -> Set["str"]: .keys_to_ignore(['1']) .skipped(['1']), MatchKeyDesc(num_loaded=0, expects_error=True) - .keys_to_load(['module.nncf_module.1.1', '2.2']).model_keys(['module.1', 'module.2']) + .keys_to_load(['module.1.1', '2.2']).model_keys(['module.1', 'module.2']) .keys_to_ignore(['1', '2.2']) - .skipped(['module.1', '2.2']).missing(['module.2']).unexpected(['module.nncf_module.1.1']), + .skipped(['module.1', '2.2']).missing(['module.2']).unexpected(['module.1.1']), # optional parameter - not necessary in checkpoint can be initialized by default in the model - # can match legacy activation quantizer + new format with |INPUT and |OUTPUT - MatchKeyDesc(num_loaded=2) - .keys_to_load([LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, - LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP2]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT.' + OP1, - CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|INPUT.' + OP2]) - .all_matched() - .with_deprecation_warning(), - # can match unified FQ MatchKeyDesc(num_loaded=1) - .keys_to_load(['module.' + LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, - 'module.' + LEGACY_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP1]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_1|OUTPUT.' + OP1]) + .keys_to_load(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP1]) + .model_keys([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_1|OUTPUT.' + OP1]) .all_matched() .with_warning(r".*Unified parameters.*"), MatchKeyDesc(num_loaded=1) - .keys_to_load(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP1]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_1|OUTPUT.' + OP1]) + .keys_to_load(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP1]) + .model_keys([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_1|OUTPUT.' + OP1]) .all_matched() .with_warning(r".*Unified parameters.*"), MatchKeyDesc(num_loaded=1) - .keys_to_load(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) + .keys_to_load(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1]) + .model_keys([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) .all_matched() .with_warning(r".*Unified parameters.*"), # not matched common operation MatchKeyDesc(num_loaded=1, expects_error=True) - .keys_to_load(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP2, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1_NOT_PARAM]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) - .matched([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) - .unexpected(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP2, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1_NOT_PARAM]), + .keys_to_load(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP2, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1_NOT_PARAM]) + .model_keys([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) + .matched([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) + .unexpected(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_1.' + OP2, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1_NOT_PARAM]), # not all unified scopes are matched: RELU_3 vs RELU_1 MatchKeyDesc(num_loaded=1, expects_error=True) - .keys_to_load(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_3.' + OP1, - 'module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1]) - .model_keys([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) - .matched([CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) - .unexpected(['module.' + CURRENT_EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_3.' + OP1]), - - # can match keys under _nncf in the new style and the keys without _nncf - MatchKeyDesc(num_loaded=1) - .keys_to_load(['key.op']) - .model_keys(['_nncf.key.op']) - .all_matched() - .with_deprecation_warning(), + .keys_to_load(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_3.' + OP1, + 'module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_2.' + OP1]) + .model_keys([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) + .matched([EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_0|OUTPUT;RELU_2|OUTPUT;RELU_1|OUTPUT.' + OP1]) + .unexpected(['module.' + EXTERNAL_QUANTIZERS_STORAGE_PREFIX + '.RELU_3.' + OP1]), + OptionalMatchKeyDesc(num_loaded=0) .keys_to_load([]) From b16d4a1cb7dfe9c2dfad22178a2a0830e68ec742 Mon Sep 17 00:00:00 2001 From: Vasily Shamporov Date: Wed, 27 Sep 2023 13:40:15 +0200 Subject: [PATCH 5/5] Use torch for CUDA 11.8 in tests (#2149) --- Makefile | 6 +++--- tests/torch/test_sanity_sample.py | 12 +++--------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 5bd8cf8f4dd..58d2121d6d3 100644 --- a/Makefile +++ b/Makefile @@ -117,11 +117,11 @@ test-examples-tensorflow: # PyTorch backend install-torch-test: pip install -U pip - pip install -e .[torch] - pip install -r tests/torch/requirements.txt + pip install -e .[torch] --index-url https://download.pytorch.org/whl/cu118 --extra-index-url=https://pypi.org/simple # ticket 119128 + pip install -r tests/torch/requirements.txt --index-url https://download.pytorch.org/whl/cu118 --extra-index-url=https://pypi.org/simple pip install -r tests/cross_fw/install/requirements.txt pip install -r tests/cross_fw/examples/requirements.txt - pip install -r examples/torch/requirements.txt + pip install -r examples/torch/requirements.txt --index-url https://download.pytorch.org/whl/cu118 --extra-index-url=https://pypi.org/simple install-torch-dev: install-torch-test install-pre-commit install-pylint pip install -r examples/post_training_quantization/torch/mobilenet_v2/requirements.txt diff --git a/tests/torch/test_sanity_sample.py b/tests/torch/test_sanity_sample.py index 42da1e08774..9e206c0b127 100644 --- a/tests/torch/test_sanity_sample.py +++ b/tests/torch/test_sanity_sample.py @@ -174,12 +174,6 @@ def set_num_threads_locally(n=1): torch.set_num_threads(old_n) -def _run_with_xfail_119128(runner: Command): - returncode = runner.run(assert_returncode_zero=False) - if returncode == 139: - pytest.xfail("Bug 119128: sporadic segment fault on backward") - - @pytest.mark.nightly class TestSanitySample: @staticmethod @@ -289,7 +283,7 @@ def test_pretrained_model_train(config, tmp_path, multiprocessing_distributed, c ) runner = Command(create_command_line(args, config["sample_type"]), env=ROOT_PYTHONPATH_ENV) - _run_with_xfail_119128(runner) + runner.run(assert_returncode_zero=False) last_checkpoint_path = os.path.join(checkpoint_save_dir, get_run_name(config_factory.config) + "_last.pth") assert os.path.exists(last_checkpoint_path) if "compression" in config["sample_config"]: @@ -374,7 +368,7 @@ def test_resume(request, config, tmp_path, multiprocessing_distributed, case_com args["--multiprocessing-distributed"] = True runner = Command(create_command_line(args, config["sample_type"]), env=ROOT_PYTHONPATH_ENV) - _run_with_xfail_119128(runner) + runner.run(assert_returncode_zero=False) last_checkpoint_path = os.path.join(checkpoint_save_dir, get_run_name(config_factory.config) + "_last.pth") assert os.path.exists(last_checkpoint_path) if "compression" in config["sample_config"]: @@ -590,7 +584,7 @@ def test_accuracy_aware_training_pipeline(accuracy_aware_config, tmp_path, multi args["--multiprocessing-distributed"] = True runner = Command(create_command_line(args, accuracy_aware_config["sample_type"]), env=ROOT_PYTHONPATH_ENV) - _run_with_xfail_119128(runner) + runner.run(assert_returncode_zero=False) checkpoint_save_dir = log_dir / get_run_name(config_factory.config) aa_checkpoint_path = get_accuracy_aware_checkpoint_dir_path(checkpoint_save_dir)