code: def _call_teardown_hook(trainer: "pl.Trainer") -> None:
      assert trainer.state.fn is not None
      fn = trainer.state.fn
  
      if trainer.datamodule is not None:
          _call_lightning_datamodule_hook(trainer, "teardown", stage=fn)
  
      _call_callback_hooks(trainer, "teardown", stage=fn)
      _call_lightning_module_hook(trainer, "teardown", stage=fn)
  
      trainer.lightning_module._current_fx_name = None
      # these could have become stale if metrics are defined in `setup`
      trainer.lightning_module._metric_attributes = None
  
      # todo: TPU 8 cores hangs in flush with TensorBoard. Might do for all loggers.
      # It might be related to xla tensors blocked when moving the cpu kill loggers.
      for logger in trainer.loggers:
          logger.finalize("success")
  
      # summarize profile results
      trainer.profiler.describe()
  
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 4 for calling a global function with example usage: _call_teardown_hook(trainer) without return types