From ebca14dfaae5cdc22b61e8170615319822d7a5e9 Mon Sep 17 00:00:00 2001 From: Ella Charlaix Date: Thu, 21 Mar 2024 11:38:01 +0100 Subject: [PATCH 1/5] Bump transformers version --- setup.py | 2 +- tests/openvino/test_modeling.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 5c6cf76404..3d79a626e3 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ INSTALL_REQUIRE = [ "torch>=1.11", - "transformers>=4.36.0,<4.39.0", + "transformers>=4.36.0,<4.40.0", "optimum @ git+https://github.com/huggingface/optimum.git#egg=optimum", "datasets>=1.4.0", "sentencepiece", diff --git a/tests/openvino/test_modeling.py b/tests/openvino/test_modeling.py index cdc7611ae9..a8124fa809 100644 --- a/tests/openvino/test_modeling.py +++ b/tests/openvino/test_modeling.py @@ -501,7 +501,7 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase): "qwen", "qwen2", "stablelm", - # "starcoder2", # TODO: enable with next transformers release + "starcoder2", ) GENERATION_LENGTH = 100 IS_SUPPORT_STATEFUL = is_openvino_version(">=", "2023.3") From be9673a5383da1e00e693668b5e8d19f077c5761 Mon Sep 17 00:00:00 2001 From: Ella Charlaix Date: Thu, 21 Mar 2024 14:35:20 +0100 Subject: [PATCH 2/5] Add generation config --- optimum/intel/neural_compressor/modeling_base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/optimum/intel/neural_compressor/modeling_base.py b/optimum/intel/neural_compressor/modeling_base.py index 72646a9f94..bec4a09c92 100644 --- a/optimum/intel/neural_compressor/modeling_base.py +++ b/optimum/intel/neural_compressor/modeling_base.py @@ -32,6 +32,7 @@ AutoModelForSequenceClassification, AutoModelForTokenClassification, AutoModelForVision2Seq, + GenerationConfig, GenerationMixin, PretrainedConfig, XLNetLMHeadModel, @@ -84,6 +85,7 @@ def __init__( self._device = getattr(self.model, "device", None) or torch.device( "cuda:0" if torch.cuda.is_available() else "cpu" ) + self.generation_config = GenerationConfig.from_model_config(config) # Registers the INCModelForXXX classes into the transformers AutoModel classes to avoid warnings when creating # a pipeline https://github.com/huggingface/transformers/blob/cad61b68396a1a387287a8e2e2fef78a25b79383/src/transformers/pipelines/base.py#L863 From 2417f68f815e97ef0a8935416313f69cea0c8052 Mon Sep 17 00:00:00 2001 From: Ella Charlaix Date: Thu, 21 Mar 2024 15:02:08 +0100 Subject: [PATCH 3/5] update setup --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3d79a626e3..d6e066b22c 100644 --- a/setup.py +++ b/setup.py @@ -61,7 +61,7 @@ "openvino": ["openvino>=2023.3", "nncf>=2.8.1"], "openvino-tokenizers": ["openvino-tokenizers[transformers]"], "nncf": ["nncf>=2.8.1"], - "ipex": ["intel-extension-for-pytorch"], + "ipex": ["intel-extension-for-pytorch", "transformers>=4.36.0,<4.39.0"], "diffusers": ["diffusers"], "quality": QUALITY_REQUIRE, "tests": TESTS_REQUIRE, From 5f9b1c4d69417a7a643ee0fab070d595571f7516 Mon Sep 17 00:00:00 2001 From: Ella Charlaix Date: Thu, 21 Mar 2024 15:49:44 +0100 Subject: [PATCH 4/5] fix --- tests/openvino/test_modeling.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/openvino/test_modeling.py b/tests/openvino/test_modeling.py index a8124fa809..ae0b55e575 100644 --- a/tests/openvino/test_modeling.py +++ b/tests/openvino/test_modeling.py @@ -524,10 +524,8 @@ def test_compare_to_transformers(self, model_arch): model_kwargs = {} if model_arch in self.REMOTE_CODE_MODELS: - model_kwargs = { - "config": AutoConfig.from_pretrained(model_id, trust_remote_code=True), - "trust_remote_code": True, - } + model_kwargs = {"trust_remote_code": True} + ov_model = OVModelForCausalLM.from_pretrained(model_id, export=True, ov_config=F32_CONFIG, **model_kwargs) self.assertIsInstance(ov_model.config, PretrainedConfig) self.assertTrue(ov_model.use_cache) From 8ea90db1cdb714fb17d22a6b0b591b9cb4e53e97 Mon Sep 17 00:00:00 2001 From: Ella Charlaix Date: Fri, 22 Mar 2024 11:15:08 +0100 Subject: [PATCH 5/5] add _convert_tokens_to_ids --- tests/openvino/test_modeling.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/openvino/test_modeling.py b/tests/openvino/test_modeling.py index b8938c7619..d1da08f58e 100644 --- a/tests/openvino/test_modeling.py +++ b/tests/openvino/test_modeling.py @@ -570,6 +570,10 @@ def test_pipeline(self, model_arch): "trust_remote_code": True, } tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=model_arch in self.REMOTE_CODE_MODELS) + + if model_arch == "qwen": + tokenizer._convert_tokens_to_ids = lambda x: 0 + model = OVModelForCausalLM.from_pretrained( model_id, export=True, use_cache=False, compile=False, **model_kwargs )