code: def _main():
      parser = argparse.ArgumentParser("SPOS Evolutional Search")
      parser.add_argument("--port", type=int, default=8084)
      parser.add_argument(
          "--imagenet-dir", type=str, default="./data/imagenet"
      )
      parser.add_argument(
          "--checkpoint",
          type=str,
          default="./data/checkpoint-150000.pth.tar",
      )
      parser.add_argument(
          "--spos-preprocessing",
          action="store_true",
          default=False,
          help="When true, image values will range from 0 to 255 and use BGR "
          "(as in original repo).",
      )
      parser.add_argument("--seed", type=int, default=42)
      parser.add_argument("--workers", type=int, default=6)
      parser.add_argument("--train-batch-size", type=int, default=128)
      parser.add_argument("--train-iters", type=int, default=200)
      parser.add_argument("--test-batch-size", type=int, default=512)
      parser.add_argument("--log-frequency", type=int, default=10)
      parser.add_argument("--label-smoothing", type=float, default=0.1)
      parser.add_argument(
          "--evolution-sample-size", type=int, default=10
      )
      parser.add_argument(
          "--evolution-population-size", type=int, default=50
      )
      parser.add_argument("--evolution-cycles", type=int, default=10)
      parser.add_argument(
          "--latency-filter",
          type=str,
          default=None,
          help="Apply latency filter by calling the name of the applied hardware.",
      )
      parser.add_argument(
          "--latency-threshold", type=float, default=100
      )
  
      args = parser.parse_args()
  
      # use a fixed set of image will improve the performance
      torch.manual_seed(args.seed)
      torch.cuda.manual_seed_all(args.seed)
      np.random.seed(args.seed)
      random.seed(args.seed)
      torch.backends.cudnn.deterministic = True
  
      assert torch.cuda.is_available()
  
      base_model = ShuffleNetV2OneShot()
      criterion = CrossEntropyLabelSmooth(1000, args.label_smoothing)
  
      if args.latency_filter:
          latency_filter = LatencyFilter(
              threshold=args.latency_threshold,
              predictor=args.latency_filter,
          )
      else:
          latency_filter = None
  
      evaluator = FunctionalEvaluator(
          evaluate_acc, criterion=criterion, args=args
      )
      evolution_strategy = strategy.RegularizedEvolution(
          model_filter=latency_filter,
          sample_size=args.evolution_sample_size,
          population_size=args.evolution_population_size,
          cycles=args.evolution_cycles,
      )
      exp = RetiariiExperiment(
          base_model, evaluator, strategy=evolution_strategy
      )
  
      exp_config = RetiariiExeConfig("local")
      exp_config.trial_concurrency = 2
      exp_config.trial_gpu_number = 1
      exp_config.max_trial_number = args.evolution_cycles
      exp_config.training_service.use_active_gpu = False
      exp_config.execution_engine = "base"
      exp_config.dummy_input = [1, 3, 224, 224]
  
      exp.run(exp_config, args.port)
  
      print("Exported models:")
      for i, model in enumerate(
          exp.export_top_models(formatter="dict")
      ):
          print(model)
          with open(f"architecture_final_{i}.json", "w") as f:
              json.dump(get_archchoice_by_model(model), f, indent=4)
  
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 4 for calling a global function with example usage: _main() without return types