mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-31 02:02:21 +06:00
Fix module initialization for root module under Zero3 (#33632)
* Use all state dict keys when checking if root module is initialized. * Apply style corrections * Add comment explaining change. * Change comment phrasing.
This commit is contained in:
parent
4df3ccddb7
commit
95a2f5f6c3
@ -617,6 +617,9 @@ def set_initialized_submodules(model, state_dict_keys):
|
||||
not_initialized_submodules = {}
|
||||
for module_name, module in model.named_modules():
|
||||
loaded_keys = {k.replace(f"{module_name}.", "") for k in state_dict_keys if k.startswith(f"{module_name}.")}
|
||||
# When checking if the root module is loaded all state_dict_keys must be used.
|
||||
if module_name == "":
|
||||
loaded_keys = set(state_dict_keys)
|
||||
if loaded_keys.issuperset(module.state_dict()):
|
||||
module._is_hf_initialized = True
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user