def reduce_metrics(logging_outputs) -> None:
        """Aggregate logging outputs from data parallel training."""
        loss_sum = sum(log.get("loss", 0) for log in logging_outputs)
        ntokens = sum(log.get("ntokens", 0) for log in logging_outputs)
        sample_size = sum(log.get("sample_size", 0) for log in logging_outputs)
        bart_loss_sum = sum(log.get("bart_loss", 0) for log in logging_outputs)

        # we divide by log(2) to convert the loss from base e to base 2
        metrics.log_scalar(
            "loss", loss_sum / sample_size / math.log(2), sample_size, round=3
        )
        metrics.log_scalar(
            "bart_loss", bart_loss_sum / sample_size / math.log(2), ntokens, 2, round=3
        )
        if sample_size != ntokens:
            metrics.log_scalar(
                "nll_loss", bart_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["bart_loss"].avg)
            )

        if "loss_prob_perplexity" in logging_outputs[0].keys():
            val = sum(log["loss_prob_perplexity"] for log in logging_outputs)
            metrics.log_scalar("loss_prob_perplexity", val / sample_size / math.log(2), round=3)
        if "code_perplexity" in logging_outputs[0].keys():
            val = sum(log["code_perplexity"] for log in logging_outputs)
            metrics.log_scalar("code_perplexity", val / len(logging_outputs), round=3)
Aggregate logging outputs from data parallel training.
speecht5/speecht5/criterions/text_pretrain_criterion.py