code: def _devices_match(
      device1: torch.device, device2: torch.device
  ) -> bool:
      """Whether two PyTorch devices are equivalent"""
      device1 = torch.device(device1)
      device2 = torch.device(device2)
      if device1.type != device2.type:
          return False
      if device1.type == "cuda":
          index1 = device1.index
          index2 = device2.index
          if index1 is None:
              index1 = torch.cuda.current_device()
          if index2 is None:
              index2 = torch.cuda.current_device()
          if index1 != index2:
              return False
      return True
  
imports: import collections
  import contextlib
  from dataclasses import dataclass
  import enum
  import inspect
  import io
  import itertools
  import threading
  from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, Union
  import warnings
  import torch
  from torch.distributed.distributed_c10d import _get_default_group
  from apex.multi_tensor_apply import multi_tensor_applier
  import amp_C
  import distributed_adam_cuda
  from torch.distributed.distributed_c10d import _coalescing_manager
label_desc: Use image node_id 2 for calling a global function with example usage: _devices_match(device1, device2) and returns: True, False, False