code: def _prepare_app_state(unit: AppStateMixin) -> Dict[str, Any]:
      """Join together all of the tracked stateful entities to simplify registration of snapshottable states, deals with FSDP case"""
      app_state = unit.app_state()
      tracked_optimizers = (
          unit._construct_tracked_optimizers()
      )  # handles fsdp
      app_state.update(tracked_optimizers)
      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 8 for calling a global function with example usage: _prepare_app_state(unit) and returns: app_state