Avoid using get_list_of_files (#15287)
* Avoid using get_list_of_files in config * Wip, change tokenizer file getter * Remove call in tokenizer files * Remove last call to get_list_model_files * Better tests * Unit tests for new function * Document bad API
This commit is contained in:
@@ -313,6 +313,7 @@ class ConfigTestUtils(unittest.TestCase):
|
||||
class ConfigurationVersioningTest(unittest.TestCase):
|
||||
def test_local_versioning(self):
|
||||
configuration = AutoConfig.from_pretrained("bert-base-cased")
|
||||
configuration.configuration_files = ["config.4.0.0.json"]
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
configuration.save_pretrained(tmp_dir)
|
||||
@@ -325,23 +326,26 @@ class ConfigurationVersioningTest(unittest.TestCase):
|
||||
|
||||
# Will need to be adjusted if we reach v42 and this test is still here.
|
||||
# Should pick the old configuration file as the version of Transformers is < 4.42.0
|
||||
configuration.configuration_files = ["config.42.0.0.json"]
|
||||
configuration.hidden_size = 768
|
||||
configuration.save_pretrained(tmp_dir)
|
||||
shutil.move(os.path.join(tmp_dir, "config.4.0.0.json"), os.path.join(tmp_dir, "config.42.0.0.json"))
|
||||
new_configuration = AutoConfig.from_pretrained(tmp_dir)
|
||||
self.assertEqual(new_configuration.hidden_size, 768)
|
||||
|
||||
def test_repo_versioning_before(self):
|
||||
# This repo has two configuration files, one for v5.0.0 and above with an added token, one for versions lower.
|
||||
repo = "microsoft/layoutxlm-base"
|
||||
# This repo has two configuration files, one for v4.0.0 and above with a different hidden size.
|
||||
repo = "hf-internal-testing/test-two-configs"
|
||||
|
||||
import transformers as new_transformers
|
||||
|
||||
new_transformers.configuration_utils.__version__ = "v5.0.0"
|
||||
new_transformers.configuration_utils.__version__ = "v4.0.0"
|
||||
new_configuration = new_transformers.models.auto.AutoConfig.from_pretrained(repo)
|
||||
self.assertEqual(new_configuration.tokenizer_class, None)
|
||||
self.assertEqual(new_configuration.hidden_size, 2)
|
||||
|
||||
# Testing an older version by monkey-patching the version in the module it's used.
|
||||
import transformers as old_transformers
|
||||
|
||||
old_transformers.configuration_utils.__version__ = "v3.0.0"
|
||||
old_configuration = old_transformers.models.auto.AutoConfig.from_pretrained(repo)
|
||||
self.assertEqual(old_configuration.tokenizer_class, "XLMRobertaTokenizer")
|
||||
self.assertEqual(old_configuration.hidden_size, 768)
|
||||
|
||||
Reference in New Issue
Block a user