code: def _stateful_to_state_dict(
      state_dict: STATE_DICT_TYPE,
  ) -> STATE_DICT_TYPE:
      """Creates a shallow copy of `state_dict` where `state_dict` is called for each Stateful object."""
      stateful_state_dict = {}
      for key, elem in state_dict.items():
          stateful_state_dict[key] = (
              elem.state_dict() if isinstance(elem, Stateful) else elem
          )
      return stateful_state_dict
  
file_path: pytorch/torch/distributed/checkpoint/state_dict_saver.py
imports: import warnings
  from concurrent.futures import Future, ThreadPoolExecutor
  from typing import Optional
  import torch
  import torch.distributed
  from torch.distributed._state_dict_utils import _offload_state_dict_to_cpu
  from torch.distributed.checkpoint.stateful import Stateful
  from .default_planner import DefaultSavePlanner
  from .metadata import Metadata, STATE_DICT_TYPE
  from .planner import SavePlanner
  from .storage import StorageWriter
  from .utils import _DistWrapper, _profile
label_desc: Use image node_id 4 for calling a global function with example usage: _stateful_to_state_dict(state_dict) and returns: stateful_state_dict