class_docstr: Feature Hook Helper
  This module helps with the setup and extraction of hooks for extracting features from
  internal nodes in a model by node name. This works quite well in eager Python but needs
  redesign for torcscript.
class_docstr_tok: ["Feature","Hook","Helper","This","module","helps","with","the","setup","and","extraction","of","hooks","for","extracting","features","from","internal","nodes","in","a","model","by","node","name",".","This","works","quite","well","in","eager","Python","but","needs","redesign","for","torcscript","."]
code: def __init__(
      self,
      hooks,
      named_modules,
      out_map=None,
      default_hook_type="forward",
  ):
      # setup feature hooks
      modules = {k: v for k, v in named_modules}
      for i, h in enumerate(hooks):
          hook_name = h["module"]
          m = modules[hook_name]
          hook_id = out_map[i] if out_map else hook_name
          hook_fn = partial(self._collect_output_hook, hook_id)
          hook_type = (
              h["hook_type"] if "hook_type" in h else default_hook_type
          )
          if hook_type == "forward_pre":
              m.register_forward_pre_hook(hook_fn)
          elif hook_type == "forward":
              m.register_forward_hook(hook_fn)
          else:
              assert False, "Unsupported hook type"
      self._feature_outputs = defaultdict(OrderedDict)
  
imports: from collections import OrderedDict, defaultdict
  from copy import deepcopy
  from functools import partial
  from typing import Dict, List, Tuple
  import torch
  import torch.nn
label_desc: Use image node_id 1 to create a new FeatureHooks object  with example: obj = FeatureHooks(hooks, named_modules, out_map, default_hook_type)