Skip to content

Commit

Permalink
fix tie_word_embeddings
Browse files Browse the repository at this point in the history
  • Loading branch information
DesmonDay committed Jul 30, 2024
1 parent 7c18d9d commit 635be9e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions paddlenlp/trainer/plugins/unified_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,15 +1029,20 @@ def save_prefix_past_key_value(model_to_save, save_directory):
def get_expected_state_dict(model_to_save):
if isinstance(model_to_save, PretrainedModel):
state_dict = model_to_save.state_dict()
if (

Check warning on line 1032 in paddlenlp/trainer/plugins/unified_checkpoint.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/plugins/unified_checkpoint.py#L1032

Added line #L1032 was not covered by tests
hasattr(model_to_save.config, "tie_word_embeddings")
and model_to_save.config.tie_word_embeddings
and hasattr(model_to_save, "_tied_weights_keys")
and model_to_save._tied_weights_keys is not None
):
for key in model_to_save._tied_weights_keys:
if key in state_dict:
state_dict.pop(key)

Check warning on line 1040 in paddlenlp/trainer/plugins/unified_checkpoint.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/plugins/unified_checkpoint.py#L1038-L1040

Added lines #L1038 - L1040 were not covered by tests
elif isinstance(model_to_save, LoRAModel):
state_dict = model_to_save.get_trainable_state_dict()
elif isinstance(model_to_save, PrefixModelForCausalLM):
state_dict = model_to_save.prefix_encoder.state_dict()

if hasattr(model_to_save, "_tied_weights_keys") and model_to_save._tied_weights_keys is not None:
for key in model_to_save._tied_weights_keys:
if key in state_dict:
state_dict.pop(key)
return state_dict


Expand Down

0 comments on commit 635be9e

Please sign in to comment.