code: def _register_hooks(
      name: str, module: nn.Module, pre_hooks, post_hooks, stats
  ):
      assert (
          isinstance(module, nn.Module)
          and len(list(module.children())) == 0
      )
  
      if name in stats:
          return
  
      module_stats = ModuleStats(name)
      stats[name] = module_stats
  
      post_hook = module.register_forward_hook(
          functools.partial(_forward_post_hook, module_stats)
      )
      post_hooks.append(post_hook)
  
      pre_hook = module.register_forward_pre_hook(
          functools.partial(_forward_pre_hook, module_stats)
      )
      pre_hooks.append(pre_hook)
  
imports: import time
  from collections import OrderedDict
  from typing import Dict, Sequence
  import functools
  import itertools
  import numpy
  import torch
  import torch.nn
  from .compute_madd import compute_madd
  from .compute_flops import compute_flops
  from .compute_memory import compute_memory
  from .stat_tree import StatTree, StatNode
  from .reporter import report_format
label_desc: Use image node_id 4 for calling a global function with example usage: _register_hooks(name, module, pre_hooks, post_hooks, stats) without return types