huggingface/transformers · error · ValueError

key isn't in the original config dict

Error message

key {k} isn't in the original config dict

What it means

ValueError from PreTrainedConfig.update_from_string: the CLI-style update string contains a key that does not already exist as an attribute on the config object. update_from_str only mutates existing attributes; it never creates new ones.

Solutions

  1. Check hasattr(config, key) for the failing key and fix the typo or use the correct attribute name.
  2. For nested configs, target the sub-config: config.text_config.update_from_string(...).
  3. If you truly need a new attribute, set it directly (config.my_key = value) instead of via update_from_string.

Example fix

// before
config.update_from_string("n_embdd=10")  # ValueError

// after
config.update_from_string("n_embd=10")
Defensive patterns

Strategy: validation

Validate before calling

updates = {"n_embd": "10", "scale_attn_weights": "false"}
missing = [k for k in updates if not hasattr(config, k)]
if missing:
    raise KeyError(f"Unknown config keys: {missing}")
config.update_from_string(",".join(f"{k}={v}" for k, v in updates.items()))

Type guard

def can_update(config, key: str) -> bool:
    return hasattr(config, key)

Try / catch

try:
    config.update_from_string(s)
except ValueError as e:
    if "isn't in the original config dict" in str(e):
        raise KeyError(f"bad update string {s!r}: {e}")

Prevention

When it happens

Trigger: config.update_from_string("n_embdd=10") (typo), or updating a key that belongs to a different model family's config (e.g. num_attention_heads on a config class that does not define it, or a parameter only present on the nested text_config).

Common situations: Scripts that build the update string dynamically from a dict of hyperparameters; copy-pasting example strings from a different model's docs; trying to set sub-config attributes at the top level of a composite (vision-language) config.

Related errors


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

Appendix: source

Thrown at src/transformers/configuration_utils.py:1187

    def update_from_string(self, update_str: str):
        """
        Updates attributes of this class with attributes from `update_str`.

        The expected format is ints, floats and strings as is, and for booleans use `true` or `false`. For example:
        "n_embd=10,resid_pdrop=0.2,scale_attn_weights=false,summary_type=cls_index"

        The keys to change have to already exist in the config object.

        Args:
            update_str (`str`): String with attributes that should be updated for this class.

        """

        d = dict(x.split("=") for x in update_str.split(","))
        for k, v in d.items():
            if not hasattr(self, k):
                raise ValueError(f"key {k} isn't in the original config dict")

            old_v = getattr(self, k)
            if isinstance(old_v, bool):
                if v.lower() in ["true", "1", "y", "yes"]:
                    v = True
                elif v.lower() in ["false", "0", "n", "no"]:
                    v = False
                else:
                    raise ValueError(f"can't derive true or false from {v} (key {k})")
            elif isinstance(old_v, int):
                v = int(v)
            elif isinstance(old_v, float):
                v = float(v)
            elif not isinstance(old_v, str):
                raise TypeError(
                    f"You can only update int, float, bool or string values in the config, got {v} for key {k}"
                )

View on GitHub (pinned to a597f97485)