code: def test_inference(model_name):
      batch_size = 10
      download_data()
      eprint(f"testing inference on {model_name}")
  
      data_shape = (
          (3, 224, 224)
          if "inception" not in model_name
          else (3, 299, 299)
      )
      dataIter = mx.io.ImageRecordIter(
          path_imgrec=VAL_DATA,
          label_width=1,
          preprocess_threads=1,
          batch_size=batch_size,
          data_shape=data_shape,
          label_name="softmax_label",
          rand_crop=False,
          rand_mirror=False,
      )
      data_batch = dataIter.next()
      data = data_batch.data[0]
      label = data_batch.label[0]
      gpu_data = data.as_in_context(mx.gpu())
      gpu_label = label.as_in_context(mx.gpu())
  
      # This is to create a model and run the model once to initialize
      # all parameters.
      cpu_model = get_model(model_name)
      cpu_model.initialize(ctx=mx.cpu())
      cpu_model(mx.np.array(data, ctx=mx.cpu()))
      gpu_model = get_model(model_name)
      gpu_model.initialize(ctx=mx.gpu())
      gpu_model(mx.np.array(data, ctx=mx.gpu()))
  
      # Force the two models have the same parameters.
      cpu_params = cpu_model.collect_params()
      gpu_params = gpu_model.collect_params()
      for k in cpu_params.keys():
          cpu_param = cpu_params.get(k)
          gpu_param = gpu_params.get(k)
          gpu_param.set_data(cpu_param.data().as_in_context(mx.gpu()))
  
      cpu_data = mx.np.array(data, ctx=mx.cpu())
      for _ in range(5):
          # Run inference.
          with autograd.record(train_mode=False):
              cpu_out = cpu_model(cpu_data)
              gpu_out = gpu_model(gpu_data)
  
          max_val = np.max(np.abs(cpu_out.asnumpy()))
          gpu_max_val = np.max(np.abs(gpu_out.asnumpy()))
          eprint(
              model_name
              + ": CPU "
              + str(max_val)
              + ", GPU "
              + str(gpu_max_val)
          )
          assert_almost_equal(cpu_out / max_val, gpu_out / gpu_max_val)
  
file_path: mxnet/tests/python/gpu/test_gluon_model_zoo_gpu.py
imports: from __future__ import print_function
  import mxnet
  import numpy
  import copy
  from mxnet import autograd
  from mxnet.gluon.model_zoo.vision import get_model
  from mxnet.test_utils import assert_almost_equal
  import sys
  import os
  import unittest
  import pytest
label_desc: Use image node_id 3 for calling a global function with example usage: test_inference(model_name) without return types