def compute(self, split):
        '''Compute the losses and return a dictionary with the losses.'''
        count = self.count
        # Loss dictionary
        loss_dict = {loss: getattr(self, loss)/count for loss in self.losses}
        # Format the losses for logging
        log_dict = { self.loss2logname(loss, split): value.item() 
            for loss, value in loss_dict.items() if not torch.isnan(value)}
        # Reset the losses
        self.reset()
        return log_dict
Compute the losses and return a dictionary with the losses.
mGPT/losses/base.py