code: def _register_hooks(
      module: torch.nn.Module,
      # pyre-ignore: Invalid type parameters [24]
      hooks: List[Tuple[Callable, _HookType]],
  ) -> List[RemovableHandle]:
      """
      Handles recursive hook attachment to module and its submodules, and passes the module name to each hook function.
      """
      removable_handle_list: List[RemovableHandle] = []
      if not isinstance(module, torch.jit.ScriptModule):
          queue: Deque[Tuple[str, torch.nn.Module]] = deque(
              [("", module)]
          )
          while len(queue) > 0:
              module_name, mod = queue.pop()
  
              # register hook
              for hook, hook_type in hooks:
                  if hook_type == _HookType.FORWARD_PRE_HOOK:
                      handle = mod.register_forward_pre_hook(
                          hook(module_name)
                      )
                  elif hook_type == _HookType.FORWARD_HOOK:
                      handle = mod.register_forward_hook(
                          hook(module_name)
                      )
                  elif hook_type == _HookType.BACKWARD_PRE_HOOK:
                      handle = mod.register_full_backward_pre_hook(
                          hook(module_name)
                      )
                  else:
                      handle = mod.register_full_backward_hook(
                          hook(module_name)
                      )
                  removable_handle_list.append(handle)
  
              for name, submodule in mod.named_children():
                  formatted_name = (
                      f"{module_name}.{name}"
                      if module_name != ""
                      else name
                  )
                  queue.append((formatted_name, submodule))
      else:
          warnings.warn(
              "Registering hooks on torch.jit.ScriptModule is not supported."
          )
      return removable_handle_list
  
imports: import copy
  import math
  import warnings
  from collections import defaultdict, deque
  from dataclasses import dataclass, field
  from enum import Enum
  from time import perf_counter
  from typing import Any, Callable, DefaultDict, Deque, Dict, List, MutableMapping, Optional, Tuple, Union
  import torch
  from torch.nn.parameter import UninitializedParameter
  from torch.utils._pytree import PyTree, tree_flatten
  from torch.utils.hooks import RemovableHandle
  from torchtnt.utils.version import is_torch_version_geq_1_13
  from typing_extensions import Literal
label_desc: Use image node_id 15 for calling a global function with example usage: _register_hooks(module, hooks) and returns: removable_handle_list