class_docstr: This is an implementation of the loss function accompanying the adaptive softmax approximation for
  graphical processing units (GPU), described in the paper "Efficient softmax approximation for GPUs"
  (http://arxiv.org/abs/1609.04309).
class_docstr_tok: ["This","is","an","implementation","of","the","loss","function","accompanying","the","adaptive","softmax","approximation","for","graphical","processing","units","(","GPU",")",",","described","in","the","paper","``","Efficient","softmax","approximation","for","GPUs","''","(","http",":","\/\/arxiv.org\/abs\/1609.04309",")","."]
docstr: Aggregate logging outputs from data parallel training.
docstr_tok: ["Aggregate","logging","outputs","from","data","parallel","training","."]
code: def reduce_metrics(logging_outputs) -> None:
      """Aggregate logging outputs from data parallel training."""
      loss_sum = utils.item(
          sum(log.get("loss", 0) for log in logging_outputs)
      )
      ntokens = utils.item(
          sum(log.get("ntokens", 0) for log in logging_outputs)
      )
      sample_size = utils.item(
          sum(log.get("sample_size", 0) for log in logging_outputs)
      )
  
      metrics.log_scalar(
          "loss",
          loss_sum / sample_size / math.log(2),
          sample_size,
          round=3,
      )
      if sample_size != ntokens:
          metrics.log_scalar(
              "nll_loss",
              loss_sum / ntokens / math.log(2),
              ntokens,
              round=3,
          )
          metrics.log_derived(
              "ppl",
              lambda meters: utils.get_perplexity(
                  meters["nll_loss"].avg
              ),
          )
      else:
          metrics.log_derived(
              "ppl",
              lambda meters: utils.get_perplexity(meters["loss"].avg),
          )
  
file_path: fairseq/fairseq/criterions/adaptive_loss.py
imports: import math
  from dataclasses import dataclass
  import torch.nn.functional
  from fairseq import utils
  from fairseq.logging import metrics
  from fairseq.criterions import FairseqCriterion, register_criterion
  from fairseq.dataclass import FairseqDataclass
  from fairseq.dataclass.constants import DDP_BACKEND_CHOICES
  from omegaconf import II
label_desc: Use image node_id 4 for calling the AdaptiveLoss obj's underlying member method code with example usage: obj.reduce_metrics(logging_outputs) without return types