Skip to content

Commit

Permalink
Enable transformers v4.47 support (#2119)
Browse files Browse the repository at this point in the history
* enable latest transformers release

* fix custom module test

* adapt config push to hub tests
  • Loading branch information
echarlaix authored Dec 12, 2024
1 parent 4a7cb29 commit 12b3b35
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tests/onnx/test_onnx_export_custom_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
24 changes: 8 additions & 16 deletions tests/test_configuration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -69,28 +68,21 @@ 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))

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))

0 comments on commit 12b3b35

Please sign in to comment.