code: def check_operator_accuracy(
      sym_fp32,
      sym_bf16,
      data_shape,
      num_input_data=1,
      bf16_use_fp32_params=False,
      rtol=1e-1,
      atol=5e-1,
      etol=0,
  ):
      """
      check accuracy for bfloat16 operators
  
      sym_fp32: Symbol
          fp32 operator
      sym_bf16: Symbol
          bf16 operator
      data_shape: tuple of int
          input data shape for fp32/bf16 symbol
      num_input_data: int
          number of input data, default is 1, should set different values for those operators with multiple inputs, like concat, elemwise_add, etc.
      bf16_use_fp32_params: bool
          currently only bn use this param as True, since bf16 bn only accept bf16 data with fp32 mean/var/scale/shift
      rtol: float
          the relative threshold
      atol: float
          the absolute threshold
      etol: float
          The error rate threshold, allow a small amount of value not consistent between bf16 and fp32
      """
      if isinstance(data_shape, tuple):
          data_shape = {"data": data_shape}
      data_range = (0.0, 10.0)
      data_list_fp32 = list()
      data_list_bf16 = list()
      for i, (_, shape) in enumerate(data_shape.items()):
          data_list_fp32.append(
              mx.nd.random.uniform(
                  low=data_range[0], high=data_range[1], shape=shape
              )
          )
          data_list_bf16.append(data_list_fp32[i].astype("bfloat16"))
  
      # Functions such as broadcast_add require shapes for both inputs in order to infer shape
      arg_shapes, _, aux_shapes = sym_fp32.infer_shape(**data_shape)
      arg_names = sym_fp32.list_arguments()
      aux_names = sym_fp32.list_auxiliary_states()
  
      exe_fp32 = sym_fp32._simple_bind(ctx=mx.cpu(), **data_shape)
  
      arg_params_fp32 = {}
      aux_params_fp32 = {}
      type_dict = {}
      for i, arg_name in enumerate(arg_names):
          if i < num_input_data:
              exe_fp32.arg_dict[arg_name][:] = data_list_fp32[i]
              continue
          arg_params_fp32[arg_name] = mx.nd.random.uniform(
              low=data_range[0], high=data_range[1], shape=arg_shapes[i]
          )
          exe_fp32.arg_dict[arg_name][:] = arg_params_fp32[arg_name]
          # specify the dtype of arguments
          if not bf16_use_fp32_params:
              type_dict.update({arg_name: "bfloat16"})
  
      for i, aux_name in enumerate(aux_names):
          aux_params_fp32[aux_name] = mx.nd.random.uniform(
              low=data_range[0], high=data_range[1], shape=aux_shapes[i]
          )
          exe_fp32.aux_dict[aux_name][:] = aux_params_fp32[aux_name]
  
      output_fp32 = exe_fp32.forward()[0]
  
      exe_bf16 = sym_bf16._simple_bind(
          ctx=mx.cpu(), **data_shape, type_dict=type_dict
      )
  
      arg_params_bf16 = {}
      aux_params_bf16 = {}
      for i, arg_name in enumerate(arg_names):
          if i < num_input_data:
              exe_bf16.arg_dict[arg_name][:] = data_list_bf16[i]
              continue
  
          if bf16_use_fp32_params:
              exe_bf16.arg_dict[arg_name][:] = arg_params_fp32[arg_name]
          else:
              exe_bf16.arg_dict[arg_name][:] = arg_params_fp32[
                  arg_name
              ].astype("bfloat16")
  
      for aux_name in aux_names:
          if bf16_use_fp32_params:
              exe_bf16.aux_dict[aux_name][:] = aux_params_fp32[aux_name]
          else:
              exe_bf16.aux_dict[aux_name][:] = aux_params_fp32[
                  aux_name
              ].astype("bfloat16")
  
      output_bf16 = exe_bf16.forward()[0]
      output_bf16.wait_to_read()
      output_bf16_2_fp32 = output_bf16.astype("float32")
      assert_almost_equal_with_err(
          output_bf16_2_fp32,
          output_fp32,
          rtol=rtol,
          atol=atol,
          etol=etol,
      )
  
imports: import os
  import sys
  import mxnet
  import numpy
  from random import randint
  import itertools
  from mxnet.test_utils import assert_almost_equal_with_err, rand_shape_nd
  import pytest
label_desc: Use image node_id 1 for calling a global function with example usage: check_operator_accuracy(sym_fp32, sym_bf16, data_shape, num_input_data, bf16_use_fp32_params, rtol, atol, etol) without return types