Skip to content

Question about tie_weights #42832

@cjw-d

Description

@cjw-d

Hi,

I noticed that the logic of the tie_weights function has changed in the transformers 5.0.0rc.

In v4.x, when tie_word_embeddings=True, weights between embed_tokens.weight and lm_head.weight were always tied, regardless of whether both tensors were present in the checkpoint.

However, in v5.0.0rc, if both embed_tokens.weight and lm_head.weight are explicitly present in the checkpoint, the model no longer ties them, resulting in two independent copies of the weights.

https://github.com/huggingface/transformers/blob/v5.0.0rc1/src/transformers/modeling_utils.py#L2362-L2369

This change affects training behavior: gradients will now be computed and applied separately to the two weight matrices, potentially leading to divergent updates and inconsistent model behavior compared to previous versions.

I'm concerned this might introduce subtle training instabilities or break backward compatibility for users who expect tied embeddings and output layers by default (as was the case in v4.x). I’m wondering whether this change could lead to any unexpected problems?For example, although embed_tokens.weight and lm_head. weight exist in the checkpoint, I still want to tie these two weights.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions