Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/transformers/core_model_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,13 @@ def convert_and_load_state_dict_in_model(
pattern_to_converter = {k: converter for converter in converters for k in converter.source_patterns}

state_dict = sorted(state_dict.items(), key=lambda kv: dot_natural_key(kv[0]))

from .integrations import is_fsdp_enabled
from .modeling_utils import is_local_dist_rank_0

if is_fsdp_enabled() and not is_local_dist_rank_0() and hf_quantizer is None:
state_dict = []

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is where the skip should happen, you r are creating a thread pool for notthing

for original_key, tensor in state_dict:
# 1. Rename the key according to all renaming pattern and optional weight converter patterns
renamed_key, source_pattern = rename_source_key(
Expand Down
4 changes: 4 additions & 0 deletions src/transformers/modeling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ def _load_parameter_into_model(model: "PreTrainedModel", param_name: str, tensor
parent, param_type = get_module_from_name(model, param_name)
if param_type in parent._parameters and not isinstance(tensor, nn.Parameter):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only used in _move_missing_keys_from_meta_to_device for missing keys, it does not really make sense for me can you elaborate on why?

tensor = nn.Parameter(tensor, requires_grad=tensor.is_floating_point())
# Only mark as initialized if we're in FSDP non-rank0 mode, to avoid expensive random initialization
# of empty tensors that will be synced from rank 0 anyway
if is_fsdp_enabled() and not is_local_dist_rank_0():
tensor._is_hf_initialized = True
# We need to use setattr here, as we set non-persistent buffers as well with this function (`load_state_dict`
# does not allow to do it)
setattr(parent, param_type, tensor)
Expand Down