docstr: MultitaskAgent shuffles and combines examples from both classifier and the
  generator tasks in a single batch. We compute losses only for those exs in the
  batch resulting in losses and num_target_tokens vectors that are smaller than
  the.
  
  This method reshapes the losses and num_target_tokens vectors back to the batch size.
  This is needed to record local metrics as the metrics need to be of batch size for classifiers.
  
  Args:
      batch: batch being processed in this iteration.
      losses: classifier or generator loss vector (shape: b' X 1), where b' <= b.
      num_target_tokens: number of tokens in each examples for classification or generation tasks. (shape: b' X 1), where b' <= b.
      indices: indices of (either classification or generation) exs for which the loss was computed.
  
  Returns:
      A tuple of reshaped losses and num_target_tokens, both of shape: b X 1.
docstr_tok: ["MultitaskAgent","shuffles","and","combines","examples","from","both","classifier","and","the","generator","tasks","in","a","single","batch",".","We","compute","losses","only","for","those","exs","in","the","batch","resulting","in","losses","and","num_target_tokens","vectors","that","are","smaller","than","the",".","This","method","reshapes","the","losses","and","num_target_tokens","vectors","back","to","the","batch","size",".","This","is","needed","to","record","local","metrics","as","the","metrics","need","to","be","of","batch","size","for","classifiers",".","Args",":","batch",":","batch","being","processed","in","this","iteration",".","losses",":","classifier","or","generator","loss","vector","(","shape",":","b","'","X","1",")",",","where","b","'","<","=","b.","num_target_tokens",":","number","of","tokens","in","each","examples","for","classification","or","generation","tasks",".","(","shape",":","b","'","X","1",")",",","where","b","'","<","=","b.","indices",":","indices","of","(","either","classification","or","generation",")","exs","for","which","the","loss","was","computed",".","Returns",":","A","tuple","of","reshaped","losses","and","num_target_tokens",",","both","of","shape",":","b","X","1","."]
code: def _reshape_to_record_metrics(
      self, batch, losses, num_target_tokens, indices
  ):
      """
      MultitaskAgent shuffles and combines examples from both classifier and the
      generator tasks in a single batch. We compute losses only for those exs in the
      batch resulting in losses and num_target_tokens vectors that are smaller than
      the.
  
      This method reshapes the losses and num_target_tokens vectors back to the batch size.
      This is needed to record local metrics as the metrics need to be of batch size for classifiers.
  
      Args:
          batch: batch being processed in this iteration.
          losses: classifier or generator loss vector (shape: b' X 1), where b' <= b.
          num_target_tokens: number of tokens in each examples for classification or generation tasks. (shape: b' X 1), where b' <= b.
          indices: indices of (either classification or generation) exs for which the loss was computed.
  
      Returns:
          A tuple of reshaped losses and num_target_tokens, both of shape: b X 1.
      """
      val_id_shape = batch.valid_indices.shape
      reshaped_losses = self._reshape_tensor(
          val_id_shape, losses, indices
      )
      reshaped_num_target_tokens = self._reshape_tensor(
          val_id_shape, num_target_tokens, indices
      )
  
      return (reshaped_losses, reshaped_num_target_tokens)
  
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 9 for calling the DirectorFidAgent obj's underlying member method code with example usage: obj._reshape_to_record_metrics(batch, losses, num_target_tokens, indices) and returns: reshaped_losses,  reshaped_num_target_tokens