            losses.append(accelerator.gather_for_metrics(loss.repeat(int(config["eval_batch_size"]))))
            del outputs
    losses = torch.cat(losses)
    try:
        eval_loss = torch.mean(losses)

    except OverflowError:
        perplexity = float("inf")
    print(f"epoch {epoch}: perplexity: {perplexity} eval_loss: {eval_loss}")
    base_log = {
        "perplexity": perplexity,
