code: def _to_hparams_dict(
      hp: Union[MutableMapping, Namespace, str]
  ) -> Union[MutableMapping, AttributeDict]:
      if isinstance(hp, Namespace):
          hp = vars(hp)
      if isinstance(hp, dict):
          hp = AttributeDict(hp)
      elif isinstance(hp, _PRIMITIVE_TYPES):
          raise ValueError(
              f"Primitives {_PRIMITIVE_TYPES} are not allowed."
          )
      elif not isinstance(hp, _ALLOWED_CONFIG_TYPES):
          raise ValueError(f"Unsupported config type of {type(hp)}.")
      return hp
  
file_path: pytorch-lightning/src/lightning/pytorch/core/mixins/hparams_mixin.py
imports: import copy
  import inspect
  import types
  from argparse import Namespace
  from typing import Any, List, MutableMapping, Optional, Sequence, Union
  from lightning.fabric.utilities.data import AttributeDict
  from lightning.pytorch.utilities.parsing import save_hyperparameters
label_desc: Use image node_id 4 for calling the HyperparametersMixin obj's underlying member method code with example usage: obj._to_hparams_dict(hp) and returns: hp