code: def _extract_device(
      module: Module,
      hook_inputs: Union[None, Tensor, Tuple[Tensor, ...]],
      hook_outputs: Union[None, Tensor, Tuple[Tensor, ...]],
  ) -> device:
      params = list(module.parameters())
      if (
          (hook_inputs is None or len(hook_inputs) == 0)
          and (hook_outputs is None or len(hook_outputs) == 0)
          and len(params) == 0
      ):
          raise RuntimeError(
              """Unable to extract device information for the module
              {}. Both inputs and outputs to the forward hook and
              `module.parameters()` are empty.
              The reason that the inputs to the forward hook are empty
              could be due to the fact that the arguments to that
              module {} are all named and are passed as named
              variables to its forward function.
              """.format(
                  module, module
              )
          )
      if hook_inputs is not None and len(hook_inputs) > 0:
          return hook_inputs[0].device
      if hook_outputs is not None and len(hook_outputs) > 0:
          return hook_outputs[0].device
  
      return params[0].device
  
imports: import typing
  from enum import Enum
  from functools import reduce
  from inspect import signature
  from typing import Any, Callable, cast, Dict, List, overload, Tuple, Union
  import numpy
  import torch
  from captum._utils.typing import BaselineType, Literal, TargetType, TensorOrTupleOfTensorsGeneric, TupleOrTensorOrBoolGeneric
  from torch import device, Tensor
  from torch.nn import Module
label_desc: Use image node_id 41 for calling a global function with example usage: _extract_device(module, hook_inputs, hook_outputs) and returns: params, hook_inputs, hook_outputs