docstr: Creating a model checkpoint dictionary object from various component states.
  
  Args:
      weights_only: saving model weights only
  Return:
      structured dictionary: {
          'epoch':                     training epoch
          'global_step':               training global step
          'pytorch-lightning_version': The version of PyTorch Lightning that produced this checkpoint
          'callbacks':                 "callback specific state"[] # if not weights_only
          'optimizer_states':          "PT optim's state_dict"[]   # if not weights_only
          'lr_schedulers':             "PT sched's state_dict"[]   # if not weights_only
          'state_dict':                Model's state_dict (e.g. network weights)
          precision_plugin.__class__.__qualname__:  precision plugin state_dict # if not weights_only
          CHECKPOINT_HYPER_PARAMS_NAME:
          CHECKPOINT_HYPER_PARAMS_KEY:
          CHECKPOINT_HYPER_PARAMS_TYPE:
          something_cool_i_want_to_save: anything you define through model.on_save_checkpoint
          LightningDataModule.__class__.__qualname__: pl DataModule's state
      }
docstr_tok: ["Creating","a","model","checkpoint","dictionary","object","from","various","component","states",".","Args",":","weights_only",":","saving","model","weights","only","Return",":","structured","dictionary",":","{","'epoch","'",":","training","epoch","'global_step","'",":","training","global","step","'pytorch-lightning_version","'",":","The","version","of","PyTorch","Lightning","that","produced","this","checkpoint","'callbacks","'",":","``","callback","specific","state","''","[","]","#","if","not","weights_only","'optimizer_states","'",":","``","PT","optim","'s","state_dict","''","[","]","#","if","not","weights_only","'lr_schedulers","'",":","``","PT","sched","'s","state_dict","''","[","]","#","if","not","weights_only","'state_dict","'",":","Model","'s","state_dict","(","e.g",".","network","weights",")","precision_plugin.__class__.__qualname__",":","precision","plugin","state_dict","#","if","not","weights_only","CHECKPOINT_HYPER_PARAMS_NAME",":","CHECKPOINT_HYPER_PARAMS_KEY",":","CHECKPOINT_HYPER_PARAMS_TYPE",":","something_cool_i_want_to_save",":","anything","you","define","through","model.on_save_checkpoint","LightningDataModule.__class__.__qualname__",":","pl","DataModule","'s","state","}"]
code: def dump_checkpoint(self, weights_only: bool = False) -> dict:
      """Creating a model checkpoint dictionary object from various component states.
  
      Args:
          weights_only: saving model weights only
      Return:
          structured dictionary: {
              'epoch':                     training epoch
              'global_step':               training global step
              'pytorch-lightning_version': The version of PyTorch Lightning that produced this checkpoint
              'callbacks':                 "callback specific state"[] # if not weights_only
              'optimizer_states':          "PT optim's state_dict"[]   # if not weights_only
              'lr_schedulers':             "PT sched's state_dict"[]   # if not weights_only
              'state_dict':                Model's state_dict (e.g. network weights)
              precision_plugin.__class__.__qualname__:  precision plugin state_dict # if not weights_only
              CHECKPOINT_HYPER_PARAMS_NAME:
              CHECKPOINT_HYPER_PARAMS_KEY:
              CHECKPOINT_HYPER_PARAMS_TYPE:
              something_cool_i_want_to_save: anything you define through model.on_save_checkpoint
              LightningDataModule.__class__.__qualname__: pl DataModule's state
          }
  
      """
      trainer = self.trainer
      model = trainer.lightning_module
      datamodule = trainer.datamodule
  
      checkpoint = {
          # the epoch and global step are saved for compatibility but they are not relevant for restoration
          "epoch": trainer.current_epoch,
          "global_step": trainer.global_step,
          "pytorch-lightning_version": pl.__version__,
          "state_dict": self._get_lightning_module_state_dict(),
          "loops": self._get_loops_state_dict(),
      }
  
      if not weights_only:
          # dump callbacks
          checkpoint["callbacks"] = call._call_callbacks_state_dict(
              trainer
          )
  
          optimizer_states = []
          for i, optimizer in enumerate(trainer.optimizers):
              # Rely on accelerator to dump optimizer state
              optimizer_state = trainer.strategy.optimizer_state(
                  optimizer
              )
              optimizer_states.append(optimizer_state)
  
          checkpoint["optimizer_states"] = optimizer_states
  
          # dump lr schedulers
          lr_schedulers = []
          for config in trainer.lr_scheduler_configs:
              lr_schedulers.append(config.scheduler.state_dict())
          checkpoint["lr_schedulers"] = lr_schedulers
  
          # precision plugin
          prec_plugin = trainer.precision_plugin
          prec_plugin_state_dict = prec_plugin.state_dict()
          if prec_plugin_state_dict:
              checkpoint[
                  prec_plugin.__class__.__qualname__
              ] = prec_plugin_state_dict
          prec_plugin.on_save_checkpoint(checkpoint)
  
      if _OMEGACONF_AVAILABLE:
          from omegaconf import Container
  
      # dump hyper-parameters
      for obj in (model, datamodule):
          if obj and obj.hparams:
              if hasattr(obj, "_hparams_name"):
                  checkpoint[
                      obj.CHECKPOINT_HYPER_PARAMS_NAME
                  ] = obj._hparams_name
              # dump arguments
              if _OMEGACONF_AVAILABLE and isinstance(
                  obj.hparams, Container
              ):
                  checkpoint[
                      obj.CHECKPOINT_HYPER_PARAMS_KEY
                  ] = obj.hparams
                  checkpoint[obj.CHECKPOINT_HYPER_PARAMS_TYPE] = type(
                      obj.hparams
                  )
              else:
                  checkpoint[obj.CHECKPOINT_HYPER_PARAMS_KEY] = dict(
                      obj.hparams
                  )
  
      # dump stateful datamodule
      if datamodule is not None:
          datamodule_state_dict = call._call_lightning_datamodule_hook(
              trainer, "state_dict"
          )
          if datamodule_state_dict:
              checkpoint[
                  datamodule.__class__.__qualname__
              ] = datamodule_state_dict
  
      # on_save_checkpoint hooks
      if not weights_only:
          # if state is returned from callback's on_save_checkpoint
          # it overrides the returned state from callback's state_dict
          # support for returning state in on_save_checkpoint
          # will be removed in v1.8
          call._call_callbacks_on_save_checkpoint(trainer, checkpoint)
      call._call_lightning_module_hook(
          trainer, "on_save_checkpoint", checkpoint
      )
      return checkpoint
  
imports: import logging
  import os
  import re
  from typing import Any, Dict, Optional
  import torch
  from fsspec.core import url_to_fs
  from fsspec.implementations.local import LocalFileSystem
  from torch import Tensor
  import lightning.pytorch
  from lightning.fabric.plugins.environments.slurm import SLURMEnvironment
  from lightning.fabric.utilities.cloud_io import _is_dir, get_filesystem
  from lightning.fabric.utilities.types import _PATH
  from lightning.pytorch.callbacks import ModelCheckpoint
  from lightning.pytorch.plugins.precision import MixedPrecision
  from lightning.pytorch.trainer import call
  from lightning.pytorch.trainer.states import TrainerFn
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from lightning.pytorch.utilities.imports import _OMEGACONF_AVAILABLE
  from lightning.pytorch.utilities.migration import pl_legacy_patch
  from lightning.pytorch.utilities.migration.utils import _pl_migrate_checkpoint
  from lightning.pytorch.utilities.rank_zero import rank_zero_info, rank_zero_warn
label_desc: Use image node_id 18 for calling the _CheckpointConnector obj's underlying member method code with example usage: obj.dump_checkpoint(weights_only) and returns: checkpoint