src/transformers/models/t5/modeling_tf_t5.py/TFT5ForConditionalGeneration/prepare_inputs_for_generation
class TFT5ForConditionalGeneration:    def prepare_inputs_for_generation(
        self,
        inputs,
        past,
        attention_mask,
        use_cache=None,
        **kwargs,
    ):
        assert past is not None, "past has to be defined for encoder_outputs"

        # first step
        if len(past) < 2:
            encoder_outputs, past_key_values = past, None
        else:
            encoder_outputs, past_key_values = past[0], past[1]
        if "encoder_hidden_states" in kwargs:
            encoder_outputs = (*encoder_outputs, kwargs["encoder_hidden_states"])
        if "encoder_attentions" in kwargs:
            encoder_outputs = (*encoder_outputs, kwargs["encoder_attentions"])

        # cut decoder_input_ids if past is used
        if past_key_values is not None:
            inputs = inputs[:, -1:]

        return {
            "input_ids": None,  # inputs don't have to be defined, but still need to be passed to make Keras.layer.__call__ happy
            "decoder_input_ids": inputs,  # inputs are the decoder_input_ids
            "past_key_values": past_key_values,
            "encoder_outputs": encoder_outputs,
            "attention_mask": attention_mask,
            "use_cache": use_cache,
        }