def compute_loss(src, trg, output, loss_func, iter_size):
    """Computes the Loss of a given input and output

    Args:
        src (tuple): Source data point. Should be tuple of (tokens, lengths)
        trg (tuple): Target data point. Should be tuple of (tokens, lengths)
        output (`obj`:torch.Tensor): Output of given input
        loss_func (`obj`:torch.nn.Module): Loss function
        iter_size (int): Number of iterations to do before calling `optimizer.step`
    Returns:
        (`obj`:torch.Tensor, float): Total loss, loss per token
    """
    src, src_length = src
    trg, trg_length = trg

    num_toks = {"trg": int(sum(trg_length - 1)), "src": int(sum(src_length))}

    tgt_labels = trg[1:]
    T, B = output.size(0), output.size(1)

    loss = loss_func(output.view(T * B, -1), tgt_labels.contiguous().view(-1))

    loss_per_batch = loss.item()
    loss /= B * iter_size

    loss_per_token = loss_per_batch / num_toks["trg"]

    return loss, loss_per_token