code: def retrain_bn(model, criterion, max_iters, log_freq, loader):
      with torch.no_grad():
          logger.info("Clear BN statistics...")
          for m in model.modules():
              if isinstance(m, nn.BatchNorm2d):
                  m.running_mean = torch.zeros_like(m.running_mean)
                  m.running_var = torch.ones_like(m.running_var)
  
          logger.info("Train BN with training set (BN sanitize)...")
          model.train()
          meters = AverageMeterGroup()
          for step in range(max_iters):
              inputs, targets = next(iter(loader))
              inputs, targets = inputs.to("cuda"), targets.to("cuda")
              logits = model(inputs)
              loss = criterion(logits, targets)
              metrics = accuracy(logits, targets)
              metrics["loss"] = loss.item()
              meters.update(metrics)
              if step % log_freq == 0 or step + 1 == max_iters:
                  logger.info(
                      "Train Step [%d/%d] %s",
                      step + 1,
                      max_iters,
                      meters,
                  )
  
imports: import time
  import json
  import random
  import logging
  import argparse
  import numpy
  import torch
  import torchvision.transforms
  import torchvision.datasets
  import nni
  from nn_meter import load_latency_predictor
  import nni.retiarii.nn.pytorch
  import nni.retiarii.strategy
  from nni.retiarii.evaluator.functional import FunctionalEvaluator
  from nni.retiarii.utils import original_state_dict_hooks
  from nni.retiarii.oneshot.pytorch.utils import AverageMeterGroup
  from nni.retiarii.experiment.pytorch import RetiariiExeConfig, RetiariiExperiment
  from network import ShuffleNetV2OneShot, load_and_parse_state_dict
  from utils import CrossEntropyLabelSmooth, accuracy, ToBGRTensor, get_archchoice_by_model
label_desc: Use image node_id 1 for calling a global function with example usage: retrain_bn(model, criterion, max_iters, log_freq, loader) without return types