code: def _forward_time_hook(
      timer_mapping: Dict[str, float],
      elapsed_times: Dict[str, float],
      # pyre-ignore: Invalid type parameters [24]
  ) -> Callable[[str], Callable]:
      # pyre-ignore: Missing parameter annotation [2]
      def intermediate_hook(
          module_name: str,
      ) -> Callable[[torch.nn.Module, Any, Any], None]:
          def hook(
              _module: torch.nn.Module, _inp: Any, _out: Any
          ) -> None:
              if torch.cuda.is_available():
                  torch.cuda.synchronize()
              elapsed_times[module_name] = (
                  perf_counter() - timer_mapping[module_name]
              )
  
          return hook
  
      return intermediate_hook
  
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 14 for calling a global function with example usage: _forward_time_hook(timer_mapping, elapsed_times) and returns: intermediate_hook, hook