code: def _get_implemented_callback_mapping(
      callbacks: List[Callback],
  ) -> Dict[str, List[Callback]]:
      """
      Processes a list of callbacks and returns a dictionary mapping each hook
      to a list of Callback classes that implement that method.
  
      Since the base Callback class is a no-op for each of these methods, if the code is different between
      the callback instance passed in and the base class, there is logic to run.
  
      This upfront processing is useful to avoid timing and profiling overheads, especially those done each step
      in the corresponding training, evaluation or prediction loop.
  
      Within each hook, the original ordering from the Callback list is preserved.
      """
      callback_hooks = (
          "on_exception",
          "on_train_start",
          "on_train_epoch_start",
          "on_train_get_next_batch_end",
          "on_train_step_start",
          "on_train_step_end",
          "on_train_epoch_end",
          "on_train_end",
          "on_eval_start",
          "on_eval_epoch_start",
          "on_eval_get_next_batch_end",
          "on_eval_step_start",
          "on_eval_step_end",
          "on_eval_epoch_end",
          "on_eval_end",
          "on_predict_start",
          "on_predict_epoch_start",
          "on_predict_get_next_batch_end",
          "on_predict_step_start",
          "on_predict_step_end",
          "on_predict_epoch_end",
          "on_predict_end",
      )
      cb_overrides: Dict[str, List[Callback]] = {}
      for hook in callback_hooks:
          for cb in callbacks:
              if _has_method_override(hook, cb, Callback):
                  if hook not in cb_overrides:
                      cb_overrides[hook] = [cb]
                  else:
                      cb_overrides[hook].append(cb)
      return cb_overrides
  
imports: import logging
  from functools import partial
  from typing import Dict, List, Type, Union
  from unittest.mock import Mock
  from torchtnt.framework.callback import Callback
  from torchtnt.framework.state import State
  from torchtnt.framework.unit import TEvalUnit, TPredictUnit, TTrainUnit
label_desc: Use image node_id 2 for calling a global function with example usage: _get_implemented_callback_mapping(callbacks) and returns: cb_overrides