code: def _prepare_app_state_for_checkpoint(
      state: State, unit: AppStateMixin, intra_epoch: bool
  ) -> Dict[str, Stateful]:
      """
      Prepares the application state for checkpointing.
      """
      app_state = _prepare_app_state(unit)
  
      # for intra-epoch checkpointing, include dataloader states
      train_state = none_throws(state.train_state)
      train_dl = train_state.dataloader
      if intra_epoch and isinstance(train_dl, Stateful):
          app_state[_TRAIN_DL_STATE_KEY] = train_dl
  
      return app_state
  
imports: import logging
  import os
  import re
  from typing import Any, Callable, cast, Dict, List, Optional, Pattern, Tuple, TypeVar
  import fsspec
  from pyre_extensions import none_throws
  from torch import distributed
  from torchtnt.framework.callbacks.checkpointer_types import RestoreOptions
  from torchtnt.framework.state import State
  from torchtnt.framework.unit import AppStateMixin
  from torchtnt.utils.distributed import get_global_rank, PGWrapper
  from torchtnt.utils.fsspec import get_filesystem
  from torchtnt.utils.stateful import Stateful
label_desc: Use image node_id 9 for calling a global function with example usage: _prepare_app_state_for_checkpoint(state, unit, intra_epoch) and returns: app_state