code: def check_equal(first, second, atol=1e-2, verbose=False):
      diction_x = {}
      diction_y = {}
  
      if verbose:
          for i, (x, y) in enumerate(zip(first, second)):
              print(x[1], y[1])
  
      for i, (x, y) in enumerate(zip(first, second)):
          k = 0
          while diction_x.get((k, x[1])) is not None:
              k = k + 1
          diction_x[k, x[1]] = x[0]
          k = 0
          while diction_y.get((k, y[1])) is not None:
              k = k + 1
          diction_y[k, y[1]] = y[0]
      if verbose:
          print()
          for i, (x, y) in enumerate(zip(diction_x, diction_y)):
              print(x, y)
  
      for i, (x, y) in enumerate(zip(diction_x, diction_y)):
          if x[0] == 1:
              continue
          if verbose:
              print("checking ", x[1], ":")
          y = diction_y[x[0], x[1]]
          x = diction_x[x[0], x[1]]
  
          if verbose:
              print(((x == float("inf")).nonzero(as_tuple=True)[0]))
              print(((y == float("inf")).nonzero(as_tuple=True)[0]))
          x = x.cpu().detach().numpy()
          y = y.cpu().detach().numpy()
  
          avgx = np.sum(abs(x), dtype=float)
          countx = x.shape[0]
          for i in range(len(x.shape) - 1):
              countx *= x.shape[i + 1]
              avgx = np.sum(avgx)
          tolerance = 1
          if avgx != float("inf") and avgx != -float("inf"):
              avgx = avgx / countx
              tolerance = avgx * atol
          if verbose:
              print("tolerance is ", tolerance)
              x = x.flatten()
              y = y.flatten()
              print("x = {}".format(x))
              print("y = {}".format(y))
              if any(x == float("inf")) or any(x == -float("inf")):
                  print("found infinity in x")
              if any(y == float("inf")) or any(y == -float("inf")):
                  print("found infinity in y")
              print(np.linalg.norm(x.astype("float64")))
              print(np.linalg.norm(y.astype("float64")))
              print("-" * 80)
          # toler = np.linalg.norm(x.astype('float64')) * 0.0005
          np.testing.assert_allclose(
              x, y, err_msg="Index: {}".format(i), atol=tolerance
          )
  
imports: import math
  import numpy
  import torch
  import pytest
  import random
  import copy
  from torch import nn
  from deepspeed import DeepSpeedTransformerLayer, DeepSpeedTransformerConfig
  from unit.modeling import BertConfig, BertLayerNorm, BertEncoder
  from unit.modelingpreln import BertEncoder
label_desc: Use image node_id 1 for calling a global function with example usage: check_equal(first, second, atol, verbose) without return types