Skip to content

Commit f6133d7

Browse files
authored
Revert "Automatic safetensors conversion when lacking these files (#2… (#29507)
Revert "Automatic safetensors conversion when lacking these files (#29390)" This reverts commit a69cbf4.
1 parent ffe60fd commit f6133d7

File tree

2 files changed

+4
-81
lines changed

2 files changed

+4
-81
lines changed

src/transformers/modeling_utils.py

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from contextlib import contextmanager
3030
from dataclasses import dataclass
3131
from functools import partial, wraps
32-
from threading import Thread
3332
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
3433
from zipfile import is_zipfile
3534

@@ -3208,39 +3207,9 @@ def from_pretrained(
32083207
)
32093208
if resolved_archive_file is not None:
32103209
is_sharded = True
3211-
3212-
if resolved_archive_file is not None:
3213-
if filename in [WEIGHTS_NAME, WEIGHTS_INDEX_NAME]:
3214-
# If the PyTorch file was found, check if there is a safetensors file on the repository
3215-
# If there is no safetensors file on the repositories, start an auto conversion
3216-
safe_weights_name = SAFE_WEIGHTS_INDEX_NAME if is_sharded else SAFE_WEIGHTS_NAME
3217-
has_file_kwargs = {
3218-
"revision": revision,
3219-
"proxies": proxies,
3220-
"token": token,
3221-
}
3222-
cached_file_kwargs = {
3223-
"cache_dir": cache_dir,
3224-
"force_download": force_download,
3225-
"resume_download": resume_download,
3226-
"local_files_only": local_files_only,
3227-
"user_agent": user_agent,
3228-
"subfolder": subfolder,
3229-
"_raise_exceptions_for_gated_repo": False,
3230-
"_raise_exceptions_for_missing_entries": False,
3231-
"_commit_hash": commit_hash,
3232-
**has_file_kwargs,
3233-
}
3234-
if not has_file(pretrained_model_name_or_path, safe_weights_name, **has_file_kwargs):
3235-
Thread(
3236-
target=auto_conversion,
3237-
args=(pretrained_model_name_or_path,),
3238-
kwargs=cached_file_kwargs,
3239-
name="Thread-autoconversion",
3240-
).start()
3241-
else:
3242-
# Otherwise, no PyTorch file was found, maybe there is a TF or Flax model file.
3243-
# We try those to give a helpful error message.
3210+
if resolved_archive_file is None:
3211+
# Otherwise, maybe there is a TF or Flax model file. We try those to give a helpful error
3212+
# message.
32443213
has_file_kwargs = {
32453214
"revision": revision,
32463215
"proxies": proxies,

tests/test_modeling_utils.py

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import os.path
2121
import sys
2222
import tempfile
23-
import threading
2423
import unittest
2524
import unittest.mock as mock
2625
import uuid
@@ -1429,7 +1428,7 @@ def test_safetensors_on_the_fly_wrong_user_opened_pr(self):
14291428
bot_opened_pr_title = None
14301429

14311430
for discussion in discussions:
1432-
if discussion.author == "SFconvertbot":
1431+
if discussion.author == "SFconvertBot":
14331432
bot_opened_pr = True
14341433
bot_opened_pr_title = discussion.title
14351434

@@ -1452,51 +1451,6 @@ def test_safetensors_on_the_fly_specific_revision(self):
14521451
with self.assertRaises(EnvironmentError):
14531452
BertModel.from_pretrained(self.repo_name, use_safetensors=True, token=self.token, revision="new-branch")
14541453

1455-
def test_absence_of_safetensors_triggers_conversion(self):
1456-
config = BertConfig(
1457-
vocab_size=99, hidden_size=32, num_hidden_layers=5, num_attention_heads=4, intermediate_size=37
1458-
)
1459-
initial_model = BertModel(config)
1460-
1461-
# Push a model on `main`
1462-
initial_model.push_to_hub(self.repo_name, token=self.token, safe_serialization=False)
1463-
1464-
# Download the model that doesn't have safetensors
1465-
BertModel.from_pretrained(self.repo_name, token=self.token)
1466-
1467-
for thread in threading.enumerate():
1468-
if thread.name == "Thread-autoconversion":
1469-
thread.join(timeout=10)
1470-
1471-
with self.subTest("PR was open with the safetensors account"):
1472-
discussions = self.api.get_repo_discussions(self.repo_name)
1473-
1474-
bot_opened_pr = None
1475-
bot_opened_pr_title = None
1476-
1477-
for discussion in discussions:
1478-
if discussion.author == "SFconvertbot":
1479-
bot_opened_pr = True
1480-
bot_opened_pr_title = discussion.title
1481-
1482-
self.assertTrue(bot_opened_pr)
1483-
self.assertEqual(bot_opened_pr_title, "Adding `safetensors` variant of this model")
1484-
1485-
@mock.patch("transformers.safetensors_conversion.spawn_conversion")
1486-
def test_absence_of_safetensors_triggers_conversion_failed(self, spawn_conversion_mock):
1487-
spawn_conversion_mock.side_effect = HTTPError()
1488-
1489-
config = BertConfig(
1490-
vocab_size=99, hidden_size=32, num_hidden_layers=5, num_attention_heads=4, intermediate_size=37
1491-
)
1492-
initial_model = BertModel(config)
1493-
1494-
# Push a model on `main`
1495-
initial_model.push_to_hub(self.repo_name, token=self.token, safe_serialization=False)
1496-
1497-
# The auto conversion is mocked to always raise; ensure that it doesn't raise in the main thread
1498-
BertModel.from_pretrained(self.repo_name, token=self.token)
1499-
15001454

15011455
@require_torch
15021456
@is_staging_test

0 commit comments

Comments
 (0)