code: def eval_once(
      child_model,
      device,
      eval_set,
      criterion,
      valid_dataloader=None,
      test_dataloader=None,
  ):
      if eval_set == "test":
          assert test_dataloader is not None
          dataloader = test_dataloader
      elif eval_set == "valid":
          assert valid_dataloader is not None
          dataloader = valid_dataloader
      else:
          raise NotImplementedError(
              "Unknown eval_set '{}'".format(eval_set)
          )
  
      tot_acc = 0
      tot = 0
      losses = []
  
      with torch.no_grad():  # save memory
          for batch in dataloader:
              (sent_ids, mask), labels = batch
  
              sent_ids = sent_ids.to(device, non_blocking=True)
              mask = mask.to(device, non_blocking=True)
              labels = labels.to(device, non_blocking=True)
  
              logits = child_model((sent_ids, mask))  # run
  
              loss = criterion(logits, labels.long())
              loss = loss.mean()
              preds = logits.argmax(dim=1).long()
              acc = torch.eq(preds, labels.long()).long().sum().item()
  
              losses.append(loss)
              tot_acc += acc
              tot += len(labels)
  
      losses = torch.tensor(losses)
      loss = losses.mean()
      if tot > 0:
          final_acc = float(tot_acc) / tot
      else:
          final_acc = 0
          logger.info("Error in calculating final_acc")
      return final_acc, loss
  
imports: import sys
  import os
  import logging
  import pickle
  import shutil
  import random
  import math
  import time
  import datetime
  import argparse
  import distutils.util
  import numpy
  import torch
  from torch import nn
  from torch import optim
  from torch.utils.data import DataLoader
  import torch.nn.functional
  from model import Model
  from nni.nas.pytorch.fixed import apply_fixed_architecture
  from dataloader import read_data_sst
label_desc: Use image node_id 4 for calling a global function with example usage: eval_once(child_model, device, eval_set, criterion, valid_dataloader, test_dataloader) and returns: final_acc,  loss