docstr: Override RAG.decode_forced to return latent states and using generator_output
  method to generate the decoder output.
docstr_tok: ["Override","RAG.decode_forced","to","return","latent","states","and","using","generator_output","method","to","generate","the","decoder","output","."]
code: def decode_forced(
      self,
      encoder_states: Tuple[torch.Tensor, ...],
      ys: torch.LongTensor,
  ) -> Tuple[
      torch.Tensor, torch.LongTensor, torch.Tensor, torch.BoolTensor
  ]:
      """
      Override RAG.decode_forced to return latent states and using generator_output
      method to generate the decoder output.
      """
      bsz = ys.size(0)
      seqlen = ys.size(1)
      inputs = ys.narrow(1, 0, seqlen - 1)
      if (
          ys[:, 0] == self.START_IDX
      ).any() and self.generation_model != "bart":
          raise AssertionError(
              "The Beginning of Sentence token is automatically added to the "
              "label in decode_forced, but you included it in the label. This means "
              "your model will have a double BOS token, which is probably not what "
              "you intended."
          )
      doc_scores = encoder_states[4]
  
      inputs = (
          self._rag_model_interface.get_initial_forced_decoder_input(
              bsz,
              inputs,
              n_docs=doc_scores.size(1)
              if doc_scores is not None
              else None,
              start_idx=self.START_IDX,
              end_idx=self.END_IDX,
              input_turns_cnt=encoder_states[2],
          )
      )
      latent, mask = self.decoder_output_before_final_projection(
          inputs, encoder_states
      )
      logits = self.generator_output(latent)
      _, preds = logits.max(dim=-1)
      return logits, preds, latent, mask
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  from typing import Optional, Any, Dict, Tuple, Union, List
  from abc import abstractmethod
  from parlai.agents.transformer.modules import TransformerDecoderLayer
  from parlai.agents.fid.fid import FidAgent, FidModel
  from parlai.core.message import Message
  from parlai.core.metrics import AverageMetric
  from parlai.core.opt import Opt
  from parlai.core.params import ParlaiParser
  from parlai.core.torch_generator_agent import PPLMetric
  from parlai.core.torch_agent import Batch, DictionaryAgent
  import parlai.utils.logging
  from projects.blenderbot2.agents.blenderbot2 import BlenderBot2FidAgent, BlenderBot2FidModel, T5BlenderBot2FidModel
  from parlai.agents.fid.fid import WizIntGoldDocRetrieverFiDAgent
  import parlai.agents.transformer.modules.ffn
  from parlai.agents.transformer.modules import LAYER_NORM_EPS
label_desc: Use image node_id 7 for calling the DirectorFidModelMixin obj's underlying member method code with example usage: obj.decode_forced(encoder_states, ys) and returns: logits,  preds,  latent,  mask