code: def _set_optim_use_dtensor(
      fsdp_state: _FSDPState,
      state_dict_settings: StateDictSettings,
  ) -> None:
      # If device_mesh is passed in when initalizing FSDP, we automatically turn the
      # _use_dtensor flag to be true for ShardedOptimStateDictConfig() if state_dict_type
      # has to be set to SHARDED_STATE_DICT.
      if getattr(fsdp_state, "_device_mesh", None):
          state_dict_type = state_dict_settings.state_dict_type
          if state_dict_type == StateDictType.LOCAL_STATE_DICT:
              raise RuntimeError(
                  "Found state_dict_type LOCAL_STATE_DICT.",
                  "DeviceMesh is not compatible with LOCAL_STATE_DICT.",
                  "Please set state_dict_type to SHARDED_STATE_DICT to get DTensor state_dict.",
              )
          elif state_dict_type == StateDictType.FULL_STATE_DICT:
              logger.warning(
                  "Found both state_dict_type FULL_STATE_DICT and device_mesh. "  # noqa: G004
                  "Please set state_dict_type to SHARDED_STATE_DICT to get DTensor state_dict."
              )
          else:
              state_dict_settings.optim_state_dict_config._use_dtensor = (
                  True
              )
  
imports: import copy
  import functools
  import logging
  import warnings
  from contextlib import ExitStack
  from dataclasses import dataclass, field
  from typing import Any, cast, Dict, Iterable, Iterator, List, NamedTuple, no_type_check, Optional, Sequence, Set, Tuple, Union
  import torch
  import torch.distributed
  import torch.distributed.fsdp._traversal_utils
  import torch.nn
  from torch.distributed._shard.sharded_tensor import ShardedTensor
  from torch.distributed._state_dict_utils import _gather_state_dict
  from torch.distributed._tensor import DTensor, Replicate
  from torch.distributed.distributed_c10d import _get_pg_default_device
  from torch.distributed.fsdp._common_utils import _apply_to_modules, _FSDPState, _get_module_fsdp_state_if_fully_sharded_module, _get_param_to_fqns, _module_handle, _named_parameters_with_duplicates, clean_tensor_name
  from torch.distributed.fsdp._debug_utils import SimpleProfiler
  from torch.distributed.fsdp._flat_param import FlatParameter, FlatParamHandle
  from torch.distributed.fsdp._fsdp_extensions import _ext_chunk_dtensor, _ext_chunk_tensor
  from torch.distributed.fsdp._runtime_utils import _lazy_init, _reset_flat_param_grad_info_if_needed
  from torch.distributed.fsdp.api import ShardingStrategy, StateDictSettings, StateDictType
  from torch.utils._pytree import tree_map_only
label_desc: Use image node_id 33 for calling a global function with example usage: _set_optim_use_dtensor(fsdp_state, state_dict_settings) without return types