    def forward(
        self,
        prev_output_tokens,
        encoder_out,
        incremental_state=None,
        mode="speech",
        alignment=None,
        **kwargs,
    ):
        """
        Args:
            prev_output_tokens (LongTensor): previous decoder outputs of shape
                `(batch, tgt_len)`, for teacher forcing
            encoder_out (optional): output from the encoder, used for
                encoder-side attention
            incremental_state (dict): dictionary used for storing state during
                :ref:`Incremental decoding`
            features_only (bool, optional): only return features without
                applying output layer (default: False).
            full_context_alignment (bool, optional): don't apply
                auto-regressive mask to self-attention (default: False).

        Returns:
            sup_speech_ctc:
                dictionary{"logits": logits, "padding_mask": padding_mask}
            sup_speech_ali and unsup_speech:
                tuple:
                    - the decoder's output of shape `(batch, tgt_len, vocab)`
                    - a dictionary with any model-specific outputs
        """
        emb_weight = self.output_embedding.weight
        if (
            mode == "unsup_speech" and self.no_emb_update_unsup
        ):  # no gradient for embedding here
            emb_weight = emb_weight.detach()
        enc_out = (
            encoder_out["encoder_out"][0]
            if self.out_proj is None
            else self.out_proj(encoder_out["encoder_out"][0])
        )
        logits = F.linear(enc_out, emb_weight, None).transpose(0, 1)  # B X T X C
        others = None
        if mode in (
            "speech",
            "sup_speech_ctc",
        ):  # speech data with label, do forcealignment
            if len(encoder_out["encoder_padding_mask"]) > 0:
                padding_mask = encoder_out["encoder_padding_mask"][0]
                logits = logits.masked_fill(padding_mask, float("-inf"))
            else:
                seq_len, bsz = encoder_out["encoder_out"][0].size()[:2]
                padding_mask = torch.zeros(
                    bsz, seq_len, device=encoder_out["encoder_out"][0].device
                ).bool()
            return {"x": logits, "padding_mask": padding_mask}
        elif mode == "sup_speech_ali":
            src_lengths = None
            if len(encoder_out["encoder_padding_mask"]) > 0:
                src_lengths = (1 - encoder_out["encoder_padding_mask"][0].long()).sum(
                    -1
                )
            else:
                seq_len, bsz = encoder_out["encoder_out"][0].size()[:2]
                src_lengths = (
                    torch.ones(bsz, device=encoder_out["encoder_out"][0].device).long()
                    * seq_len
                )
            assert alignment is not None
            alignment = self.extend_alignment(
                alignment, src_lengths, prev_output_tokens
            )
            others = {"pseudo_target_tokens": alignment}
        elif mode == "unsup_speech":
            enc_out_ori = (
                encoder_out["encoder_unmasked_out"][0]
                if self.out_proj is None
                else self.out_proj(encoder_out["encoder_unmasked_out"][0])
            )
            logits_ori = F.linear(enc_out_ori, emb_weight, None).transpose(0, 1)
            if len(encoder_out["encoder_padding_mask"]) > 0:
                encoder_padding_mask = encoder_out["encoder_padding_mask"][0]
                logits_ori = logits_ori.masked_fill(encoder_padding_mask, float("-inf"))
            pseudo_labels = utils.log_softmax(logits_ori, dim=-1)
            others = {
                "pseudo_target_logprobs": pseudo_labels,
                "padding_mask": encoder_out["encoder_padding_mask"],  # B X T
                "mask_indices": encoder_out[
                    "mask_indices"
                ],  # True for masked frames B X T
            }
        return logits, others
Args:
prev_output_tokens (LongTensor): previous decoder outputs of shape
`(batch, tgt_len)`, for teacher forcing
encoder_out (optional): output from the encoder, used for
encoder-side attention
incremental_state (dict): dictionary used for storing state during
:ref:`Incremental decoding`
features_only (bool, optional): only return features without
applying output layer (default: False).
full_context_alignment (bool, optional): don't apply
auto-regressive mask to self-attention (default: False).

Returns:
sup_speech_ctc:
dictionary{"logits": logits, "padding_mask": padding_mask}
sup_speech_ali and unsup_speech:
tuple:
- the decoder's output of shape `(batch, tgt_len, vocab)`
- a dictionary with any model-specific outputs
examples/speech_text_joint_to_text/models/joint_speech_text_pretrain_transformer.py