huggingface/transformers · error · ValueError

Multiple valid text configs were found in the model config:

Error message

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`

What it means

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.

Source

Thrown at src/transformers/configuration_utils.py:1339

        decoder_possible_text_config_names = ("decoder", "generator", "text_config")
        encoder_possible_text_config_names = ("text_encoder",)
        if return_both:
            possible_text_config_names = encoder_possible_text_config_names + decoder_possible_text_config_names
        elif decoder:
            possible_text_config_names = decoder_possible_text_config_names
        else:
            possible_text_config_names = encoder_possible_text_config_names

        valid_text_config_names = []
        for text_config_name in possible_text_config_names:
            if hasattr(self, text_config_name):
                text_config = getattr(self, text_config_name, None)
                if text_config is not None:
                    valid_text_config_names += [text_config_name]

        if len(valid_text_config_names) > 1:
            raise ValueError(
                f"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`"
            )
        elif len(valid_text_config_names) == 1:
            config_to_return = getattr(self, valid_text_config_names[0])
        else:
            config_to_return = self

        # handle legacy models with flat config structure, when we only want one of the configs
        if not return_both and len(valid_text_config_names) == 0 and config_to_return.is_encoder_decoder:
            config_to_return = copy.deepcopy(config_to_return)
            prefix_to_keep = "decoder" if decoder else "encoder"
            for key in config_to_return.to_dict():
                # NOTE: We can't discard keys because:
                # 1) we can't truly delete a cls attribute on a dataclass; 2) we can't set the value to `None` due to
                # strict validation. So we just keep it as is, since there are only a couple old models falling in this condition
                if key.startswith(prefix_to_keep):

View on GitHub (pinned to a597f97485)

Solutions

  1. Access the desired sub-config directly: text_config = config.text_config.
  2. Delete or set to None the redundant legacy attribute (e.g. del config.decoder_config) before calling get_text_config.
  3. When defining a new composite config, expose exactly one text-config attribute from the recognized name list.

Example fix

// before
config.text_config = ClvpTextConfig(...)
config.decoder_config = ClvpDecoderConfig(...)  # both non-None
text = config.get_text_config()  # ValueError

// after
del config.decoder_config
text = config.get_text_config()
Defensive patterns

Strategy: validation

Validate before calling

from transformers.configuration_utils import PreTrainedConfig
candidates = [n for n in ("text_config", "decoder_config", "encoder_config", "second_decoder_config")
              if getattr(config, n, None) is not None]
if len(candidates) > 1:
    raise ValueError(f"ambiguous text config: {candidates}; pick explicitly")

Type guard

def text_config_is_unambiguous(config) -> bool:
    names = [n for n in dir(config) if n.endswith("_config")]
    return sum(getattr(config, n, None) is not None for n in names) <= 1

Try / catch

try:
    text = config.get_text_config()
except ValueError as e:
    if "Multiple valid text configs" in str(e):
        text = config.text_config  # pick explicitly

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/4ea1d0a7a09aee53. Report an issue: GitHub.