code: def diff(
      x1: Any, x2: Any, prefix: Tuple = ()
  ) -> Tuple[list, list, list]:
      mismatch = []
      if isinstance(x1, dict) and isinstance(x2, dict):
          only_left = [prefix + (k,) for k in x1.keys() - x2.keys()]
          only_right = [prefix + (k,) for k in x2.keys() - x1.keys()]
          for k in x2.keys() & x1.keys():
              _left, _right, _mismatch = diff(
                  x1[k], x2[k], prefix + (k,)
              )
              only_left.extend(_left)
              only_right.extend(_right)
              mismatch.extend(_mismatch)
      elif isinstance(x1, list) and isinstance(x2, list):
          only_left = list(range(len(x1) - 1, len(x2) - 1, -1))
          only_right = list(range(len(x1) - 1, len(x2) - 1, -1))
          for i, (v1, v2) in enumerate(zip(x1, x2)):
              _left, _right, _mismatch = diff(v1, v2, prefix + (i,))
              only_left.extend(_left)
              only_right.extend(_right)
              mismatch.extend(_mismatch)
      else:
          only_left = []
          only_right = []
          if isinstance(x1, torch.Tensor) and isinstance(
              x2, torch.Tensor
          ):
              _is_mismatch = not torch.all(x1 == x2)
          else:
              try:
                  _is_mismatch = bool(x1 != x2)
              except RuntimeError:
                  _is_mismatch = True
  
          if _is_mismatch:
              mismatch.append((prefix, type(x1), type(x2)))
  
      return only_left, only_right, mismatch
  
file_path: megatron-lm/megatron/core/dist_checkpointing/dict_utils.py
imports: from collections import defaultdict
  from typing import Any, Callable, Iterable, Optional, Tuple, Union
  import torch
label_desc: Use image node_id 2 for calling a global function with example usage: diff(x1, x2, prefix) and returns: only_left,  only_right,  mismatch