code: def _call_callback_hooks(
      trainer: "pl.Trainer",
      hook_name: str,
      *args: Any,
      monitoring_callbacks: Optional[bool] = None,
      **kwargs: Any,
  ) -> None:
      log.debug(
          f"{trainer.__class__.__name__}: calling callback hook: {hook_name}"
      )
  
      pl_module = trainer.lightning_module
      if pl_module:
          prev_fx_name = pl_module._current_fx_name
          pl_module._current_fx_name = hook_name
  
      callbacks = trainer.callbacks
      if monitoring_callbacks is True:
          # the list of "monitoring callbacks" is hard-coded to these two. we could add an API to define this
          callbacks = [
              cb
              for cb in callbacks
              if isinstance(cb, (EarlyStopping, Checkpoint))
          ]
      elif monitoring_callbacks is False:
          callbacks = [
              cb
              for cb in callbacks
              if not isinstance(cb, (EarlyStopping, Checkpoint))
          ]
  
      for callback in callbacks:
          fn = getattr(callback, hook_name)
          if callable(fn):
              with trainer.profiler.profile(
                  f"[Callback]{callback.state_key}.{hook_name}"
              ):
                  fn(trainer, trainer.lightning_module, *args, **kwargs)
  
      if pl_module:
          # restore current_fx when nested context
          pl_module._current_fx_name = prev_fx_name
  
imports: import logging
  from copy import deepcopy
  from typing import Any, Callable, Dict, Optional, Type, Union
  from packaging.version import Version
  import lightning.pytorch
  from lightning.fabric.utilities.device_dtype_mixin import _DeviceDtypeModuleMixin
  from lightning.pytorch.callbacks import Checkpoint, EarlyStopping
  from lightning.pytorch.trainer.states import TrainerStatus
  from lightning.pytorch.utilities.exceptions import _TunerExitException
  from lightning.pytorch.utilities.model_helpers import is_overridden
  from lightning.pytorch.utilities.rank_zero import rank_zero_warn
label_desc: Use image node_id 7 for calling a global function with example usage: _call_callback_hooks(trainer, hook_name) without return types