Deal with nested configs better in base class (#25237)
* Deal better with nested configs * Fixes * More fixes * Fix last test * Clean up existing configs * Remove hack in MPT Config * Update src/transformers/configuration_utils.py Co-authored-by: Younes Belkada <49240599+younesbelkada@users.noreply.github.com> * Fix setting a nested config via dict in the kwargs * Adapt common test * Add test for nested config load with dict --------- Co-authored-by: Younes Belkada <49240599+younesbelkada@users.noreply.github.com>
This commit is contained in:
@@ -118,9 +118,11 @@ class ConfigTester(object):
|
||||
|
||||
def check_config_can_be_init_without_params(self):
|
||||
if self.config_class.is_composition:
|
||||
return
|
||||
config = self.config_class()
|
||||
self.parent.assertIsNotNone(config)
|
||||
with self.parent.assertRaises(ValueError):
|
||||
config = self.config_class()
|
||||
else:
|
||||
config = self.config_class()
|
||||
self.parent.assertIsNotNone(config)
|
||||
|
||||
def check_config_arguments_init(self):
|
||||
kwargs = copy.deepcopy(config_common_kwargs)
|
||||
|
||||
@@ -210,6 +210,13 @@ class ConfigTestUtils(unittest.TestCase):
|
||||
f" {', '.join(keys_with_defaults)}."
|
||||
)
|
||||
|
||||
def test_nested_config_load_from_dict(self):
|
||||
config = AutoConfig.from_pretrained(
|
||||
"hf-internal-testing/tiny-random-CLIPModel", text_config={"num_hidden_layers": 2}
|
||||
)
|
||||
self.assertNotIsInstance(config.text_config, dict)
|
||||
self.assertEqual(config.text_config.__class__.__name__, "CLIPTextConfig")
|
||||
|
||||
def test_from_pretrained_subfolder(self):
|
||||
with self.assertRaises(OSError):
|
||||
# config is in subfolder, the following should not work without specifying the subfolder
|
||||
|
||||
Reference in New Issue
Block a user