Use commit hash to look in cache instead of calling head (#18534)
* Use commit hash to look in cache instead of calling head * Add tests * Add attr for local configs too * Stupid typos * Fix tests * Update src/transformers/utils/hub.py Co-authored-by: Julien Chaumond <julien@huggingface.co> * Address Julien's comments Co-authored-by: Julien Chaumond <julien@huggingface.co>
This commit is contained in:
@@ -21,6 +21,7 @@ from transformers import CONFIG_MAPPING, AutoConfig, BertConfig, GPT2Config, T5C
|
||||
from transformers.testing_utils import (
|
||||
DUMMY_UNKNOWN_IDENTIFIER,
|
||||
SMALL_MODEL_IDENTIFIER,
|
||||
RequestCounter,
|
||||
require_tensorflow_probability,
|
||||
require_tf,
|
||||
slow,
|
||||
@@ -287,3 +288,21 @@ class TFAutoModelTest(unittest.TestCase):
|
||||
def test_model_from_pt_suggestion(self):
|
||||
with self.assertRaisesRegex(EnvironmentError, "Use `from_pt=True` to load this model"):
|
||||
_ = TFAutoModel.from_pretrained("hf-internal-testing/tiny-bert-pt-only")
|
||||
|
||||
def test_cached_model_has_minimum_calls_to_head(self):
|
||||
# Make sure we have cached the model.
|
||||
_ = TFAutoModel.from_pretrained("hf-internal-testing/tiny-random-bert")
|
||||
with RequestCounter() as counter:
|
||||
_ = TFAutoModel.from_pretrained("hf-internal-testing/tiny-random-bert")
|
||||
self.assertEqual(counter.get_request_count, 0)
|
||||
self.assertEqual(counter.head_request_count, 1)
|
||||
self.assertEqual(counter.other_request_count, 0)
|
||||
|
||||
# With a sharded checkpoint
|
||||
_ = TFAutoModel.from_pretrained("ArthurZ/tiny-random-bert-sharded")
|
||||
with RequestCounter() as counter:
|
||||
_ = TFAutoModel.from_pretrained("ArthurZ/tiny-random-bert-sharded")
|
||||
self.assertEqual(counter.get_request_count, 0)
|
||||
# There is no pytorch_model.bin so we still get one call for this one.
|
||||
self.assertEqual(counter.head_request_count, 2)
|
||||
self.assertEqual(counter.other_request_count, 0)
|
||||
|
||||
Reference in New Issue
Block a user