def METHOD_NAME(self, model, sample, reduce=True):
    """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
    """
    token_embeddings = model.encoder.embed_tokens(sample["net_input"]["src_tokens"])
    input_logits, extra = model(**sample["net_input"])
    loss, nll_loss = self.compute_loss(
        model, (input_logits, extra), sample, reduce=reduce
    )
    sample_size = (
        sample["target"].size(0) if self.sentence_avg else sample["ntokens"]
    )
    if model.training:
        noise = self.noise_sampler.sample(sample_shape=token_embeddings.shape).to(
            token_embeddings
        )
        noised_embeddings = token_embeddings.clone() + noise
        noised_logits, _ = model(
            **sample["net_input"], token_embeddings=noised_embeddings
        )
        symm_kl = self._get_symm_kl(noised_logits, input_logits)
    if model.training:
        symm_kl = symm_kl * sample_size
        loss = loss + self.r3f_lambda * symm_kl
    logging_output = {
        "loss": loss.data,
        "nll_loss": nll_loss.data,
        "ntokens": sample["ntokens"],
        "nsentences": sample["target"].size(0),
        "sample_size": sample_size,
    }
    if model.training:
        logging_output.update(
            symm_kl=utils.item(symm_kl.data) if reduce else symm_kl.data
        )
    return loss, sample_size, logging_output