code: def measure_latency(model, num_iters=200, *, warmup_iters=50):
      device = next(model.parameters()).device
      num_feat = model.input_dim
      model.eval()
      latencys = []
      data = _build_random_data(device, num_feat)
      with torch.no_grad():
          try:
              for i in range(warmup_iters + num_iters):
                  if device.type == "cuda":
                      torch.cuda.synchronize()
                  start = time.time()
                  model(data)
                  if device.type == "cuda":
                      torch.cuda.synchronize()
                  dt = time.time() - start
                  if i >= warmup_iters:
                      latencys.append(dt)
          except RuntimeError as e:
              if "cuda" in str(e) or "CUDA" in str(e):
                  INF = 100
                  return INF
              else:
                  raise e
  
      return np.mean(latencys)
  
imports: import logging
  from collections import OrderedDict
  import time
  import numpy
  import torch
  import nni.retiarii.nn.pytorch
  from nni.nas.pytorch.mutables import Mutable, InputChoice, LayerChoice
label_desc: Use image node_id 3 for calling a global function with example usage: measure_latency(model, num_iters) and returns: np, INF