{"record":{"id":"103013a4a6c9c0cc","repo":"Lightning-AI/pytorch-lightning","slug":"unsupported-config-type-of-type-hp","errorCode":null,"errorMessage":"Unsupported config type of {type(hp)}.","messagePattern":"Unsupported config type of (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/core/mixins/hparams_mixin.py","lineNumber":163,"sourceCode":"        by base classes.\n\n        Args:\n            ignore_list: Names of hyperparameters to remove.\n\n        \"\"\"\n        for key in ignore_list:\n            self._hparams.pop(key, None)\n\n    @staticmethod\n    def _to_hparams_dict(hp: Union[MutableMapping, Namespace, str]) -> Union[MutableMapping, AttributeDict]:\n        if isinstance(hp, Namespace):\n            hp = vars(hp)\n        if isinstance(hp, dict):\n            hp = AttributeDict(hp)\n        elif isinstance(hp, _PRIMITIVE_TYPES):\n            raise ValueError(f\"Primitives {_PRIMITIVE_TYPES} are not allowed.\")\n        elif not isinstance(hp, _ALLOWED_CONFIG_TYPES):\n            raise ValueError(f\"Unsupported config type of {type(hp)}.\")\n        return hp\n\n    @property\n    def hparams(self) -> Union[AttributeDict, MutableMapping]:\n        \"\"\"The collection of hyperparameters saved with :meth:`save_hyperparameters`. It is mutable by the user. For\n        the frozen set of initial hyperparameters, use :attr:`hparams_initial`.\n\n        Returns:\n            Mutable hyperparameters dictionary\n\n        \"\"\"\n        if not hasattr(self, \"_hparams\"):\n            self._hparams = AttributeDict()\n        return self._hparams\n\n    @property\n    def hparams_initial(self) -> AttributeDict:\n        \"\"\"The collection of hyperparameters saved with :meth:`save_hyperparameters`. These contents are read-only.","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/core/mixins/hparams_mixin.py#L145-L181","documentation":"_to_hparams_dict rejects config objects whose type is neither a dict/MutableMapping, argparse.Namespace, nor one of _ALLOWED_CONFIG_TYPES. The hparams mechanism serializes key-value structures, so arbitrary Python objects cannot be stored as hparams.","triggerScenarios":"Calling save_hyperparameters or _set_hparams with e.g. a custom class instance, a list, or a tuple that is not in _ALLOWED_CONFIG_TYPES.","commonSituations":"User passed a hydra/omegaconf object of an unsupported version, a pathlib.Path, a list of args, or a custom ConfigClass to save_hyperparameters.","solutions":["Convert the object to a plain dict first (e.g. dict(config), OmegaConf.to_container(cfg))","Use keyword arguments: save_hyperparameters(lr=1e-3, batch_size=32)","For argparse, pass the Namespace directly"],"exampleFix":"# before\nself.save_hyperparameters(my_custom_config_obj)\n\n# after\nself.save_hyperparameters(dict(my_custom_config_obj))","handlingStrategy":"type-guard","validationCode":"if not isinstance(hp, (dict, MutableMapping, Namespace)):\n    hp = dict(hp) if hasattr(hp, 'keys') else {'value': hp}","typeGuard":"def is_supported_config(obj) -> bool:\n    return isinstance(obj, (dict, MutableMapping, Namespace)) or type(obj).__name__ in ('DictConfig', 'ListConfig', 'AttributeDict')","tryCatchPattern":"try:\n    self.save_hyperparameters(cfg)\nexcept ValueError as e:\n    if 'Unsupported config type' in str(e):\n        from omegaconf import OmegaConf\n        self.save_hyperparameters(OmegaConf.to_container(cfg))\n    else:\n        raise","preventionTips":["Normalize configs to plain dicts at the entry point of your scripts","Pin supported config library versions (omegaconf compatibility) in requirements"],"tags":["pytorch-lightning","hparams","save-hyperparameters","type-validation","unsupported-type"],"backgroundTag":"hyperparameter-config-invalid","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}