Skip to content

Commit

Permalink
Always initialize tied output_embeddings if it has a bias term (huggi…
Browse files Browse the repository at this point in the history
…ngface#28947)

Continue to initialize tied output_embeddings if it has a bias term

The bias term is not tied, and so will need to be initialized accordingly.
  • Loading branch information
hackyon authored Feb 12, 2024
1 parent 792819f commit 136cd89
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/transformers/modeling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3748,11 +3748,13 @@ def _fix_key(key):
else:
_loaded_keys = loaded_keys
not_initialized_submodules = set_initialized_submodules(model, _loaded_keys)
# if we're about to tie the output embeds to the input embeds we don't need to init them
# If we're about to tie the output embeds to the input embeds we don't need to init them
if hasattr(model.config, "tie_word_embeddings") and model.config.tie_word_embeddings:
output_embeddings = model.get_output_embeddings()
if output_embeddings is not None:
output_embeddings._is_hf_initialized = True
# Still need to initialize if there is a bias term since biases are not tied.
if not hasattr(output_embeddings, "bias") or output_embeddings.bias is None:
output_embeddings._is_hf_initialized = True
else:
not_initialized_submodules = dict(model.named_modules())
# This will only initialize submodules that are not marked as initialized by the line above.
Expand Down

0 comments on commit 136cd89

Please sign in to comment.