Commit 1fc855e4 authored by Julien Chaumond's avatar Julien Chaumond
Browse files

[tests] Safety checks on CONFIG_MAPPING

parent 3c86b6f3
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
import os import os
import unittest import unittest
from transformers.configuration_auto import AutoConfig from transformers.configuration_auto import CONFIG_MAPPING, AutoConfig
from transformers.configuration_bert import BertConfig from transformers.configuration_bert import BertConfig
from transformers.configuration_roberta import RobertaConfig from transformers.configuration_roberta import RobertaConfig
...@@ -42,3 +42,13 @@ class AutoConfigTest(unittest.TestCase): ...@@ -42,3 +42,13 @@ class AutoConfigTest(unittest.TestCase):
def test_config_for_model_str(self): def test_config_for_model_str(self):
config = AutoConfig.for_model("roberta") config = AutoConfig.for_model("roberta")
self.assertIsInstance(config, RobertaConfig) self.assertIsInstance(config, RobertaConfig)
def test_pattern_matching_fallback(self):
"""
In cases where config.json doesn't include a model_type,
perform a few safety checks on the config mapping's order.
"""
# no key string should be included in a later key string (typical failure case)
keys = list(CONFIG_MAPPING.keys())
for i, key in enumerate(keys):
self.assertFalse(any(key in later_key for later_key in keys[i+1:]))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment