code: def _verify_state_dict(
      model_state_dict: Dict[str, ValueType],
      optim_state_dict: OptimizerStateType,
      info: _StateDictInfo,
  ) -> None:
      # FSDP root must exist otherwise FSDP state_dict will be incorrect.
      has_fsdp_root = False
      for module in info.fsdp_modules:
          fsdp_state = _get_module_fsdp_state_if_fully_sharded_module(
              module
          )
          assert (
              fsdp_state is not None
          ), "Expected a fsdp_state with a fsdp module."
          if fsdp_state._is_root:
              has_fsdp_root = True
              break
      if info.fsdp_modules and not has_fsdp_root:
          raise RuntimeError(
              "The model has FSDP modules but no FSDP root module exists."
          )
  
      # Verify if the model_state_dict and optim_state_dict are valid. This API
      # should give the users an explicit error message to debug or report.
      if (
          info.handle_model
          and not model_state_dict
          and not info.submodule_prefixes
          and not info.ignore_frozen_params
          and not (info.cpu_offload and info.full_state_dict)
          and info.strict
      ):
          raise RuntimeError(
              "The option indicates that model state_dict is required to save "
              "or load, but model state_dict is empty."
              f"rank = {dist.get_rank()=}."
          )
  
      if info.handle_optim:
          if not (
              optim_state_dict and optim_state_dict[STATE]
          ) and not (info.cpu_offload and info.full_state_dict):
              raise RuntimeError(
                  "The option indicates that model state_dict is required to save, "
                  f"or load but optim state_dict is empty. {optim_state_dict}"
              )
  
      for key in model_state_dict.keys():
          if FLAT_PARAM in key:
              raise RuntimeError(
                  f"{key} contains {FLAT_PARAM}. This can happen if the model "
                  "is not the root module."
              )
  
imports: import contextlib
  import functools
  import gc
  from dataclasses import asdict, dataclass, field
  from itertools import chain
  from typing import Any, Callable, cast, Dict, Iterable, List, no_type_check, Optional, Set, Tuple, Union
  import torch
  import torch.distributed
  import torch.nn
  from torch.distributed._shard.sharded_tensor import ShardedTensor
  from torch.distributed._state_dict_utils import _gather_state_dict, _offload_state_dict_to_cpu
  from torch.distributed._tensor import DTensor
  from torch.distributed.fsdp import FullOptimStateDictConfig, FullStateDictConfig, FullyShardedDataParallel, OptimStateDictConfig, ShardedOptimStateDictConfig, ShardedStateDictConfig, StateDictConfig, StateDictType
  from torch.distributed.fsdp._common_utils import _get_module_fsdp_state_if_fully_sharded_module, FSDP_WRAPPED_MODULE
  from torch.nn.modules.module import _IncompatibleKeys
  from torch.nn.parallel import DistributedDataParallel
label_desc: Use image node_id 4 for calling a global function with example usage: _verify_state_dict(model_state_dict, optim_state_dict, info) without return types