Skip to content

Commit 8f50efd

Browse files
authored
Fix CI with changes from huggingface-hub 0.8.0 (#227)
* Fix test script for huggingface_hub 0.8.0 release * Fix exception type * Fix test_save_model_with_different_name
1 parent 65bb7fa commit 8f50efd

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

tests/onnxruntime/test_modeling_ort.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
)
1818

1919
import onnxruntime
20+
from huggingface_hub.utils import EntryNotFoundError
2021
from optimum.onnxruntime import (
2122
ONNX_WEIGHTS_NAME,
2223
ORTModelForCausalLM,
@@ -50,9 +51,8 @@ def test_load_model_from_hub(self):
5051
self.assertIsInstance(model.config, PretrainedConfig)
5152

5253
def test_load_model_from_hub_without_onnx_model(self):
53-
with self.assertRaises(Exception) as context:
54+
with self.assertRaises(EntryNotFoundError):
5455
ORTModel.from_pretrained(self.FAIL_ONNX_MODEL_ID)
55-
self.assertEqual("Not Found", context.exception.response.reason)
5656

5757
@require_hf_token
5858
def test_load_model_from_hub_private(self):
@@ -72,10 +72,11 @@ def test_save_model(self):
7272
def test_save_model_with_different_name(self):
7373
with tempfile.TemporaryDirectory() as tmpdirname:
7474
test_model_name = "model-test.onnx"
75-
local_model_path = str(Path(self.LOCAL_MODEL_PATH).joinpath("model.onnx").absolute())
76-
# copy two models to simulate a optimization
77-
shutil.copy(local_model_path, os.path.join(tmpdirname, test_model_name))
78-
shutil.copy(local_model_path, os.path.join(tmpdirname, "model.onnx"))
75+
model = ORTModel.from_pretrained(self.LOCAL_MODEL_PATH)
76+
77+
# save two models to simulate a optimization
78+
model.save_pretrained(tmpdirname)
79+
model.save_pretrained(tmpdirname, file_name=test_model_name)
7980

8081
model = ORTModel.from_pretrained(tmpdirname, file_name=test_model_name)
8182

tests/test_configuration_utils.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import tempfile
1717
import unittest
1818

19-
from transformers.testing_utils import PASS, USER, is_staging_test
19+
from transformers.testing_utils import TOKEN, USER, is_staging_test
2020

21-
from huggingface_hub import delete_repo, login
21+
from huggingface_hub import HfFolder, delete_repo, set_access_token
2222
from optimum.configuration_utils import BaseConfig
2323
from requests.exceptions import HTTPError
2424

@@ -47,22 +47,24 @@ def test_create_and_test_config_from_and_save_pretrained(self):
4747
class ConfigPushToHubTester(unittest.TestCase):
4848
@classmethod
4949
def setUpClass(cls):
50-
cls._token = login(username=USER, password=PASS)
50+
cls._token = TOKEN
51+
set_access_token(TOKEN)
52+
HfFolder.save_token(TOKEN)
5153

5254
@classmethod
5355
def tearDownClass(cls):
5456
try:
55-
delete_repo(token=cls._token, name="optimum-test-base-config")
57+
delete_repo(token=cls._token, repo_id="optimum-test-base-config")
5658
except HTTPError:
5759
pass
5860

5961
try:
60-
delete_repo(token=cls._token, name="optimum-test-base-config-org", organization="valid_org")
62+
delete_repo(token=cls._token, repo_id="valid_org/optimum-test-base-config-org")
6163
except HTTPError:
6264
pass
6365

6466
try:
65-
delete_repo(token=cls._token, name="optimum-test-base-dynamic-config")
67+
delete_repo(token=cls._token, repo_id="optimum-test-base-dynamic-config")
6668
except HTTPError:
6769
pass
6870

0 commit comments

Comments
 (0)