code: def _forward_post_hook(
      module_stats: ModuleStats, module: nn.Module, input, output
  ):
      assert not module_stats.done
  
      module_stats.end_time = time.time()
      module_stats.duration = (
          module_stats.end_time - module_stats.start_time
      )
  
      inputs, outputs = _flatten(input), _flatten(output)
      module_stats.input_shape = inputs[0].size()
      module_stats.output_shape = outputs[0].size()
  
      parameter_quantity = 0
      # iterate through parameters and count num params
      for name, p in module.named_parameters():
          parameter_quantity += 0 if p is None else torch.numel(p.data)
      module_stats.parameter_quantity = parameter_quantity
  
      inference_memory = 1
      for oi in outputs:
          for s in oi.size():
              inference_memory *= s
      # memory += parameters_number  # exclude parameter memory
      inference_memory = (
          inference_memory * 4 / (1024**2)
      )  # shown as MB unit
      module_stats.inference_memory = inference_memory
      module_stats.MAdd = compute_madd(module, inputs, outputs)
      module_stats.Flops = compute_flops(module, inputs, outputs)
      module_stats.Memory = compute_memory(module, inputs, outputs)
  
      return output
  
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 7 for calling a global function with example usage: _forward_post_hook(module_stats, module, input, output) and returns: output