def forward(self, src_tokens, src_lengths, prev_output_tokens, bert_input, **kwargs):
    "\n        Run the forward pass for an encoder-decoder model.\n\n        First feed a batch of source tokens through the encoder. Then, feed the\n        encoder output and previous decoder outputs (i.e., input feeding/teacher\n        forcing) to the decoder to produce the next outputs::\n\n            encoder_out = self.encoder(src_tokens, src_lengths)\n            return self.decoder(prev_output_tokens, encoder_out)\n\n        Args:\n            src_tokens (LongTensor): tokens in the source language of shape\n                `(batch, src_len)`\n            src_lengths (LongTensor): source sentence lengths of shape `(batch)`\n            prev_output_tokens (LongTensor): previous decoder outputs of shape\n                `(batch, tgt_len)`, for input feeding/teacher forcing\n\n        Returns:\n            tuple:\n                - the decoder's output of shape `(batch, tgt_len, vocab)`\n                - a dictionary with any model-specific outputs\n        "
    bert_encoder_padding_mask = bert_input.eq(self.berttokenizer.pad())
    (bert_encoder_out, _) = self.bert_encoder(bert_input, output_all_encoded_layers=True, attention_mask=(~ bert_encoder_padding_mask))
    bert_encoder_out = bert_encoder_out[self.bert_output_layer]
    if self.mask_cls_sep:
        bert_encoder_padding_mask += bert_input.eq(self.berttokenizer.cls())
        bert_encoder_padding_mask += bert_input.eq(self.berttokenizer.sep())
    bert_encoder_out = bert_encoder_out.permute(1, 0, 2).contiguous()
    bert_encoder_out = {'bert_encoder_out': bert_encoder_out, 'bert_encoder_padding_mask': bert_encoder_padding_mask}
    encoder_out = self.encoder(src_tokens, src_lengths=src_lengths, bert_encoder_out=bert_encoder_out)
    decoder_out = self.decoder(prev_output_tokens, encoder_out=encoder_out, bert_encoder_out=bert_encoder_out, **kwargs)
    return decoder_out
Run the forward pass for an encoder-decoder model.

First feed a batch of source tokens through the encoder. Then, feed the
encoder output and previous decoder outputs (i.e., input feeding/teacher
forcing) to the decoder to produce the next outputs::

    encoder_out = self.encoder(src_tokens, src_lengths)
    return self.decoder(prev_output_tokens, encoder_out)

Args:
    src_tokens (LongTensor): tokens in the source language of shape
        `(batch, src_len)`
    src_lengths (LongTensor): source sentence lengths of shape `(batch)`
    prev_output_tokens (LongTensor): previous decoder outputs of shape
        `(batch, tgt_len)`, for input feeding/teacher forcing

Returns:
    tuple:
        - the decoder's output of shape `(batch, tgt_len, vocab)`
        - a dictionary with any model-specific outputs
def forward(self, src_tokens, src_lengths, prev_output_tokens, bert_input, **kwargs):
    "\n        Run the forward pass for an encoder-decoder model.\n\n        First feed a batch of source tokens through the encoder. Then, feed the\n        encoder output and previous decoder outputs (i.e., input feeding/teacher\n        forcing) to the decoder to produce the next outputs::\n\n            encoder_out = self.encoder(src_tokens, src_lengths)\n            return self.decoder(prev_output_tokens, encoder_out)\n\n        Args:\n            src_tokens (LongTensor): tokens in the source language of shape\n                `(batch, src_len)`\n            src_lengths (LongTensor): source sentence lengths of shape `(batch)`\n            prev_output_tokens (LongTensor): previous decoder outputs of shape\n                `(batch, tgt_len)`, for input feeding/teacher forcing\n\n        Returns:\n            tuple:\n                - the decoder's output of shape `(batch, tgt_len, vocab)`\n                - a dictionary with any model-specific outputs\n        "
    bert_encoder_padding_mask = bert_input.eq(self.berttokenizer.pad())
    (bert_encoder_out, _) = self.bert_encoder(bert_input, output_all_encoded_layers=True, attention_mask=(~ bert_encoder_padding_mask))
    bert_encoder_out = bert_encoder_out[self.bert_output_layer]
    if self.mask_cls_sep:
        bert_encoder_padding_mask += bert_input.eq(self.berttokenizer.cls())
        bert_encoder_padding_mask += bert_input.eq(self.berttokenizer.sep())
    bert_encoder_out = bert_encoder_out.permute(1, 0, 2).contiguous()
    bert_encoder_out = {'bert_encoder_out': bert_encoder_out, 'bert_encoder_padding_mask': bert_encoder_padding_mask}
    encoder_out = self.encoder(src_tokens, src_lengths=src_lengths, bert_encoder_out=bert_encoder_out)
    decoder_out = self.decoder(prev_output_tokens, encoder_out=encoder_out, bert_encoder_out=bert_encoder_out, **kwargs)
    return decoder_out