From 07996341cc083c4c31ae512887c9d22c9084bbfe Mon Sep 17 00:00:00 2001 From: Nikita Malinin Date: Mon, 2 Dec 2024 15:28:26 +0100 Subject: [PATCH] Revert "Added BF16 & FP16 models to PTQ tests" (#3124) Reverts openvinotoolkit/nncf#2922 ### Related tickets 158536 --- .../data/ptq_reference_data.yaml | 8 ------ tests/post_training/model_scope.py | 26 ------------------- .../pipelines/masked_language_modeling.py | 25 ++++++------------ 3 files changed, 8 insertions(+), 51 deletions(-) diff --git a/tests/post_training/data/ptq_reference_data.yaml b/tests/post_training/data/ptq_reference_data.yaml index 175f8c383d2..94f70f3a931 100644 --- a/tests/post_training/data/ptq_reference_data.yaml +++ b/tests/post_training/data/ptq_reference_data.yaml @@ -26,14 +26,6 @@ hf/hf-internal-testing/tiny-random-gpt2_backend_OV: metric_value: null hf/hf-internal-testing/tiny-random-gpt2_backend_TORCH: metric_value: null -hf/bert-base-uncased_fp16_backend_FP32: - metric_value: null -hf/bert-base-uncased_fp16_backend_OV: - metric_value: null -hf/bert-base-uncased_bf16_backend_FP32: - metric_value: null -hf/bert-base-uncased_bf16_backend_OV: - metric_value: null torchvision/resnet18_backend_FP32: metric_value: 0.6978 torchvision/resnet18_backend_OV: diff --git a/tests/post_training/model_scope.py b/tests/post_training/model_scope.py index 8a3691458ee..54b49d63a21 100644 --- a/tests/post_training/model_scope.py +++ b/tests/post_training/model_scope.py @@ -12,8 +12,6 @@ import copy from typing import Dict, List -import torch - import nncf from nncf import ModelType from nncf import QuantizationPreset @@ -83,30 +81,6 @@ }, "backends": [BackendType.TORCH, BackendType.OV, BackendType.OPTIMUM], }, - { - "reported_name": "hf/bert-base-uncased_fp16", - "model_id": "bert-base-uncased", - "pipeline_cls": MaskedLanguageModelingHF, - "compression_params": { - "preset": QuantizationPreset.MIXED, - "model_type": ModelType.TRANSFORMER, - "subset_size": 2, - }, - "backends": [BackendType.OV], - "params": {"base_precision": torch.float16}, - }, - { - "reported_name": "hf/bert-base-uncased_bf16", - "model_id": "bert-base-uncased", - "pipeline_cls": MaskedLanguageModelingHF, - "compression_params": { - "preset": QuantizationPreset.MIXED, - "model_type": ModelType.TRANSFORMER, - "subset_size": 2, - }, - "backends": [BackendType.OV], - "params": {"base_precision": torch.bfloat16}, - }, # Torchvision models { "reported_name": "torchvision/resnet18", diff --git a/tests/post_training/pipelines/masked_language_modeling.py b/tests/post_training/pipelines/masked_language_modeling.py index b53d0601f76..9f750808506 100644 --- a/tests/post_training/pipelines/masked_language_modeling.py +++ b/tests/post_training/pipelines/masked_language_modeling.py @@ -29,26 +29,14 @@ class MaskedLanguageModelingHF(PTQTestPipeline): """Pipeline for masked language models from Hugging Face repository""" def prepare_model(self) -> None: - torch_dtype = self.params.get("base_precision", torch.float32) if self.backend in PT_BACKENDS: - self.model_hf = transformers.AutoModelForSequenceClassification.from_pretrained( - self.model_id, torch_dtype=torch_dtype - ) + self.model_hf = transformers.AutoModelForSequenceClassification.from_pretrained(self.model_id) self.model = self.model_hf self.model.config.torchscript = True # Set to export by convert_model via torch.jit.trace self.dummy_tensor = self.model_hf.dummy_inputs["input_ids"] if self.backend in OV_BACKENDS + [BackendType.FP32]: - if torch_dtype != torch.float32: - # Since optimum-intel does not produce custom-type models, this workaround handles it. - self.model_hf = transformers.AutoModelForSequenceClassification.from_pretrained( - self.model_id, torch_dtype=torch_dtype - ) - self.model = ov.convert_model(self.model_hf, example_input=self.model_hf.dummy_inputs) - else: - self.model_hf = OVModelForSequenceClassification.from_pretrained( - self.model_id, export=True, compile=False - ) - self.model = self.model_hf.model + self.model_hf = OVModelForSequenceClassification.from_pretrained(self.model_id, export=True, compile=False) + self.model = self.model_hf.model if self.backend == BackendType.ONNX: self.model_hf = ORTModelForSequenceClassification.from_pretrained(self.model_id, export=True) @@ -87,10 +75,13 @@ def transform_func(data): return torch.tensor([data["input_ids"]]).type(dtype=torch.LongTensor).to(device) else: - input_names = [p.get_friendly_name() for p in self.model.get_parameters()] def transform_func(data): - return {n: np.expand_dims(data[n], axis=0) for n in input_names} + return { + "input_ids": np.expand_dims(data["input_ids"], axis=0), + "token_type_ids": np.expand_dims(data["token_type_ids"], axis=0), + "attention_mask": np.expand_dims(data["attention_mask"], axis=0), + } return transform_func