Skip to content

Commit

Permalink
Revert "Added BF16 & FP16 models to PTQ tests" (#3124)
Browse files Browse the repository at this point in the history
Reverts #2922

### Related tickets

158536
  • Loading branch information
KodiaqQ authored Dec 2, 2024
1 parent 03c0540 commit 0799634
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 51 deletions.
8 changes: 0 additions & 8 deletions tests/post_training/data/ptq_reference_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 0 additions & 26 deletions tests/post_training/model_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import copy
from typing import Dict, List

import torch

import nncf
from nncf import ModelType
from nncf import QuantizationPreset
Expand Down Expand Up @@ -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",
Expand Down
25 changes: 8 additions & 17 deletions tests/post_training/pipelines/masked_language_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 0799634

Please sign in to comment.