docstr: Aggregate logging outputs from data parallel training.
docstr_tok: ["Aggregate","logging","outputs","from","data","parallel","training","."]
code: def aggregate_logging_outputs(logging_outputs):
      """Aggregate logging outputs from data parallel training."""
      loss_sum = sum(log.get("loss", 0) for log in logging_outputs)
      nll_loss_sum = sum(
          log.get("nll_loss", 0) for log in logging_outputs
      )
      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
      )
      return {
          "loss": loss_sum / sample_size if sample_size > 0 else 0.0,
          "nll_loss": nll_loss_sum / ntokens / math.log(2),
          "ntokens": ntokens,
          "nsentences": nsentences,
          "sample_size": sample_size,
      }
  
file_path: translate/pytorch_translate/research/rescore/rescoring_criterion.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import math
  import torch
  from fairseq import utils
  from fairseq.criterions import LegacyFairseqCriterion, register_criterion
  from pytorch_translate import generate, utils
  from pytorch_translate.rescoring.model_scorers import SimpleModelScorer
  from pytorch_translate.rescoring.rescorer import add_args, combine_weighted_scores, Rescorer
label_desc: Use image node_id 4 for calling the RescoringCriterion obj's underlying member method code with example usage: obj.aggregate_logging_outputs(logging_outputs) and returns: dict