code: def recursive_copy_to_device(
      value: Any, non_blocking: bool, device: torch.device
  ) -> Any:
      """
      Recursively searches lists, tuples, dicts and copies any object which
      supports an object.to API (e.g. tensors) to device if possible.
      Other values are passed as-is in the result.
  
      Note:  These are all copies, so if there are two objects that reference
      the same object, then after this call, there will be two different objects
      referenced on the device.
      """
      if isinstance(value, list) or isinstance(value, tuple):
          device_val = []
          for val in value:
              device_val.append(
                  recursive_copy_to_device(
                      val, non_blocking=non_blocking, device=device
                  )
              )
  
          return (
              device_val
              if isinstance(value, list)
              else tuple(device_val)
          )
      elif isinstance(value, collections.abc.Mapping):
          device_val = {}
          for key, val in value.items():
              device_val[key] = recursive_copy_to_device(
                  val, non_blocking=non_blocking, device=device
              )
  
          return device_val
      elif callable(getattr(value, "to", None)):
          return value.to(device=device, non_blocking=non_blocking)
  
      return value
  
imports: import collections.abc
  import contextlib
  import json
  import logging
  import os
  import time
  from functools import partial
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.nn
  from classy_vision.generic.distributed_util import broadcast_object, is_primary
  from fvcore.common.file_io import PathManager
label_desc: Use image node_id 12 for calling a global function with example usage: recursive_copy_to_device(value, non_blocking, device) and returns: value, unknown, device_val, value