    def reduce_metrics(cls, logging_outputs) -> None:
        """Aggregate logging outputs from data parallel training."""
        super().reduce_metrics(logging_outputs)

        sample_size = sum(log.get("sample_size", 0) for log in logging_outputs)

        rdrop_kl_loss = utils.item(
            sum(log.get("rdrop_kl_loss", 0) for log in logging_outputs)
            / sample_size
            / math.log(2)
        )
        if rdrop_kl_loss > 0:
            metrics.log_scalar("rdrop_kl_loss", rdrop_kl_loss)
Aggregate logging outputs from data parallel training.
fairseq/criterions/label_smoothed_cross_entropy_with_rdrop.py