From 12b3b35366bbc2282c45407eae642cdab4c1e894 Mon Sep 17 00:00:00 2001 From: Ella Charlaix <80481427+echarlaix@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:35:56 +0100 Subject: [PATCH] Enable transformers v4.47 support (#2119) * enable latest transformers release * fix custom module test * adapt config push to hub tests --- setup.py | 8 +++---- tests/onnx/test_onnx_export_custom_module.py | 4 ++-- tests/test_configuration_utils.py | 24 +++++++------------- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/setup.py b/setup.py index 6736085943a..28b6941ebe8 100644 --- a/setup.py +++ b/setup.py @@ -51,7 +51,7 @@ "datasets>=1.2.1", "evaluate", "protobuf>=3.20.1", - "transformers>=4.36,<4.47.0", + "transformers>=4.36,<4.48.0", ], "onnxruntime-gpu": [ "onnx", @@ -60,19 +60,19 @@ "evaluate", "protobuf>=3.20.1", "accelerate", # ORTTrainer requires it. - "transformers>=4.36,<4.47.0", + "transformers>=4.36,<4.48.0", ], "exporters": [ "onnx", "onnxruntime", "timm", - "transformers>=4.36,<4.47.0", + "transformers>=4.36,<4.48.0", ], "exporters-gpu": [ "onnx", "onnxruntime-gpu", "timm", - "transformers>=4.36,<4.47.0", + "transformers>=4.36,<4.48.0", ], "exporters-tf": [ "tensorflow>=2.4,<=2.12.1", diff --git a/tests/onnx/test_onnx_export_custom_module.py b/tests/onnx/test_onnx_export_custom_module.py index 4398c14f01d..9416093c841 100644 --- a/tests/onnx/test_onnx_export_custom_module.py +++ b/tests/onnx/test_onnx_export_custom_module.py @@ -22,7 +22,7 @@ if is_torch_available(): import torch - from transformers.models.deberta import modeling_deberta + from transformers.models.sew_d import modeling_sew_d from optimum.utils import check_if_torch_greater @@ -36,7 +36,7 @@ def test_training(self): """Tests export of StableDropout in training mode.""" devnull = open(os.devnull, "wb") # drop_prob must be > 0 for the test to be meaningful - sd = modeling_deberta.StableDropout(0.1) + sd = modeling_sew_d.StableDropout(0.1) # Avoid warnings in training mode do_constant_folding = False # Dropout is a no-op in inference mode diff --git a/tests/test_configuration_utils.py b/tests/test_configuration_utils.py index 4c721f089d7..d70b01fe7e1 100644 --- a/tests/test_configuration_utils.py +++ b/tests/test_configuration_utils.py @@ -12,13 +12,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import os import tempfile import unittest from huggingface_hub import HfFolder, delete_repo from requests.exceptions import HTTPError -from transformers.testing_utils import TOKEN, USER, is_staging_test +from transformers.testing_utils import TOKEN, TemporaryHubRepo, is_staging_test from optimum.configuration_utils import BaseConfig @@ -69,12 +68,11 @@ def tearDownClass(cls): def test_push_to_hub(self): config = FakeConfig(attribute=15) - with tempfile.TemporaryDirectory() as tmp_dir: - config.save_pretrained( - os.path.join(tmp_dir, "optimum-test-base-config"), push_to_hub=True, token=self._token - ) - new_config = FakeConfig.from_pretrained(f"{USER}/optimum-test-base-config") + with TemporaryHubRepo(token=self._token) as tmp_repo: + config.push_to_hub(tmp_repo.repo_id, token=self._token) + + new_config = FakeConfig.from_pretrained(tmp_repo.repo_id) for k, v in config.to_dict().items(): if k != "optimum_version" and k != "transformers_version": self.assertEqual(v, getattr(new_config, k)) @@ -82,15 +80,9 @@ def test_push_to_hub(self): def test_push_to_hub_in_organization(self): config = FakeConfig(attribute=15) - with tempfile.TemporaryDirectory() as tmp_dir: - config.save_pretrained( - os.path.join(tmp_dir, "optimum-test-base-config-org"), - push_to_hub=True, - token=self._token, - organization="valid_org", - ) - - new_config = FakeConfig.from_pretrained("valid_org/optimum-test-base-config-org") + with TemporaryHubRepo(namespace="valid_org", token=self._token) as tmp_repo: + config.push_to_hub(tmp_repo.repo_id, token=self._token) + new_config = FakeConfig.from_pretrained(tmp_repo.repo_id) for k, v in config.to_dict().items(): if k != "optimum_version" and k != "transformers_version": self.assertEqual(v, getattr(new_config, k))