Unverified Commit 136cd893 authored by JB (Don)'s avatar JB (Don) Committed by GitHub
Browse files

Always initialize tied output_embeddings if it has a bias term (#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.
parent 792819f6
...@@ -3748,10 +3748,12 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix ...@@ -3748,10 +3748,12 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix
else: else:
_loaded_keys = loaded_keys _loaded_keys = loaded_keys
not_initialized_submodules = set_initialized_submodules(model, _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: if hasattr(model.config, "tie_word_embeddings") and model.config.tie_word_embeddings:
output_embeddings = model.get_output_embeddings() output_embeddings = model.get_output_embeddings()
if output_embeddings is not None: if output_embeddings is not None:
# 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 output_embeddings._is_hf_initialized = True
else: else:
not_initialized_submodules = dict(model.named_modules()) not_initialized_submodules = dict(model.named_modules())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment