code: def check_state_dict_equal(
      d1: OrderedDict,
      d2: OrderedDict,
      ignore_device: bool = True,
      ignore_dtype: bool = False,
  ):
      assert len(list(d1.keys())) == len(
          list(d2.keys())
      ), f"Number of keys unequal: {len(list(d1.keys()))} vs {len(list(d2.keys()))}"
      for k, v1 in d1.items():
          assert k in d2
          v2 = d2[k]
          if isinstance(v1, dict):
              assert isinstance(v2, dict)
              check_state_dict_equal(v1, v2, ignore_device)
          elif isinstance(v1, list):
              assert isinstance(v2, list)
              for v1_i, v2_i in zip(v1, v2):
                  if isinstance(v1_i, torch.Tensor):
                      assert isinstance(v2_i, torch.Tensor)
                      if not ignore_device:
                          v1_i = v1_i.to("cpu")
                          v2_i = v2_i.to("cpu")
                      if ignore_dtype:
                          v1_i = v1_i.to(v2_i.dtype)
                      assert_close_loose(v1_i, v2_i)
                  elif isinstance(v1_i, dict):
                      assert isinstance(v2_i, dict)
                      check_state_dict_equal(v1_i, v2_i, ignore_device)
                  else:
                      assert (
                          v1_i == v2_i
                      ), f"{v1_i} not equals to {v2_i}"
          elif isinstance(v1, torch.Tensor):
              assert isinstance(v2, torch.Tensor)
              if not ignore_device:
                  v1 = v1.to("cpu")
                  v2 = v2.to("cpu")
              if ignore_dtype:
                  v1 = v1.to(v2.dtype)
              assert_close_loose(v1, v2)
          else:
              assert v1 == v2, f"{v1} not equals to {v2}"
  
file_path: ColossalAI/colossalai/testing/comparison.py
imports: from typing import Any, List, OrderedDict
  import torch
  import torch.distributed
  from torch import Tensor
  from torch.distributed import ProcessGroup
  from torch.testing import assert_close
  from torch.utils._pytree import tree_flatten
label_desc: Use image node_id 5 for calling a global function with example usage: check_state_dict_equal(d1, d2, ignore_device, ignore_dtype) without return types