Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix state dict hook for early fusion models #2317

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all 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: 5 additions & 2 deletions torchtune/modules/model_fusion/_early_fusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ def _state_dict_hook(module, state_dict, prefix, *args, **kwargs):
[!Note] This update changes the order of the OrderedDict
"""
for n, p in module.tok_embeddings.named_parameters():
state_dict[f"{prefix}decoder.tok_embeddings.{n}"] = p
del state_dict[f"{prefix}tok_embeddings.{n}"]
orig_key = f"{prefix}tok_embeddings.{n}"
if orig_key in state_dict:
# preserve the original tensor with its requires_grad state
state_dict[f"{prefix}decoder.tok_embeddings.{n}"] = state_dict[orig_key]
del state_dict[orig_key]

@staticmethod
def _load_state_dict_hook(module, state_dict, prefix, *args, **kwargs):
Expand Down