def forward(self, model, sample, reduce=True, loss_name="gpt"):
        """Compute the loss for the given sample.

        Returns a tuple with three elements:
        1) the loss
        2) the sample size, which is used as the denominator for the gradient
        3) logging outputs to display while training
        """
        net_output = model(**sample["net_input"])
        loss, _ = self.compute_loss(model, net_output, sample, reduce=reduce)
        sample_size = (sample["target"][sample["net_input"]['gpt_loss_mask']] != self.padding_idx).sum().int()
        logging_output = {
            "loss": loss.data,
            "ntokens": sample["ntokens"],
            "nsentences": sample["target"].size(0),
            "sample_size": sample_size,
        }
        # for loss_name_item in LOSS_NAMES:
        #     logging_output[loss_name_item] = 0.01
        #     logging_output[loss_name_item + "sample_size"] = 1
        logging_output[loss_name] = loss.data
        logging_output[loss_name + "sample_size"] = sample["ntokens"]
        return loss, sample_size, logging_output
Compute the loss for the given sample.

        Returns a tuple with three elements:
        1) the loss
        2) the sample size, which is used as the denominator for the gradient
        3) logging outputs to display while training
        
kosmos-2/unilm/criterions/unigpt.py