Skip to content

Commit

Permalink
Avoid race condition (huggingface#31973)
Browse files Browse the repository at this point in the history
* [test_all] hub

* remove delete

* remove delete

* remove delete

* remove delete

* remove delete

* remove delete

* [test_all]

* [test_all]

* [test_all]

* [test_all]

* [test_all]

* [test_all]

---------

Co-authored-by: ydshieh <[email protected]>
  • Loading branch information
2 people authored and zucchini-nlp committed Jul 16, 2024
1 parent b75e6f6 commit 4c0e021
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 32 deletions.
14 changes: 10 additions & 4 deletions tests/generation/test_configuration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,11 @@ def test_push_to_hub(self):
if k != "transformers_version":
self.assertEqual(v, getattr(new_config, k))

# Reset repo
delete_repo(token=self._token, repo_id="test-generation-config")
try:
# Reset repo
delete_repo(token=self._token, repo_id="test-generation-config")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand All @@ -278,8 +281,11 @@ def test_push_to_hub_in_organization(self):
if k != "transformers_version":
self.assertEqual(v, getattr(new_config, k))

# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-generation-config-org")
try:
# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-generation-config-org")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand Down
14 changes: 10 additions & 4 deletions tests/utils/test_configuration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ def test_push_to_hub(self):
if k != "transformers_version":
self.assertEqual(v, getattr(new_config, k))

# Reset repo
delete_repo(token=self._token, repo_id="test-config")
try:
# Reset repo
delete_repo(token=self._token, repo_id="test-config")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand All @@ -149,8 +152,11 @@ def test_push_to_hub_in_organization(self):
if k != "transformers_version":
self.assertEqual(v, getattr(new_config, k))

# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-config-org")
try:
# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-config-org")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand Down
14 changes: 10 additions & 4 deletions tests/utils/test_feature_extraction_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ def test_push_to_hub(self):
for k, v in feature_extractor.__dict__.items():
self.assertEqual(v, getattr(new_feature_extractor, k))

# Reset repo
delete_repo(token=self._token, repo_id="test-feature-extractor")
try:
# Reset repo
delete_repo(token=self._token, repo_id="test-feature-extractor")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand All @@ -106,8 +109,11 @@ def test_push_to_hub_in_organization(self):
for k, v in feature_extractor.__dict__.items():
self.assertEqual(v, getattr(new_feature_extractor, k))

# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-feature-extractor")
try:
# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-feature-extractor")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand Down
14 changes: 10 additions & 4 deletions tests/utils/test_image_processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ def test_push_to_hub(self):
for k, v in image_processor.__dict__.items():
self.assertEqual(v, getattr(new_image_processor, k))

# Reset repo
delete_repo(token=self._token, repo_id="test-image-processor")
try:
# Reset repo
delete_repo(token=self._token, repo_id="test-image-processor")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand All @@ -117,8 +120,11 @@ def test_push_to_hub_in_organization(self):
for k, v in image_processor.__dict__.items():
self.assertEqual(v, getattr(new_image_processor, k))

# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-image-processor")
try:
# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-image-processor")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand Down
14 changes: 10 additions & 4 deletions tests/utils/test_modeling_flax_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ def test_push_to_hub(self):
max_diff = (base_params[key] - new_params[key]).sum().item()
self.assertLessEqual(max_diff, 1e-3, msg=f"{key} not identical")

# Reset repo
delete_repo(token=self._token, repo_id="test-model-flax")
try:
# Reset repo
delete_repo(token=self._token, repo_id="test-model-flax")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand Down Expand Up @@ -115,8 +118,11 @@ def test_push_to_hub_in_organization(self):
max_diff = (base_params[key] - new_params[key]).sum().item()
self.assertLessEqual(max_diff, 1e-3, msg=f"{key} not identical")

# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-model-flax-org")
try:
# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-model-flax-org")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand Down
14 changes: 10 additions & 4 deletions tests/utils/test_modeling_tf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,11 @@ def test_push_to_hub(self):
break
self.assertTrue(models_equal)

# Reset repo
delete_repo(token=self._token, repo_id="test-model-tf")
try:
# Reset repo
delete_repo(token=self._token, repo_id="test-model-tf")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand Down Expand Up @@ -786,8 +789,11 @@ def test_push_to_hub_in_organization(self):
break
self.assertTrue(models_equal)

# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-model-tf-org")
try:
# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-model-tf-org")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand Down
14 changes: 10 additions & 4 deletions tests/utils/test_modeling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1847,8 +1847,11 @@ def test_push_to_hub(self):
for p1, p2 in zip(model.parameters(), new_model.parameters()):
self.assertTrue(torch.equal(p1, p2))

# Reset repo
delete_repo(token=self._token, repo_id="test-model")
try:
# Reset repo
delete_repo(token=self._token, repo_id="test-model")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand Down Expand Up @@ -1887,8 +1890,11 @@ def test_push_to_hub_in_organization(self):
for p1, p2 in zip(model.parameters(), new_model.parameters()):
self.assertTrue(torch.equal(p1, p2))

# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-model-org")
try:
# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-model-org")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand Down
14 changes: 10 additions & 4 deletions tests/utils/test_tokenization_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ def test_push_to_hub(self):
new_tokenizer = BertTokenizer.from_pretrained(f"{USER}/test-tokenizer")
self.assertDictEqual(new_tokenizer.vocab, tokenizer.vocab)

# Reset repo
delete_repo(token=self._token, repo_id="test-tokenizer")
try:
# Reset repo
delete_repo(token=self._token, repo_id="test-tokenizer")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand All @@ -167,8 +170,11 @@ def test_push_to_hub_in_organization(self):
new_tokenizer = BertTokenizer.from_pretrained("valid_org/test-tokenizer-org")
self.assertDictEqual(new_tokenizer.vocab, tokenizer.vocab)

# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-tokenizer-org")
try:
# Reset repo
delete_repo(token=self._token, repo_id="valid_org/test-tokenizer-org")
except: # noqa E722
pass

# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
Expand Down

0 comments on commit 4c0e021

Please sign in to comment.