{"record":{"id":"4ea1d0a7a09aee53","repo":"huggingface/transformers","slug":"multiple-valid-text-configs-were-found-in-the-mode","errorCode":null,"errorMessage":"Multiple valid text configs were found in the model config: {valid_text_config_names}. In this case, using `get_text_config()` would be ambiguous. Please specify the desired text config directly, e.g. `text_config = config.sub_config_name`","messagePattern":"Multiple valid text configs were found in the model config: (.+?)\\. In this case, using `get_text_config\\(\\)` would be ambiguous\\. Please specify the desired text config directly, e\\.g\\. `text_config = config\\.sub_config_name`","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/configuration_utils.py","lineNumber":1339,"sourceCode":"\n        decoder_possible_text_config_names = (\"decoder\", \"generator\", \"text_config\")\n        encoder_possible_text_config_names = (\"text_encoder\",)\n        if return_both:\n            possible_text_config_names = encoder_possible_text_config_names + decoder_possible_text_config_names\n        elif decoder:\n            possible_text_config_names = decoder_possible_text_config_names\n        else:\n            possible_text_config_names = encoder_possible_text_config_names\n\n        valid_text_config_names = []\n        for text_config_name in possible_text_config_names:\n            if hasattr(self, text_config_name):\n                text_config = getattr(self, text_config_name, None)\n                if text_config is not None:\n                    valid_text_config_names += [text_config_name]\n\n        if len(valid_text_config_names) > 1:\n            raise ValueError(\n                f\"Multiple valid text configs were found in the model config: {valid_text_config_names}. In this \"\n                \"case, using `get_text_config()` would be ambiguous. Please specify the desired text config directly, \"\n                \"e.g. `text_config = config.sub_config_name`\"\n            )\n        elif len(valid_text_config_names) == 1:\n            config_to_return = getattr(self, valid_text_config_names[0])\n        else:\n            config_to_return = self\n\n        # handle legacy models with flat config structure, when we only want one of the configs\n        if not return_both and len(valid_text_config_names) == 0 and config_to_return.is_encoder_decoder:\n            config_to_return = copy.deepcopy(config_to_return)\n            prefix_to_keep = \"decoder\" if decoder else \"encoder\"\n            for key in config_to_return.to_dict():\n                # NOTE: We can't discard keys because:\n                # 1) we can't truly delete a cls attribute on a dataclass; 2) we can't set the value to `None` due to\n                # strict validation. So we just keep it as is, since there are only a couple old models falling in this condition\n                if key.startswith(prefix_to_keep):","sourceCodeStart":1321,"sourceCodeEnd":1357,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/configuration_utils.py#L1321-L1357","documentation":"ValueError from PreTrainedConfig.get_text_config when more than one candidate text-config attribute is present and non-None on the config (checked against encoder/decoder possible text config name lists). With several valid sub-configs, returning 'the' text config would be ambiguous, so the method refuses to choose.","triggerScenarios":"A composite config that defines both e.g. text_config and decoder_config (or several of the known aliases) with non-None values, then calling config.get_text_config() or model.generate() which calls it internally.","commonSituations":"Vision-language or encoder-decoder configs that evolved: older checkpoints carry both legacy (decoder_config) and new (text_config) attributes; custom model configs that accidentally define multiple alias attributes.","solutions":["Access the desired sub-config directly: text_config = config.text_config.","Delete or set to None the redundant legacy attribute (e.g. del config.decoder_config) before calling get_text_config.","When defining a new composite config, expose exactly one text-config attribute from the recognized name list."],"exampleFix":"// before\nconfig.text_config = ClvpTextConfig(...)\nconfig.decoder_config = ClvpDecoderConfig(...)  # both non-None\ntext = config.get_text_config()  # ValueError\n\n// after\ndel config.decoder_config\ntext = config.get_text_config()","handlingStrategy":"validation","validationCode":"from transformers.configuration_utils import PreTrainedConfig\ncandidates = [n for n in (\"text_config\", \"decoder_config\", \"encoder_config\", \"second_decoder_config\")\n              if getattr(config, n, None) is not None]\nif len(candidates) > 1:\n    raise ValueError(f\"ambiguous text config: {candidates}; pick explicitly\")","typeGuard":"def text_config_is_unambiguous(config) -> bool:\n    names = [n for n in dir(config) if n.endswith(\"_config\")]\n    return sum(getattr(config, n, None) is not None for n in names) <= 1","tryCatchPattern":"try:\n    text = config.get_text_config()\nexcept ValueError as e:\n    if \"Multiple valid text configs\" in str(e):\n        text = config.text_config  # pick explicitly","preventionTips":["Define exactly one text-config attribute per composite config; keep legacy aliases as None.","In shared library code, access the sub-config by name rather than get_text_config() when multiple may exist."],"tags":["config","text-config","multi-modal","ambiguity"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}