code: def _convert_leaf_modules_to_stat_tree(leaf_modules):
      assert isinstance(leaf_modules, OrderedDict)
  
      create_index = 1
      root_node = StatNode(name="root", parent=None)
      for name, module_stats in leaf_modules.items():
          names = name.split(".")
          for i in range(len(names)):
              create_index += 1
              stat_node_name = ".".join(names[0 : i + 1])
              parent_node = get_parent_node(root_node, stat_node_name)
              node = StatNode(name=stat_node_name, parent=parent_node)
              parent_node.add_child(node)
              if i == len(names) - 1:  # leaf module itself
                  input_shape = module_stats.input_shape
                  output_shape = module_stats.output_shape
                  node.input_shape = input_shape
                  node.output_shape = output_shape
                  node.parameter_quantity = (
                      module_stats.parameter_quantity
                  )
                  node.inference_memory = module_stats.inference_memory
                  node.MAdd = module_stats.MAdd
                  node.Flops = module_stats.Flops
                  node.duration = module_stats.duration
                  node.Memory = module_stats.Memory
      return StatTree(root_node)
  
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 9 for calling a global function with example usage: _convert_leaf_modules_to_stat_tree(leaf_modules) and returns: StatTree