From 65705b0d98050137d73f012638511cd33d84ef4b Mon Sep 17 00:00:00 2001 From: yujun <50394665+JunnYu@users.noreply.github.com> Date: Wed, 4 Jan 2023 12:14:43 +0800 Subject: [PATCH] add prepare_decoder_input_ids_from_labels method --- paddlenlp/transformers/t5/modeling.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/paddlenlp/transformers/t5/modeling.py b/paddlenlp/transformers/t5/modeling.py index e414582cf5ac..b85a0d554db4 100644 --- a/paddlenlp/transformers/t5/modeling.py +++ b/paddlenlp/transformers/t5/modeling.py @@ -1553,6 +1553,9 @@ def prepare_inputs_for_generation( "use_cache": use_cache, } + def prepare_decoder_input_ids_from_labels(self, labels: paddle.Tensor): + return self._shift_right(labels) + @staticmethod def expand_inputs_for_generation(input_ids, expand_size, attention_mask=None, **model_kwargs): index = paddle.tile(paddle.arange(input_ids.shape[0]).unsqueeze(-1), [1, expand_size]).reshape([-1]) @@ -1650,6 +1653,7 @@ def forward( output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, ): + return_dict = return_dict if return_dict is not None else self.config.use_return_dict encoder_outputs = self.encoder( input_ids=input_ids,