code: def _init_device_handle(
      state: _FSDPState,
      module: nn.Module,
      ignored_params: Set[nn.Parameter],
      device_id: Optional[Union[int, torch.device]],
  ) -> _FSDPState:
      """
      Determine device handle used for initializing FSDP.
  
      If a device is specified by ``device_id``,
      then returns device handle corresponds to that device type. Otherwise, If the
      module is already on a non-CPU device, then the device type is that non-CPU device type.
      If the module is on CPU or meta, then the device type is the current cuda device.
  
      This method will be called once ignored paramters was determined, as the device handle maybe needed
      for other initialization.
      """
      determined_device = None
      if device_id is not None:
          determined_device = (
              device_id
              if isinstance(device_id, torch.device)
              else torch.device(device_id)
          )
      if determined_device is None:
          for param in _get_orig_params(module, ignored_params):
              if param.device.type in {"cpu", "meta"}:
                  continue
              if determined_device is None:
                  determined_device = param.device
              else:
                  if param.device.type != determined_device.type:
                      raise RuntimeError(
                          f"FSDP does not support modules with different device types "
                          f"but got params on {determined_device.type} and {param.device.type}"
                      )
          determined_device = determined_device or torch.device(
              "cuda", torch.cuda.current_device()
          )
  
      state._device_handle = _FSDPDeviceHandle.from_device(
          determined_device
      )
      return state
  
imports: import collections
  import itertools
  import os
  import warnings
  from typing import Any, Callable, Deque, Dict, Generator, Iterable, Iterator, List, no_type_check, Optional, Set, Tuple, Union
  import torch
  import torch.distributed
  import torch.distributed.fsdp._exec_order_utils
  import torch.distributed.fsdp._traversal_utils
  import torch.distributed.fsdp.fully_sharded_data_parallel
  import torch.nn
  from torch.distributed.algorithms._comm_hooks import default_hooks
  from torch.distributed.device_mesh import _mesh_resources, DeviceMesh
  from torch.distributed.distributed_c10d import _get_default_group
  from torch.distributed.fsdp._common_utils import _FSDPDeviceHandle, _FSDPState, _get_module_fsdp_state, _is_fsdp_flattened, _named_parameters_with_duplicates, clean_tensor_name, TrainingState
  from torch.distributed.fsdp._flat_param import _FSDP_USE_FULL_PREC_IN_EVAL, FlatParameter, FlatParamHandle, HandleShardingStrategy
  from torch.distributed.fsdp._limiter_utils import _FreeEventQueue
  from torch.distributed.fsdp.api import BackwardPrefetch, CPUOffload, FullOptimStateDictConfig, FullStateDictConfig, MixedPrecision, ShardingStrategy, StateDictConfig, StateDictType
  from torch.distributed.fsdp.wrap import _Policy
  from torch.distributed.tensor.parallel.fsdp import DTensorExtensions
  from torch.distributed.utils import _sync_params_and_buffers
  from torch.utils._python_dispatch import is_traceable_wrapper_subclass
  from torch.utils.hooks import RemovableHandle
label_desc: Use image node_id 10 for calling a global function with example usage: _init_device_handle(state, module, ignored_params, device_id) and returns: state