Skip to content

Commit

Permalink
Bump transformers version (#724)
Browse files Browse the repository at this point in the history
* Bump transformers version

* fix default ignored scope for model using sdpa by default

* fix quant ops test

* update setup

* add ops quant num gpt2

* fix expected ops quant in test

* update optimum version
  • Loading branch information
echarlaix authored May 29, 2024
1 parent aefabf0 commit ca05db0
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
"ignored_scopes": [
"{re}.*__add___[0-1]",
"{re}.*layer_norm_0",
"{re}.*matmul_1",
"{re}.*__truediv__*"
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
"ignored_scopes": [
"{re}.*__add___[0-1]",
"{re}.*layer_norm_0",
"{re}.*matmul_1",
"{re}.*__truediv__*"
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
"ignored_scopes": [
"{re}.*__add___[0-1]",
"{re}.*layer_norm_0",
"{re}.*matmul_1",
"{re}.*__truediv__*"
]
}
]
2 changes: 0 additions & 2 deletions optimum/intel/openvino/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@
"{re}.*Embedding.*",
"{re}.*add___.*",
"{re}.*layer_norm_.*",
"{re}.*matmul_1",
"{re}.*__truediv__.*",
],
}

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

INSTALL_REQUIRE = [
"torch>=1.11",
"transformers>=4.36.0,<4.41.0",
"optimum~=1.19",
"transformers>=4.36.0,<4.42.0",
"optimum~=1.20",
"datasets>=1.4.0",
"sentencepiece",
"scipy",
Expand Down
2 changes: 1 addition & 1 deletion tests/openvino/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ def test_compare_output_attentions(self, model_arch):
preprocessor = AutoFeatureExtractor.from_pretrained(model_id)
inputs = preprocessor(images=image, return_tensors="pt")

transformers_model = AutoModelForImageClassification.from_pretrained(model_id)
transformers_model = AutoModelForImageClassification.from_pretrained(model_id, attn_implementation="eager")
transformers_model.eval()
with torch.no_grad():
transformers_outputs = transformers_model(**inputs, output_attentions=True)
Expand Down
4 changes: 2 additions & 2 deletions tests/openvino/test_quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

class OVQuantizerTest(unittest.TestCase):
SUPPORTED_ARCHITECTURES_TORCH_MODEL = (
(OVModelForSequenceClassification, "bert", 32, 35),
(OVModelForSequenceClassification, "bert", 22, 35),
(OVModelForCausalLM, "gpt2", 41, 3),
)
SUPPORTED_ARCHITECTURES_OV_MODEL = (
Expand Down Expand Up @@ -665,7 +665,7 @@ def preprocess_function(examples, tokenizer):


class OVTrainerTest(unittest.TestCase):
SUPPORTED_ARCHITECTURES_WITH_EXPECTED_QUANTIZED_MATMULS = (("distilbert-base-uncased", 49, 38),)
SUPPORTED_ARCHITECTURES_WITH_EXPECTED_QUANTIZED_MATMULS = (("distilbert-base-uncased", 67, 38),)

@parameterized.expand(SUPPORTED_ARCHITECTURES_WITH_EXPECTED_QUANTIZED_MATMULS)
def test_aware_training_quantization(self, model_name, expected_fake_quantize, expected_int8):
Expand Down
38 changes: 20 additions & 18 deletions tests/openvino/test_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,30 +322,30 @@ def tearDown(self):
"default_quantization": OVTrainerTestDescriptor(
model_id="hf-internal-testing/tiny-random-bert",
nncf_compression_config=DEFAULT_QUANTIZATION_CONFIG,
expected_fake_quantize=34,
expected_fake_quantize=22,
expected_int8=32,
compression_metrics=["compression_loss"],
),
"distillation,default_quantization": OVTrainerTestDescriptor(
model_id="hf-internal-testing/tiny-random-bert",
teacher_model_id="hf-internal-testing/tiny-random-bert",
nncf_compression_config=DEFAULT_QUANTIZATION_CONFIG,
expected_fake_quantize=34,
expected_fake_quantize=22,
expected_int8=32,
compression_metrics=["compression_loss", "distillation_loss", "task_loss"],
),
"customized_quantization": OVTrainerTestDescriptor(
model_id="hf-internal-testing/tiny-random-bert",
nncf_compression_config=CUSTOMIZED_QUANTIZATION_CONFIG,
expected_fake_quantize=34,
expected_fake_quantize=22,
expected_int8=32,
compression_metrics=["compression_loss"],
),
"distillation,customized_quantization": OVTrainerTestDescriptor(
model_id="hf-internal-testing/tiny-random-bert",
teacher_model_id="hf-internal-testing/tiny-random-bert",
nncf_compression_config=CUSTOMIZED_QUANTIZATION_CONFIG,
expected_fake_quantize=34,
expected_fake_quantize=22,
expected_int8=32,
compression_metrics=["compression_loss", "distillation_loss", "task_loss"],
),
Expand All @@ -365,7 +365,7 @@ def tearDown(self):
"default_quantization,structured_movement_sparsity": OVTrainerTestDescriptor(
model_id="hf-internal-testing/tiny-random-bert",
nncf_compression_config=[DEFAULT_QUANTIZATION_CONFIG, STRUCTURED_MOVEMENT_SPARSITY_CONFIG_FOR_BERT],
expected_fake_quantize=34,
expected_fake_quantize=22,
expected_int8=32,
expected_binary_masks=60,
compression_metrics=["compression_loss"],
Expand All @@ -376,7 +376,7 @@ def tearDown(self):
CUSTOMIZED_QUANTIZATION_CONFIG,
STRUCTURED_MOVEMENT_SPARSITY_CONFIG_FOR_BERT,
],
expected_fake_quantize=34,
expected_fake_quantize=22,
expected_int8=32,
expected_binary_masks=60,
compression_metrics=["compression_loss"],
Expand All @@ -385,7 +385,7 @@ def tearDown(self):
model_id="hf-internal-testing/tiny-random-bert",
teacher_model_id="hf-internal-testing/tiny-random-bert",
nncf_compression_config=[DEFAULT_QUANTIZATION_CONFIG, STRUCTURED_MOVEMENT_SPARSITY_CONFIG_FOR_BERT],
expected_fake_quantize=34,
expected_fake_quantize=22,
expected_int8=32,
expected_binary_masks=60,
compression_metrics=["compression_loss", "distillation_loss", "task_loss"],
Expand All @@ -397,7 +397,7 @@ def tearDown(self):
CUSTOMIZED_QUANTIZATION_CONFIG,
STRUCTURED_MOVEMENT_SPARSITY_CONFIG_FOR_BERT,
],
expected_fake_quantize=34,
expected_fake_quantize=22,
expected_int8=32,
expected_binary_masks=60,
compression_metrics=["compression_loss", "distillation_loss", "task_loss"],
Expand All @@ -418,7 +418,7 @@ def tearDown(self):
"default_quantization,unstructured_movement_sparsity": OVTrainerTestDescriptor(
model_id="hf-internal-testing/tiny-random-bert",
nncf_compression_config=[DEFAULT_QUANTIZATION_CONFIG, UNSTRUCTURED_MOVEMENT_SPARSITY_CONFIG_FOR_BERT],
expected_fake_quantize=34,
expected_fake_quantize=22,
expected_int8=32,
expected_binary_masks=60,
compression_metrics=["compression_loss"],
Expand All @@ -429,7 +429,7 @@ def tearDown(self):
CUSTOMIZED_QUANTIZATION_CONFIG,
UNSTRUCTURED_MOVEMENT_SPARSITY_CONFIG_FOR_BERT,
],
expected_fake_quantize=34,
expected_fake_quantize=22,
expected_int8=32,
expected_binary_masks=60,
compression_metrics=["compression_loss"],
Expand All @@ -438,7 +438,7 @@ def tearDown(self):
model_id="hf-internal-testing/tiny-random-bert",
teacher_model_id="hf-internal-testing/tiny-random-bert",
nncf_compression_config=[DEFAULT_QUANTIZATION_CONFIG, UNSTRUCTURED_MOVEMENT_SPARSITY_CONFIG_FOR_BERT],
expected_fake_quantize=34,
expected_fake_quantize=22,
expected_int8=32,
expected_binary_masks=60,
compression_metrics=["compression_loss", "distillation_loss", "task_loss"],
Expand All @@ -450,7 +450,7 @@ def tearDown(self):
CUSTOMIZED_QUANTIZATION_CONFIG,
UNSTRUCTURED_MOVEMENT_SPARSITY_CONFIG_FOR_BERT,
],
expected_fake_quantize=34,
expected_fake_quantize=22,
expected_int8=32,
expected_binary_masks=60,
compression_metrics=["compression_loss", "distillation_loss", "task_loss"],
Expand Down Expand Up @@ -553,7 +553,7 @@ def check_ovmodel_reshaping(self, ovmodel: OVModel):
"default_quantization": OVTrainerTestDescriptor(
model_id="yujiepan/tiny-random-swin-patch4-window7-224",
nncf_compression_config=DEFAULT_QUANTIZATION_CONFIG,
expected_fake_quantize=28,
expected_fake_quantize=36,
expected_int8=28,
compression_metrics=["compression_loss"],
),
Expand All @@ -572,15 +572,15 @@ def check_ovmodel_reshaping(self, ovmodel: OVModel):
"default_quantization,structured_movement_sparsity": OVTrainerTestDescriptor(
model_id="yujiepan/tiny-random-swin-patch4-window7-224",
nncf_compression_config=[STRUCTURED_MOVEMENT_SPARSITY_CONFIG_FOR_SWIN, DEFAULT_QUANTIZATION_CONFIG],
expected_fake_quantize=28,
expected_fake_quantize=36,
expected_int8=28,
expected_binary_masks=48,
compression_metrics=["compression_loss"],
),
"default_quantization,unstructured_movement_sparsity": OVTrainerTestDescriptor(
model_id="yujiepan/tiny-random-swin-patch4-window7-224",
nncf_compression_config=[UNSTRUCTURED_MOVEMENT_SPARSITY_CONFIG_FOR_SWIN, DEFAULT_QUANTIZATION_CONFIG],
expected_fake_quantize=28,
expected_fake_quantize=36,
expected_int8=28,
expected_binary_masks=48,
compression_metrics=["compression_loss"],
Expand All @@ -589,7 +589,7 @@ def check_ovmodel_reshaping(self, ovmodel: OVModel):
model_id="yujiepan/tiny-random-swin-patch4-window7-224",
teacher_model_id="yujiepan/tiny-random-swin-patch4-window7-224",
nncf_compression_config=[STRUCTURED_MOVEMENT_SPARSITY_CONFIG_FOR_SWIN, DEFAULT_QUANTIZATION_CONFIG],
expected_fake_quantize=28,
expected_fake_quantize=36,
expected_int8=28,
expected_binary_masks=48,
compression_metrics=["compression_loss", "distillation_loss", "task_loss"],
Expand All @@ -598,7 +598,7 @@ def check_ovmodel_reshaping(self, ovmodel: OVModel):
model_id="yujiepan/tiny-random-swin-patch4-window7-224",
teacher_model_id="yujiepan/tiny-random-swin-patch4-window7-224",
nncf_compression_config=[UNSTRUCTURED_MOVEMENT_SPARSITY_CONFIG_FOR_SWIN, DEFAULT_QUANTIZATION_CONFIG],
expected_fake_quantize=28,
expected_fake_quantize=36,
expected_int8=28,
expected_binary_masks=48,
compression_metrics=["compression_loss", "distillation_loss", "task_loss"],
Expand Down Expand Up @@ -797,7 +797,9 @@ def prepare_model_and_dataset(self, desc: OVTrainerTestDescriptor):

self.feature_extractor = AutoFeatureExtractor.from_pretrained(desc.model_id)
self.tokenizer = self.feature_extractor
self.model = AutoModelForAudioClassification.from_pretrained(desc.model_id, num_labels=self.num_labels)
self.model = AutoModelForAudioClassification.from_pretrained(
desc.model_id, num_labels=self.num_labels, attn_implementation="eager"
)
self.teacher_model = None
if desc.teacher_model_id:
self.teacher_model = AutoModelForAudioClassification.from_pretrained(
Expand Down

0 comments on commit ca05db0

Please sign in to comment.