Update modeling_utils.py

This commit is contained in:
Cyril Vallez 2025-02-04 21:15:34 +01:00
parent e726b21f21
commit 367be9019b
No known key found for this signature in database

View file

@ -4720,7 +4720,7 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix
loaded_keys = [cls._fix_state_dict_key_on_load(key)[0] for key in loaded_state_dict_keys]
has_prefix_module = any(s.startswith(prefix) for s in loaded_keys) if len(prefix) > 0 else False
expects_prefix_module = any(s.startswith(prefix) for s in expected_keys) if len(len(prefix) > 0) else False
expects_prefix_module = any(s.startswith(prefix) for s in expected_keys) if len(prefix) > 0 else False
remove_prefix_from_model = not has_prefix_module and expects_prefix_module
add_prefix_to_model = has_prefix_module and not expects_prefix_module