"...git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "777b1bfe6236ca7034d5eb6358e37c2345101886"
Unverified Commit 33aafc26 authored by Sylvain Gugger's avatar Sylvain Gugger Committed by GitHub
Browse files

Skip keys not in the state dict when finding mismatched weights (#24749)

parent 3d869726
...@@ -3157,6 +3157,9 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix ...@@ -3157,6 +3157,9 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix
mismatched_keys = [] mismatched_keys = []
if ignore_mismatched_sizes: if ignore_mismatched_sizes:
for checkpoint_key in loaded_keys: for checkpoint_key in loaded_keys:
# If the checkpoint is sharded, we may not have the key here.
if checkpoint_key not in state_dict:
continue
model_key = checkpoint_key model_key = checkpoint_key
if remove_prefix_from_model: if remove_prefix_from_model:
# The model key starts with `prefix` but `checkpoint_key` doesn't so we add it. # The model key starts with `prefix` but `checkpoint_key` doesn't so we add it.
......
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