code: def eval_it(model, dataloader, args, epoch):
      global val_loss
      model.eval()
      tloss = 0.0
      tcnt = 0.0
      st_time = time.time()
      with tqdm(
          dataloader, desc="Eval Ep " + str(epoch), mininterval=60
      ) as tq:
          for batch in tq:
              with torch.no_grad():
                  pred = model(batch)
                  nll_loss = F.nll_loss(
                      pred.view(-1, pred.shape[-1]),
                      batch["tgt_text"].view(-1),
                      ignore_index=0,
                  )
              loss = nll_loss
              loss = loss.item()
              tloss += loss * len(batch["tgt_text"])
              tcnt += len(batch["tgt_text"])
              tq.set_postfix({"loss": tloss / tcnt}, refresh=False)
      print(
          "Eval Ep ",
          str(epoch),
          "AVG Loss ",
          tloss / tcnt,
          "Steps ",
          tcnt,
          "Time ",
          time.time() - st_time,
      )
      if tloss / tcnt < val_loss:
          print(
              "Saving best model ", "Ep ", epoch, " loss ", tloss / tcnt
          )
          torch.save(model, args.save_model + "best")
          val_loss = tloss / tcnt
  
file_path: dgl/examples/pytorch/graphwriter/train.py
imports: import os
  import sys
  import time
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from graphwriter import *
  from opts import *
  from tqdm import tqdm
  from utlis import *
  from pycocoevalcap.bleu.bleu import Bleu
  from pycocoevalcap.meteor.meteor import Meteor
  from pycocoevalcap.rouge.rouge import Rouge
label_desc: Use image node_id 2 for calling a global function with example usage: eval_it(model, dataloader, args, epoch) without return types