Reduce the error log when using core models that need their weights renamed, and provide a step forward (#32656)
* Fin * Modify msg * Finish up nits
This commit is contained in:
@@ -1640,17 +1640,18 @@ class ModelUtilsTest(TestCasePlus):
|
||||
|
||||
logger = logging.get_logger("transformers.modeling_utils")
|
||||
config = PretrainedConfig()
|
||||
warning_msg_gamma = "A parameter name that contains `gamma` will be renamed internally"
|
||||
warning_msg_gamma = "`gamma_param` -> `weight_param`"
|
||||
model = TestModelGamma(config)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
model.save_pretrained(tmp_dir)
|
||||
with LoggingLevel(logging.WARNING):
|
||||
with LoggingLevel(logging.INFO):
|
||||
with CaptureLogger(logger) as cl1:
|
||||
_, loading_info = TestModelGamma.from_pretrained(tmp_dir, config=config, output_loading_info=True)
|
||||
|
||||
missing_keys = loading_info["missing_keys"]
|
||||
unexpected_keys = loading_info["unexpected_keys"]
|
||||
self.assertIn("`TestModelGamma`", cl1.out)
|
||||
self.assertIn(warning_msg_gamma, cl1.out)
|
||||
self.assertIn("gamma_param", missing_keys)
|
||||
self.assertIn("weight_param", unexpected_keys)
|
||||
@@ -1664,17 +1665,18 @@ class ModelUtilsTest(TestCasePlus):
|
||||
def forward(self):
|
||||
return self.beta_param.sum()
|
||||
|
||||
warning_msg_beta = "A parameter name that contains `beta` will be renamed internally"
|
||||
warning_msg_beta = "`beta_param` -> `bias_param`"
|
||||
model = TestModelBeta(config)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
model.save_pretrained(tmp_dir)
|
||||
with LoggingLevel(logging.WARNING):
|
||||
with LoggingLevel(logging.INFO):
|
||||
with CaptureLogger(logger) as cl2:
|
||||
_, loading_info = TestModelBeta.from_pretrained(tmp_dir, config=config, output_loading_info=True)
|
||||
|
||||
missing_keys = loading_info["missing_keys"]
|
||||
unexpected_keys = loading_info["unexpected_keys"]
|
||||
self.assertIn("`TestModelBeta`", cl2.out)
|
||||
self.assertIn(warning_msg_beta, cl2.out)
|
||||
self.assertIn("beta_param", missing_keys)
|
||||
self.assertIn("bias_param", unexpected_keys)
|
||||
|
||||
Reference in New Issue
Block a user