code: def pre_train_pair(
      train_loader, model, criterion, margin_softmax, optimizer, epoch
  ):
      top1 = AverageMeter()
      top5 = AverageMeter()
  
      model.train()
      for i, (vis_img, nir_img, vis_label, nir_label) in enumerate(
          train_loader
      ):
          input = torch.cat((vis_img, nir_img), 0).cuda(
              non_blocking=True
          )
          label = torch.cat((vis_label, nir_label), 0).cuda(
              non_blocking=True
          )
          batch_size = input.size(0)
  
          if batch_size < 2 * args.batch_size:
              continue
  
          # forward
          output = model(input)[0]
          output = margin_softmax(output, label)
          loss = criterion(output, label)
  
          optimizer.zero_grad()
          loss.backward()
          optimizer.step()
  
          # measure accuracy and record loss
          prec1, prec5 = accuracy(output.data, label.data, topk=(1, 5))
          top1.update(prec1.item(), batch_size)
          top5.update(prec5.item(), batch_size)
  
          # print log
          if i % args.print_iter == 0:
              info = "====> Epoch: [{:0>3d}][{:3d}/{:3d}] | ".format(
                  epoch, i, len(train_loader)
              )
              info += "Loss: ce: {:4.3f} | ".format(loss.item())
              info += "Prec@1: {:4.2f} ({:4.2f}) Prec@5: {:4.2f} ({:4.2f})".format(
                  top1.val, top1.avg, top5.val, top5.avg
              )
              print(info)
  
file_path: insightface/recognition/idmmd/train.py
imports: import os
  import argparse
  import random
  import numpy
  import torch
  import torch.nn
  import torch.backends.cudnn
  from utils import *
  from network.lightcnn112 import LightCNN_29Layers_cosface
  from losses import IDMMD, CosFace
  from dataset_mix import Real_Dataset_112_paired, IdentitySampler, GenIdx
label_desc: Use image node_id 2 for calling a global function with example usage: pre_train_pair(train_loader, model, criterion, margin_softmax, optimizer, epoch) without return types