class_docstr: Base class for the losses in order to combine commonly used methods.
class_docstr_tok: ["Base","class","for","the","losses","in","order","to","combine","commonly","used","methods","."]
docstr: Aggregates logging outputs from data parallel training.
  
  Args:
      logging_outputs: Output log with 'translation_loss' and
                       'prediction_loss'.
  Returns:
      agg_output: Aggregated logs.
docstr_tok: ["Aggregates","logging","outputs","from","data","parallel","training",".","Args",":","logging_outputs",":","Output","log","with","'translation_loss","'","and","'prediction_loss","'",".","Returns",":","agg_output",":","Aggregated","logs","."]
code: def aggregate_logging_outputs(logging_outputs):
      """Aggregates logging outputs from data parallel training.
  
      Args:
          logging_outputs: Output log with 'translation_loss' and
                           'prediction_loss'.
      Returns:
          agg_output: Aggregated logs.
      """
      ntokens = sum(log.get("ntokens", 0) for log in logging_outputs)
      nsentences = sum(
          log.get("nsentences", 0) for log in logging_outputs
      )
      sample_size = sum(
          log.get("sample_size", 0) for log in logging_outputs
      )
      agg_output = {
          "ntokens": ntokens,
          "nsentences": nsentences,
          "sample_size": sample_size,
      }
  
      for loss in ["translation_loss", "prediction_loss"]:
          loss_sum = sum(log.get(loss, 0) for log in logging_outputs)
  
          agg_output[loss] = loss_sum / sample_size / math.log(2)
          if loss == "translation_loss" and sample_size != ntokens:
              agg_output["nll_loss"] = loss_sum / ntokens / math.log(2)
  
      return agg_output
  
imports: import abc
  import math
  import torch
  from fairseq import utils
  from fairseq.criterions import register_criterion
  from fairseq.criterions.label_smoothed_cross_entropy import LabelSmoothedCrossEntropyCriterion
  from pytorch_translate.utils import maybe_cuda
label_desc: Use image node_id 3 for calling the _BasePredictionCriterion obj's underlying member method code with example usage: obj.aggregate_logging_outputs(logging_outputs) and returns: agg_output