This commit is contained in:
thomwolf
2019-01-28 17:47:29 +01:00
parent a45a9cc0e1
commit bd3b3aee9c
2 changed files with 6 additions and 2 deletions

View File

@@ -606,7 +606,8 @@ class BertPreTrainedModel(nn.Module):
for name, child in module._modules.items():
if child is not None:
load(child, prefix + name + '.')
load(model, prefix='' if hasattr(model, 'bert') else 'bert.')
start_prefix = 'bert.' if not hasattr(model, 'bert') and any(s.startwith('bert.') for s in state_dict.keys()) else ''
load(model, prefix=start_prefix)
if len(missing_keys) > 0:
logger.info("Weights of {} not initialized from pretrained model: {}".format(
model.__class__.__name__, missing_keys))