code: def train(epoch, model, criterion, optimizer, loader, writer, args):
      model.train()
      meters = AverageMeterGroup()
      cur_lr = optimizer.param_groups[0]["lr"]
  
      for step, (x, y) in enumerate(loader):
          x, y = x.to("cuda"), y.to("cuda")
          cur_step = len(loader) * epoch + step
          optimizer.zero_grad()
          logits = model(x)
          loss = criterion(logits, y)
          loss.backward()
          optimizer.step()
  
          metrics = accuracy(logits, y)
          metrics["loss"] = loss.item()
          meters.update(metrics)
  
          writer.add_scalar("lr", cur_lr, global_step=cur_step)
          writer.add_scalar(
              "loss/train", loss.item(), global_step=cur_step
          )
          writer.add_scalar(
              "acc1/train", metrics["acc1"], global_step=cur_step
          )
          writer.add_scalar(
              "acc5/train", metrics["acc5"], global_step=cur_step
          )
  
          if step % args.log_frequency == 0 or step + 1 == len(loader):
              logger.info(
                  "Epoch [%d/%d] Step [%d/%d]  %s",
                  epoch + 1,
                  args.epochs,
                  step + 1,
                  len(loader),
                  meters,
              )
  
      logger.info("Epoch %d training summary: %s", epoch + 1, meters)
  
file_path: nni/examples/nas/legacy/oneshot/spos/evaluation.py
imports: import os
  import argparse
  import logging
  import random
  import numpy
  import torch
  import torch.nn
  import torchvision.transforms
  import torchvision.datasets
  from nni.retiarii import fixed_arch
  from nni.retiarii.oneshot.pytorch.utils import AverageMeterGroup
  from torch.utils.tensorboard import SummaryWriter
  from network import ShuffleNetV2OneShot
  from utils import CrossEntropyLabelSmooth, accuracy, ToBGRTensor
label_desc: Use image node_id 1 for calling a global function with example usage: train(epoch, model, criterion, optimizer, loader, writer, args) without return types