Update Transformers to huggingface_hub >= 0.1.0 (#14251)
* Update Transformers to huggingface_hub >= 0.1.0 * Forgot to save... * Style * Fix test
This commit is contained in:
@@ -26,7 +26,7 @@ from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
||||
from huggingface_hub import HfApi, Repository
|
||||
from huggingface_hub import Repository, delete_repo, login
|
||||
from requests.exceptions import HTTPError
|
||||
from transformers import (
|
||||
AutoTokenizer,
|
||||
@@ -1307,19 +1307,18 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
||||
class TrainerIntegrationWithHubTester(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls._api = HfApi(endpoint=ENDPOINT_STAGING)
|
||||
cls._token = cls._api.login(username=USER, password=PASS)
|
||||
cls._token = login(username=USER, password=PASS)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
for model in ["test-trainer", "test-trainer-epoch", "test-trainer-step"]:
|
||||
try:
|
||||
cls._api.delete_repo(token=cls._token, name=model)
|
||||
delete_repo(token=cls._token, name=model)
|
||||
except HTTPError:
|
||||
pass
|
||||
|
||||
try:
|
||||
cls._api.delete_repo(token=cls._token, name="test-trainer-org", organization="valid_org")
|
||||
delete_repo(token=cls._token, name="test-trainer-org", organization="valid_org")
|
||||
except HTTPError:
|
||||
pass
|
||||
|
||||
@@ -1396,6 +1395,10 @@ class TrainerIntegrationWithHubTester(unittest.TestCase):
|
||||
print(commits, len(commits))
|
||||
|
||||
def test_push_to_hub_with_saves_each_n_steps(self):
|
||||
num_gpus = max(1, get_gpu_count())
|
||||
if num_gpus > 2:
|
||||
return
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
trainer = get_regression_trainer(
|
||||
output_dir=os.path.join(tmp_dir, "test-trainer-step"),
|
||||
@@ -1409,7 +1412,8 @@ class TrainerIntegrationWithHubTester(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
_ = Repository(tmp_dir, clone_from=f"{USER}/test-trainer-step", use_auth_token=self._token)
|
||||
commits = self.get_commit_history(tmp_dir)
|
||||
expected_commits = [f"Training in progress, step {i}" for i in range(20, 0, -5)]
|
||||
total_steps = 20 // num_gpus
|
||||
expected_commits = [f"Training in progress, step {i}" for i in range(total_steps, 0, -5)]
|
||||
expected_commits.append("initial commit")
|
||||
self.assertListEqual(commits, expected_commits)
|
||||
print(commits, len(commits))
|
||||
|
||||
Reference in New Issue
Block a user