Skip to content

Commit

Permalink
Do not warn about unexpected decoder weights when loading T5EncoderMo…
Browse files Browse the repository at this point in the history
…del and LongT5EncoderModel (huggingface#26211)

Ignore decoder weights when using T5EncoderModel and LongT5EncoderModel

Both T5EncoderModel and LongT5EncoderModel do not have any decoder layers, so
loading a pretrained model checkpoint such as t5-small will give warnings about
keys found in the model checkpoint that are not in the model itself.

To prevent this log warning, r"decoder" has been added to _keys_to_ignore_on_load_unexpected for
both T5EncoderModel and LongT5EncoderModel
  • Loading branch information
fleonce authored Sep 28, 2023
1 parent 38e9632 commit 216dff7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/transformers/models/longt5/modeling_longt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2152,6 +2152,7 @@ def _reorder_cache(self, past_key_values, beam_idx):
)
class LongT5EncoderModel(LongT5PreTrainedModel):
_tied_weights_keys = ["encoder.embed_tokens.weight"]
_keys_to_ignore_on_load_unexpected = [r"decoder"]

def __init__(self, config: LongT5Config):
super().__init__(config)
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/t5/modeling_t5.py
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,7 @@ def _reorder_cache(self, past_key_values, beam_idx):
)
class T5EncoderModel(T5PreTrainedModel):
_tied_weights_keys = ["encoder.embed_tokens.weight"]
_keys_to_ignore_on_load_unexpected = [r"decoder"]

def __init__(self, config: T5Config):
super().__init__(config)
Expand Down

0 comments on commit 216dff7

Please sign in to comment.