docstr: Compute the loss for the given sample.
  
  Returns a tuple with three elements:
  1) the loss
  2) the sample size, which is used as the denominator for the gradient
  3) logging outputs to display while training
docstr_tok: ["Compute","the","loss","for","the","given","sample",".","Returns","a","tuple","with","three","elements",":","1",")","the","loss","2",")","the","sample","size",",","which","is","used","as","the","denominator","for","the","gradient","3",")","logging","outputs","to","display","while","training"]
code: def forward(self, model, sample, reduce=True):
      """Compute the loss for the given sample.
  
      Returns a tuple with three elements:
      1) the loss
      2) the sample size, which is used as the denominator for the gradient
      3) logging outputs to display while training
      """
  
      src_tokens = sample["net_input"]["src_tokens"]
      src_lengths = sample["net_input"]["src_lengths"]
      prev_output_tokens = sample["net_input"]["prev_output_tokens"]
  
      encoder_out = model.encoder(src_tokens, src_lengths)
      student_output = model.student_decoder(
          prev_output_tokens, encoder_out
      )
      teacher_output = model.teacher_decoder(
          prev_output_tokens, encoder_out
      )
  
      (
          teacher_loss,
          teacher_nll_loss,
          teacher_probs,
      ) = self.compute_teacher_loss(
          model, teacher_output, sample, reduce=reduce
      )
  
      # do not propagate gradient from student loss to teacher output
      teacher_probs = teacher_probs.detach()
      student_loss, student_nll_loss = self.compute_student_loss(
          model, student_output, sample, teacher_probs, reduce=reduce
      )
  
      total_loss = student_loss + teacher_loss
  
      sample_size = (
          sample["target"].size(0)
          if self.args.sentence_avg
          else sample["ntokens"]
      )
      logging_output = {
          "teacher_loss": utils.item(teacher_loss.data)
          if reduce
          else teacher_loss.data,
          "teacher_nll_loss": utils.item(teacher_nll_loss.data)
          if reduce
          else teacher_nll_loss.data,
          "student_loss": utils.item(student_loss.data)
          if reduce
          else student_loss.data,
          "student_nll_loss": utils.item(student_nll_loss.data)
          if reduce
          else student_nll_loss.data,
          "loss": utils.item(total_loss.data)
          if reduce
          else total_loss.data,
          "ntokens": sample["ntokens"],
          "nsentences": sample["target"].size(0),
          "sample_size": sample_size,
      }
      return total_loss, sample_size, logging_output
  
file_path: translate/pytorch_translate/research/knowledge_distillation/dual_decoder_kd_loss.py
imports: import math
  from fairseq import utils
  from fairseq.criterions import LegacyFairseqCriterion, register_criterion
label_desc: Use image node_id 3 for calling the DualDecoderCriterion obj's underlying member method code with example usage: obj.forward(model, sample, reduce) and returns: total_loss,  sample_size,  logging_output